client.cpp
上传用户:bjlvip
上传日期:2010-02-08
资源大小:744k
文件大小:1k
- // client.cpp
- #define _WIN32_DCOM
- #include <iostream.h>
- #include <stdio.h>
- #include "Componentcomponent.h"
- #include "ChannelHookchannelhook.h"
- void main()
- {
- cout << "Client: Calling CoInitialize()" << endl;
- CoInitialize(NULL);
- // Load the channel hook
- void* silly;
- CoCreateInstance(CLSID_ClientChannelHook, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, &silly);
- /*
- To connect to the Component on the local machine use:
- COSERVERINFO ServerInfo = { 0, 0, 0, 0 };
- To connect to the Component on a remote machine use:
- COSERVERINFO ServerInfo = { 0, L"YourServerName", 0, 0 };
- */
- COSERVERINFO ServerInfo = { 0, 0, 0, 0 };
- cout << "Client: Calling CoCreateInstance() " << endl;
- MULTI_QI qi = { &IID_IUnknown, NULL, 0 };
- HRESULT hr = CoCreateInstanceEx(CLSID_InsideCOM, NULL, CLSCTX_LOCAL_SERVER, &ServerInfo, 1, &qi);
- if(FAILED(hr))
- {
- printf("Client: hr = %0xn", hr);
- exit(0);
- }
- ISum* pSum;
- qi.pItf->QueryInterface(IID_ISum, (void**)&pSum);
- int sum;
- hr = pSum->Sum(4, 9, &sum);
- cout << "Client: Calling Sum() return value is " << sum << endl;
- printf("HRESULT is %xn", hr);
- cout << "Client: Calling Release() for pSum" << endl;
- hr = pSum->Release();
- cout << "Client: Calling CoUninitialize()" << endl;
- qi.pItf->Release();
- CoUninitialize();
- }