Having a generic function GetProcAddress for both unicode and ascii builds - fails in release mode
-
Hi All, I am having a common code snippet to be compiled in VC6 and in Embedded vc++(CE). Right now i am working with vc6 part.
void* CNewClass::GetProcAddress1(HMODULE hModule, LPCTSTR lpFuncName)
{
USES_CONVERSION;//for ATL, to use A2W declare this first#ifdef \_WINCE //for wince LPCWSTR lpUnicodeFuncName = A2W( lpFuncName ); return(GetProcAddress(hModule, lpUnicodeFuncName)); #else // for vc6 LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName ); return (GetProcAddress(hModule, lpAsciiFuncName)); #endif
}
Problem: This function (GetProcAddress) returns 0/fails in release mode. It works fine in debug mode. General Info: The function GetProcAddress resolves to GetProcAddressA or GetProcAddressW based on the build(ascii or unicode) in EVC++ whereas in vc6, it is GetProcAddress only (simlar to GetProcAddressA with LPCSTR as second parameter). Also just FYI: http://blog.voidnish.com/?p=70[^] I tried lot of ways to typecastings.. but didnot work. Please help.
Priya Sundar
-
Hi All, I am having a common code snippet to be compiled in VC6 and in Embedded vc++(CE). Right now i am working with vc6 part.
void* CNewClass::GetProcAddress1(HMODULE hModule, LPCTSTR lpFuncName)
{
USES_CONVERSION;//for ATL, to use A2W declare this first#ifdef \_WINCE //for wince LPCWSTR lpUnicodeFuncName = A2W( lpFuncName ); return(GetProcAddress(hModule, lpUnicodeFuncName)); #else // for vc6 LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName ); return (GetProcAddress(hModule, lpAsciiFuncName)); #endif
}
Problem: This function (GetProcAddress) returns 0/fails in release mode. It works fine in debug mode. General Info: The function GetProcAddress resolves to GetProcAddressA or GetProcAddressW based on the build(ascii or unicode) in EVC++ whereas in vc6, it is GetProcAddress only (simlar to GetProcAddressA with LPCSTR as second parameter). Also just FYI: http://blog.voidnish.com/?p=70[^] I tried lot of ways to typecastings.. but didnot work. Please help.
Priya Sundar
Should the
LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName );
line be:
LPCSTR lpAsciiFuncName = (LPCSTR)T2A( lpFuncName );
? That may not be the source of your trouble, but it won't help... Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[^]
-
Hi All, I am having a common code snippet to be compiled in VC6 and in Embedded vc++(CE). Right now i am working with vc6 part.
void* CNewClass::GetProcAddress1(HMODULE hModule, LPCTSTR lpFuncName)
{
USES_CONVERSION;//for ATL, to use A2W declare this first#ifdef \_WINCE //for wince LPCWSTR lpUnicodeFuncName = A2W( lpFuncName ); return(GetProcAddress(hModule, lpUnicodeFuncName)); #else // for vc6 LPCSTR lpAsciiFuncName = (LPCSTR)W2A( lpFuncName ); return (GetProcAddress(hModule, lpAsciiFuncName)); #endif
}
Problem: This function (GetProcAddress) returns 0/fails in release mode. It works fine in debug mode. General Info: The function GetProcAddress resolves to GetProcAddressA or GetProcAddressW based on the build(ascii or unicode) in EVC++ whereas in vc6, it is GetProcAddress only (simlar to GetProcAddressA with LPCSTR as second parameter). Also just FYI: http://blog.voidnish.com/?p=70[^] I tried lot of ways to typecastings.. but didnot work. Please help.
Priya Sundar
On my system this code (following Iain's suggestion), compiled with VC6 works fine both on
Debug
andRelease
buildLPCSTR lpAsciiFuncName = T2A( lpFuncName );
return (GetProcAddress(hModule, lpAsciiFuncName));If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
On my system this code (following Iain's suggestion), compiled with VC6 works fine both on
Debug
andRelease
buildLPCSTR lpAsciiFuncName = T2A( lpFuncName );
return (GetProcAddress(hModule, lpAsciiFuncName));If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]Hi, Still it is not working after using T2A(). And fyi I am compiling my application(vc6) in UNICODE! Could you please show me your function call? The below is my function call:
CString CompletePathOfDll ="E:\\sample.dll";
HINSTANCE DllHandle = LoadLibrary(CompletePathOfDll);//loads the dll successfullyif (DllHandle != NULL)
{
int IsCorrectDll=(int)GetProcAddress1(DllHandle ,TEXT("Get_Data_Function"));
if(IsCorrectDll>0)
{
//do something
}
}Thanks.
Priya Sundar