client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- // client.cpp
- #include <iostream.h>
- #include "Componentcomponent.h" // Generated by MIDL
- void main()
- {
- cout << "Client: Calling CoInitialize()" << endl;
- HRESULT hr = CoInitialize(NULL);
- if(FAILED(hr))
- cout << "CoInitialize failed" << endl;
-
- IUnknown* pUnknown;
- ISum* pSum;
- cout << "Client: Calling CoCreateInstance()" << endl;
- hr = CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
- if(FAILED(hr))
- cout << "CoCreateInstance failed" << endl;
- cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
- hr = pUnknown->QueryInterface(IID_ISum, (void**)&pSum);
- if(FAILED(hr))
- cout << "IID_ISum not supported" << endl;
- hr = pUnknown->Release();
- cout << "Client: Calling pUnknown->Release() reference count = " << hr << endl;
- int sum;
- hr = pSum->Sum(2, 3, &sum);
- if(SUCCEEDED(hr))
- cout << "Client: Calling Sum(2, 3) = " << sum << endl;
- hr = pSum->Release();
- cout << "Client: Calling pSum->Release() reference count = " << hr << endl;
- cout << "Client: Calling CoUninitialize()" << endl;
- CoUninitialize();
- }