使用注册COM 组件 方法

                                         使用注册COM 组件  方法

 

     1.首先导入DLL

         #import "MMGifCtrl.dll"   no_namespace

      2.确保DLL已经被注册,注册DLL的代码如下:

            //这里注册dll, 这行语句会弹DOS窗口,下面的代码不会 SHELLEXECUTEINFO ShExecInfo = {0}; ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS; ShExecInfo.hwnd = NULL; ShExecInfo.lpVerb = TEXT("open"); ShExecInfo.lpFile = TEXT("regsvr32.exe"); CString strParam = TEXT("/"") + theApp.strRootDirectory + TEXT("//MMGifCtrl.dll/" /s"); ShExecInfo.lpParameters = strParam; wchar_t szBuf[MAX_PATH]; GetSystemDirectoryW(szBuf, MAX_PATH); ShExecInfo.lpDirectory = szBuf; ShExecInfo.nShow = SW_HIDE; ShExecInfo.hInstApp = NULL; ShellExecuteEx(&ShExecInfo); // 指定时间没结束 if (WaitForSingleObject(ShExecInfo.hProcess, 5000) == WAIT_TIMEOUT) { // 强行杀死进程 TerminateProcess(ShExecInfo.hProcess, 0); _com_issue_error(hr); }

       3.  获得COM的接口

           IMMGifCtrl * pShowGif = NULL; HRESULT hr; hr = ::CoCreateInstance(__uuidof(CMMGifCtrl), NULL, CLSCTX_INPROC, __uuidof(IMMGifCtrl), (LPVOID*)&pShowGif); if(FAILED(hr)) { //说明COM没有被注册,在此用代码注册 COM }

      4.  获得了  IMMGifCtrl接口,就可以干活啦!

你可能感兴趣的:(使用注册COM 组件 方法)