client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:2k
- // client.cpp
- #define _WIN32_DCOM
- #include <iostream.h>
- #include "Componentcomponent.h"
- void main()
- {
- cout << "Client: Calling CoInitialize()" << endl;
- CoInitializeEx(NULL, COINIT_MULTITHREADED);
-
- IUnknown* pUnknown = 0;
- ISum* pSum = 0;
- cout << "Client: Calling CoGetClassObject() " << endl;
- IClassFactory* pClassFactory = 0;
- CoGetClassObject(CLSID_InsideCOM, CLSCTX_LOCAL_SERVER, NULL, IID_IClassFactory, (void**)&pClassFactory);
- cout << "Client: CreateInstance() " << endl;
- pClassFactory->CreateInstance(NULL, IID_IUnknown, (void**)&pUnknown);
- cout << "Client: Release() " << endl;
- pUnknown->Release();
- pUnknown = 0;
- cout << "Client: CreateInstance again() " << endl;
- pClassFactory->CreateInstance(NULL, IID_IUnknown, (void**)&pUnknown);
- pClassFactory->Release();
- // cout << "Client: Calling CoCreateInstance() " << endl;
- // CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
- cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
- HRESULT hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
- if(FAILED(hr))
- cout << "QueryInterface FAILED" << endl;
- cout << "Client: Calling Release() for pUnknown" << endl;
- hr = pUnknown->Release();
- cout << "Client: pSum = " << pSum << endl;
- int sum;
- hr = pSum->Sum(4, 9, &sum);
- if(SUCCEEDED(hr))
- cout << "Client: Calling Sum() return value is " << sum << endl;
- cout << "Client: Calling Release() for pSum" << endl;
- hr = pSum->Release();
- cout << "Client: Calling CoUninitialize()" << endl;
- CoUninitialize();
- }