CoGetClassObject client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
源码类别:
Windows编程
开发平台:
Visual C++
- // CoGetClassObject Client.cpp
- // Use this client on Windows 2000 or Windows NT
- #define _WIN32_DCOM
- #include <iostream.h>
- #include "Componentcomponent.h"
- void main()
- {
- cout << "Client: Calling CoInitialize()" << endl;
- CoInitialize(NULL);
- HRESULT hr;
- ISum* pSum;
- IClassFactory* pClassFactory;
- cout << "Client: Calling CoGetClassObject()" << endl;
- hr = CoGetClassObject(CLSID_InsideCOM, CLSCTX_LOCAL_SERVER, NULL, IID_IClassFactory, (void**)&pClassFactory);
- if(FAILED(hr))
- cout << "CoGetClassObject FAILED" << endl;
- cout << "Client: Calling CreateInstace() pClassFactory = " << pClassFactory << endl;
- hr = pClassFactory->CreateInstance(NULL, IID_ISum, (void**)&pSum);
- if(FAILED(hr))
- cout << "CreateInstance FAILED" << endl;
- cout << "Client: Calling Release()" << endl;
- pClassFactory->Release();
- int sum;
- hr = pSum->Sum(2, 3, &sum);
- if(SUCCEEDED(hr))
- cout << "Client: Calling Sum() on " << pSum << " return value is " << sum << endl;
- hr = pSum->Sum(7, 8, &sum);
- if(SUCCEEDED(hr))
- cout << "Client: Calling Sum() on " << pSum << " return value is " << sum << endl;
- hr = pSum->Release();
- cout << "Client: Calling Release() for ISum on " << hr << endl;
- cout << "Client: Calling CoUninitialize()" << endl;
- CoUninitialize();
- }