偶想通过IMoniker接口,获得一个已经存在的COM对象的接口指针,请问各位DX,如何为之?
解决方案 »
- 抠图算法的边缘处理问题
- vs 2010 ado 连接oracle错误,ORA 01019
- swprintf_s 无法找到标识符。。。
- 急!!!在线等,一个运行错误:运行时,报红 X 提示为“......”内存引用“......”内存,该内存不能为“written”
- ADO中如何访问SQL的存储过程
- MFC中,如何判断Access数据库表中已存在该数据
- 请教高手:模板函数怎么用?请高手指点
- 明天水平考试祝大家好运
- 这段语句是何意?
- 请问做“每日一贴”,怎样做最简省?
- 使用CHtmlView,碰到的奇怪问题
- loadlibrary后,调用DLL中函数执行数据库校验,校验时间若短,dll可以free,若长,程序在freelibrary处阻塞了!!!
{
HRESULT hr;
WCHAR szObject[128];
WCHAR wszMsg[128] = {L"Your Message Here...\n"};
IMoniker *pmkObject = NULL;
IUnknown *pIUnk = NULL;
IPersistFile *pIPersistFile = NULL;
ICustomInterface *pICustomInterface = NULL;
// Create a wide-character version of the object's file name.
wsprintf(wszObject, L"%hs", pszObject);
// Get a file moniker for the object (a *.smp file).
hr = CreateFileMoniker(wszObject, &pmkObject);
if(FAILED(hr))
{
printf("Client: CreateFileMoniker for Object failed");
return;
}
// BindMoniker is equivalent to calling CreateBindCtx() followed by
// a call to BindToObject(). It has the net result of binding the
// interface (specified by the IID) to the moniker.
hr = BindMoniker(pmkObject, 0, IID_IUnknown, (void **)&pIUnk);
if (FAILED(hr))
{
printf("Client: BindMoniker failed (%x)\n", hr);
return;
}
// Try a couple QueryInterface calls into the object code; first a
// QueryInterface to IPersistFile...
hr = pIUnk->QueryInterface(IID_IPersistFile,
(void **)&pIPersistFile);
if (FAILED(hr)) {
printf("Client: QueryInterface IPersistFile failed (%x)\n", hr);
pIUnk->Release();
return;
}
// Followed by a QueryInterface to ICustomInterface.
hr = pIUnk->QueryInterface(IID_ICustomInterface,
(void **)&pICustomInterface);
if (FAILED(hr)) {
printf("Client: QueryInterface failed (%x)\n", hr);
pIUnk->Release();
pIPersistFile->Release();
return;
}
// CustomReport() is the object function that displays the time and
// date information on the object.
hr = pICustomInterface->CustomReport();
if (FAILED(hr))
{
printf("Client: pICustomInterface->CustomReport failed (%x)\n",
hr);
pIUnk->Release();
pIPersistFile->Release();
return;
}
// Clean up resources by calling release on each of the interfaces.
pIPersistFile->Release();
pICustomInterface->Release();
pIUnk->Release();
return;
}
// Get a file moniker for the object (a *.smp file).
hr = CreateFileMoniker(wszObject, &pmkObject);
2. bind to object
// BindMoniker is equivalent to calling CreateBindCtx() followed by
// a call to BindToObject(). It has the net result of binding the
// interface (specified by the IID) to the moniker.
hr = BindMoniker(pmkObject, 0, IID_IUnknown, (void **)&pIUnk);