CreateHardwareEventMoniker
-
I am using some code to develop an Autoplay handler based on this application note. http://msdn2.microsoft.com/en-us/library/bb776827.aspx As described in this article, I would want to enable or disable the Autoplay feature by using code like this .
typedef HRESULT (*CREATEHARDWAREEVENTMONIKER)(REFCLSID clsid, LPCWSTR pszEventHandler, IMoniker **ppmoniker); HRESULT RegisterComponent(IUnknown* punk, DWORD* dpwToken) { HRESULT hr = E_FAIL; HINSTANCE hinstShSvcs = LoadLibrary(TEXT("shsvcs.dll")); if (hinstShSvcs) { CREATEHARDWAREEVENTMONIKER fct = (CREATEHARDWAREEVENTMONIKER)GetProcAddress(hinstShSvcs, "CreateHardwareEventMoniker"); if (fct) { IMoniker* pmoniker; **hr = fct(CLSID_App, TEXT("VideoCameraArrival"), &pmoniker);** if (SUCCEEDED(hr)) { IRunningObjectTable *prot; if (SUCCEEDED(GetRunningObjectTable(0, &prot))) { hr = prot->Register(ROTFLAGS_ALLOWANYCLIENT | ROTFLAGS_REGISTRATIONKEEPSALIVE, punk, pmoniker, &_dwRegisterROT); prot->Release(); } pmoniker->Release(); } CoRegisterClassObject(CLSID_App, static_cast<IClassFactory *>(this), CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE, &_dwRegisterClass; } FreeLibrary(hinstShSvcs); } return hr; }
However I find that there is an exception occuring in this line hr = fct(CLSID_App, TEXT("VideoCameraArrival"), &pmoniker); The exception is as follows : Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. I am debugging this on Visual Studio 2005 and have no clue as to why this is happenning . help is appreciated .Engineering is the effort !