client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- // client.cpp
- #define _WIN32_DCOM
- #include <iostream.h>
- #include <stdio.h>
- #include "Component CoInitializeSecuritycomponent.h"
- void main()
- {
- cout << "Client: Calling CoInitialize()" << endl;
- CoInitialize(NULL);
-
- IUnknown* pUnknown;
- ISum* pSum;
- cout << "Client: Calling CoCreateInstance() " << endl;
- HRESULT hr = CoCreateInstance(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, IID_IUnknown, (void**)&pUnknown);
- if(FAILED(hr))
- {
- if(hr == E_ACCESSDENIED)
- printf("CoCreateInstance FAILED hr = E_ACCESSDENTIEDn", hr);
- else
- printf("CoCreateInstance FAILED hr = %0xn", hr);
- exit(0);
- }
- cout << "Client: Calling QueryInterface() for ISum on " << pUnknown << endl;
- 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();
- }