Article ID: 140346
Article Last Modified on 12/1/2003
BOOL CTestregApp::InitInstance()
{
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
At this point, add the following code segment, which will allow you to
check the return codes from LoadLibrary(), GetProcAddress(), and
DllRegisterServer.
#ifdef _WIN32
HINSTANCE hDLL = LoadLibrary("some.ocx");
if(NULL == hDLL)
{
// See Winerror.h for explaination of error code.
DWORD error = GetLastError();
TRACE1("LoadLibrary() Failed with: %i\n", error);
return FALSE;
}
typedef HRESULT (CALLBACK *HCRET)(void);
HCRET lpfnDllRegisterServer;
lpfnDllRegisterServer =
(HCRET)GetProcAddress(hDLL, "DllRegisterServer");
if(NULL == lpfnDllRegisterServer)
{
// See Winerror.h for explaination of error code.
DWORD error = GetLastError();
TRACE1("GetProcAddress() Failed with %i\n", error);
return FALSE;
}
if(FAILED((*lpfnDllRegisterServer)()))
{
TRACE("DLLRegisterServer() Failed");
return FALSE;
}
#else // 16-bit
HINSTANCE hDLL = LoadLibrary("regtest.ocx");
if(HINSTANCE_ERROR > hDLL)
{
// See LoadLibrary() help for explaination of error code.
TRACE1("LoadLibrary() Failed with: %i\n", hDLL);
return FALSE;
}
typedef HRESULT (CALLBACK *HCRET)(void);
HCRET lpfnDllRegisterServer;
lpfnDllRegisterServer =
(HCRET)GetProcAddress(hDLL, "DllRegisterServer");
if(NULL == lpfnDllRegisterServer)
{
// See GetProcAddress() help for explaination of error code.
TRACE("GetProcAddress() Failed");
return FALSE;
}
if(FAILED((*lpfnDllRegisterServer)()))
{
TRACE("DLLRegisterServer() Failed");
return FALSE;
}
#endif
Additional query words: kbinf 1.51 1.52 1.52b 2.00 2.10 2.20 2.50 2.51 2.52 3.00 3.10 3.20 4.00
Keywords: kbctrl kbcode KB140346