I had ever used the following function to register my 32-bit COM/DLL components on 32-bit Windows platform such as Window XP, and Windows 7. It works fine. But when running on 64-bit Windows 7, the function can't register successfully. The result is as expected!
int RegisterComponent(LPCTSTR lpszDllName)
{
// Load the library
HINSTANCE hLib = LoadLibrary(lpszDllName);
if (hLib == NULL)
{
return -2;
}
typedef HRESULT (CALLBACK *HCRET)(void);
HCRET lpfnDllRegisterServer;
// Find the entry point
lpfnDllRegisterServer = (HCRET)GetProcAddress(hLib, "DllRegisterServer");
if (lpfnDllRegisterServer == NULL)
{
return -3;
}
// Call the function by function pointer..
if (FAILED((*lpfnDllRegisterServer)()))
{
//DLL Registration failed..
return -4;
}
FreeLibrary(hLib);
return 0;
}
I can use the following command to manually register the 32-bit COM componet: C:\Windows\SysWOW64>regsvr32
How to smartly register a 32-bit COM/DLL component programmatically on different targeting platforms (for example, X86 and X64)?
int RegisterComponent(LPCTSTR lpszDllName)
{
if ( IsWow64() )
{
...
}
else
{
...
}
return 0;
}
Thank you very much!