代码如下。如何避免TYPE_E_LIBNOTREGISTERED(hr=0x8002801D, Library not registered) error(DO NOT register the ActiveX to Windows)
的disp->Invoke()
?
注册 ActiveX 控件时,一切正常,但我不想注册到 WINDOWS。
谢谢!
#define WIN32_LEAN_AND_MEAN
#include <tchar.h>
#include <Windows.h>
#include <assert.h>
#include <stdio.h>
#include <ole2.h>
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
OleInitialize(NULL);
LPCTSTR lpFile = _T("D:\\Temp\\Flash32_11_4_402_287.ocx");
HMODULE hDll = LoadLibrary(lpFile);
if (hDll)
{
typedef HRESULT (WINAPI *DllGetClassObject_t)(REFCLSID, REFIID, LPVOID*);
DllGetClassObject_t DllGetClassObject = NULL;
DllGetClassObject = (DllGetClassObject_t)GetProcAddress(hDll, "DllGetClassObject");
if (DllGetClassObject)
{
CLSID clsid = GUID_NULL;
IClassFactory *pCF = NULL;
if (SUCCEEDED(CLSIDFromString(L"{D27CDB6E-AE6D-11CF-96B8-444553540000}", &clsid))
&& SUCCEEDED(DllGetClassObject(clsid, IID_IClassFactory, (void**)&pCF)))
{
IOleObject *obj = NULL;
IDispatch *disp = NULL;
if (SUCCEEDED(pCF->CreateInstance(NULL, IID_IOleObject, (void**)&obj))
&& SUCCEEDED(obj->QueryInterface(IID_IDispatch, (void**)&disp)))
{
DISPPARAMS params = { NULL, NULL, 0, 0 };
HRESULT hr = disp->Invoke(0x70, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD,
¶ms, NULL, NULL, NULL);
assert(SUCCEEDED(hr));
//ERROR: hr=0x8002801D,TYPE_E_LIBNOTREGISTERED, Library not registered
}
if (disp) disp->Release();
if (obj) obj->Release();
pCF->Release();
}
}
}
OleUninitialize();
return 0;
}