client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- // client.cpp
- // This client program only works on Windows 95/98
- // To use this client under Windows 2000 or Windows NT, see the comments in the local.cpp file
- #define _WIN32_DCOM
- #include <iostream.h>
- #include "Componentcomponent.h"
- void main()
- {
- cout << "Client: Calling CoInitialize()" << endl;
- CoInitialize(NULL);
-
- IUnknown* pUnknown;
- ISum* pSum;
- 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(2, 3, &sum);
- if(SUCCEEDED(hr))
- cout << "Client: Calling Sum() return value is " << sum << endl;
- hr = pSum->Sum(7, 8, &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();
- }