- 注册时间
- 2011-3-6
- 最后登录
- 1970-1-1
该用户从未签到
|
1. 定义导出函数指针- //定义函数指针
- typedef HRESULT (_stdcall *Func) (REFCLSID , REFIID , LPVOID*);
- Func g_DllGetClassObject=NULL;
复制代码 2.导出COM组件这个DLL 的 DllGetClassObject函数- if (g_DllGetClassObject==NULL)
- {
- CString strParam = theApp.strRootDirectory + TEXT("//MMGifCtrl.dll");
- HMODULE module=LoadLibrary(strParam.GetBuffer(0));
- if (module!=NULL)
- {
- g_DllGetClassObject= (Func) GetProcAddress(module,"DllGetClassObject");
- }
- }
复制代码 3.通过 DllGetClassObject 获得COM的类厂,然后通过类厂获得所要的接口。- IMMGifCtrl * pShowGif = NULL;
- CComQIPtr<IClassFactory> pGifFactory;
- HRESULT hr;
- //如果 g_DllGetClassObject不为空
- if (g_DllGetClassObject)
- {
- hr= g_DllGetClassObject(__uuidof(CMMGifCtrl), IID_IClassFactory,(LPVOID*)&pGifFactory);
- if (hr ==S_OK)
- {
- pGifFactory->CreateInstance(NULL,__uuidof(IMMGifCtrl),(LPVOID*)&pShowGif);
- if (pShowGif)
- {
- //成功获得COM接口
- }
- }
- }
复制代码 |
|