|
From: --== Alain ==-- on 30 Sep 2006 15:15 Hi, I'm still working on my DLL and is function to extract strings from the stringtable stored in the DLL. it looks like that : // -- mydll.cpp extern "C" __declspec(dllexport) LPTSTR GetString(int Index) { TCHAR res[2048]; ::LoadString(GetModuleHandle(NULL),Index, res, sizeof(res)/sizeof(TCHAR)); LPTSTR Answer(res); return((Answer)); } // -- mydll.h extern "C" __declspec(dllexport) LPTSTR GetString(int Index); however, on code --> ::LoadString(GetModuleHandle(NULL),Index, res, sizeof(res)/sizeof(TCHAR)); res is always empty... i guess that issue is with getModuleHandle. However, after reading some post on internet, it seems correct...so where is the mistake ? thx, Al.
From: Alex Blekhman on 30 Sep 2006 15:38 "--== Alain ==--" wrote: > > I'm still working on my DLL and is function to extract > strings from the stringtable stored in the DLL. > > it looks like that : > // -- mydll.cpp > extern "C" __declspec(dllexport) LPTSTR GetString(int > Index) > { > TCHAR res[2048]; > ::LoadString(GetModuleHandle(NULL),Index, res, > sizeof(res)/sizeof(TCHAR)); > LPTSTR Answer(res); > return((Answer)); > } > // -- mydll.h > extern "C" __declspec(dllexport) LPTSTR GetString(int > Index); > > however, on code --> > ::LoadString(GetModuleHandle(NULL),Index, res, > sizeof(res)/sizeof(TCHAR)); > res is always empty... i guess that issue is with > getModuleHandle. > However, after reading some post on internet, it seems > correct...so where is the mistake ? The mistake is that GetModuleHandle(NULL) will return handle to the module used to create the running process. I.e., your ..EXE file, not .DLL, which contains string table. Youy could eliminate `GetString' function at all. Just store somewhere in main program handle to the .DLL and call CString::LoadString with this handle passed as first parameter and string index as second. HTH Alex
From: --== Alain ==-- on 30 Sep 2006 15:48 Yes i understand but it means to link statically my resource string table to my exe. i would like to avoid it. So my question is how can i get the Handle of the DLL ? thx, Al. Alex Blekhman wrote: > "--== Alain ==--" wrote: >> >> I'm still working on my DLL and is function to extract strings from >> the stringtable stored in the DLL. >> >> it looks like that : >> // -- mydll.cpp >> extern "C" __declspec(dllexport) LPTSTR GetString(int Index) >> { >> TCHAR res[2048]; >> ::LoadString(GetModuleHandle(NULL),Index, res, >> sizeof(res)/sizeof(TCHAR)); >> LPTSTR Answer(res); >> return((Answer)); >> } >> // -- mydll.h >> extern "C" __declspec(dllexport) LPTSTR GetString(int Index); >> >> however, on code --> ::LoadString(GetModuleHandle(NULL),Index, res, >> sizeof(res)/sizeof(TCHAR)); >> res is always empty... i guess that issue is with getModuleHandle. >> However, after reading some post on internet, it seems correct...so >> where is the mistake ? > > > The mistake is that GetModuleHandle(NULL) will return handle to the > module used to create the running process. I.e., your .EXE file, not > .DLL, which contains string table. > Youy could eliminate `GetString' function at all. Just store somewhere > in main program handle to the .DLL and call CString::LoadString with > this handle passed as first parameter and string index as second. > > HTH > Alex
From: --== Alain ==-- on 30 Sep 2006 15:57 for now i just send the result from LoadLibrary(DLL_Name); --== Alain ==-- wrote: > Yes i understand but it means to link statically my resource string > table to my exe. i would like to avoid it. > > So my question is how can i get the Handle of the DLL ? > thx, > > Al. > > Alex Blekhman wrote: >> "--== Alain ==--" wrote: >>> >>> I'm still working on my DLL and is function to extract strings from >>> the stringtable stored in the DLL. >>> >>> it looks like that : >>> // -- mydll.cpp >>> extern "C" __declspec(dllexport) LPTSTR GetString(int Index) >>> { >>> TCHAR res[2048]; >>> ::LoadString(GetModuleHandle(NULL),Index, res, >>> sizeof(res)/sizeof(TCHAR)); >>> LPTSTR Answer(res); >>> return((Answer)); >>> } >>> // -- mydll.h >>> extern "C" __declspec(dllexport) LPTSTR GetString(int Index); >>> >>> however, on code --> ::LoadString(GetModuleHandle(NULL),Index, res, >>> sizeof(res)/sizeof(TCHAR)); >>> res is always empty... i guess that issue is with getModuleHandle. >>> However, after reading some post on internet, it seems correct...so >>> where is the mistake ? >> >> >> The mistake is that GetModuleHandle(NULL) will return handle to the >> module used to create the running process. I.e., your .EXE file, not >> .DLL, which contains string table. >> Youy could eliminate `GetString' function at all. Just store somewhere >> in main program handle to the .DLL and call CString::LoadString with >> this handle passed as first parameter and string index as second. >> >> HTH >> Alex
From: Alex Blekhman on 30 Sep 2006 16:26 "--== Alain ==--" wrote: > Yes i understand but it means to link statically my > resource string table to my exe. i would like to avoid it. > > So my question is how can i get the Handle of the DLL ? No, you still can have resource string table in DLL. Just load the DLL and store its handle somewhere. HINSTANCE hResInst = ::AfxLoadLibrary(dllName); CString strMessage; strMessage.LoadString(hResInst, IDS_MESSAGE); // ... ::AfxFreeLibrary(hResInst); HTH Alex
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: how to get function name in DLL Next: Getting permissions info for a user |