Re: function in DLL



"--== 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

.



Relevant Pages

  • Re: function in DLL
    ... table to my exe. ... So my question is how can i get the Handle of the DLL? ... ::LoadString,Index, res, sizeof/sizeof); ... 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. ...
    (microsoft.public.vc.language)
  • Re: function in DLL
    ... Yes i understand but it means to link statically my resource string table to my exe. ... So my question is how can i get the Handle of the DLL? ... ::LoadString,Index, res, sizeof/sizeof); ...
    (microsoft.public.vc.language)
  • Re: Explicit Linking of DLLs in VB.net
    ... yes this technique will only work on managed assemblys (exe or dll) ... "YourObject" is a form and is limited to the form methods. ... Wel implement propertys, methods, events in your interface and start ... Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Explicit Linking of DLLs in VB.net (attn Michel or any others)
    ... loads the dll and finds a form in the dll. ... Dim extForm As Form = extAssembly.CreateInstance("test.entry", ... Wel implement propertys, methods, events in your interface and start ... Public Shared Function LoadMeByName(ByVal vstrAssemblyName As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Access crashes when calling DLL function.
    ... I have started bypassing code in the form to find the problem. ... are local String variables. ... I then built a simple input form (in the same mdb) that calls the crashing ... functions from a DLL they provide. ...
    (microsoft.public.access.modulesdaovba)