chapter9_collectionclient.cpp
来自「atl development adsfasdfasdf」· C++ 代码 · 共 62 行
CPP
62 行
//
// Chapter9_CollectionClient.cpp
//
#include <windows.h>
#include <tchar.h>
#include <iostream.h>
#include <initguid.h>
#include <atlbase.h>
#include "..\Chapter9_CollectionServer\Chapter9_CollectionServer_i.c"
#include "..\Chapter9_CollectionServer\Chapter9_CollectionServer.h"
int main( int argc, char *argv[] )
{
cout << "Initializing COM" << endl;
if ( FAILED( CoInitialize( NULL )))
{
cout << "Unable to initialize COM" << endl;
return -1;
}
// Get the class factory
IApplication* pApp;
HRESULT hr = CoCreateInstance( CLSID_Application,
NULL,
CLSCTX_SERVER,
IID_IApplication,
(void**) &pApp );
if ( FAILED( hr ))
{
cout.setf( ios::hex, ios::basefield );
cout << "Failed to create server instance. HR = " << hr << endl;
return -1;
}
cout << "Instance created" << endl;
IMovieCollection *pMovies;
pApp->get_Movies( (IDispatch**) &pMovies );
long lCount;
pMovies->get_Count( &lCount );
for ( int i = 0; i < lCount; i++ )
{
USES_CONVERSION;
IMovie* pMovie = 0;
pMovies->get_Item( i + 1, &pMovie );
BSTR bstr = 0;
pMovie->get_Title( &bstr );
cout << W2A( bstr ) << " - ";
SysFreeString( bstr );
pMovie->get_Director( &bstr );
cout << W2A( bstr ) << endl;
SysFreeString( bstr );
pMovie->Release();
}
pMovies->Release();
cout << "Shuting down COM" << endl;
CoUninitialize();
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?