Re: function in DLL
- From: "Abdo Haji-Ali" <ahali@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 1 Oct 2006 21:58:43 +0200
"--== Alain ==--" <nospam@xxxxxxxxxxx> wrote in message
news:#ixSqhY5GHA.3736@xxxxxxxxxxxxxxxxxxxxxxx
extern "C" __declspec(dllexport) LPTSTR GetString(HMODULE hwnd_DLL, int
Index);
extern "C" __declspec(dllexport) LPTSTR GetString(HMODULE hwnd_DLL, int
Index)
{
static TCHAR *strRes;
int iError;
TCHAR re[2048] = {'\0'};
strRes=&re[0];
What the point of this line? Saving the address of the string as static
doesn't mean that the string itself won't get freed when you return from the
function. You'll have to make the whole array static.
static TCHAR re[2048] = {'\0'};
iError = ::LoadString(hwnd_DLL,Index, re, sizeof(re)/sizeof(re[0]));
return(strRes);
return re; // No need for strRes at all
}Can you show us the code which you think has failed?
i also tried to pass it by reference, but nothing has changed.
i tried also to turn the function to send back a string (STL), butSame as before...
nothing works also...
BTW, Alex has suggested a way to load string from a DLL string table without
the need to export a function from the DLL itself . You can always use the
Win32 equivalent of the MFC functions, like:
You can use LoadLibrary instead of AfxLoadLibray()HINSTANCE hResInst = ::AfxLoadLibrary(dllName);
You can use Win32's LoadString() (Not yours)...CString strMessage;
strMessage.LoadString(hResInst, IDS_MESSAGE);
This one is just like FreeLibrary()::AfxFreeLibrary(hResInst);
--
Abdo Haji-Ali
Programmer
In|Framez
.
- Follow-Ups:
- Re: function in DLL
- From: --== Alain ==--
- Re: function in DLL
- References:
- function in DLL
- From: --== Alain ==--
- Re: function in DLL
- From: Alex Blekhman
- Re: function in DLL
- From: --== Alain ==--
- Re: function in DLL
- From: Alex Blekhman
- Re: function in DLL
- From: --== Alain ==--
- function in DLL
- Prev by Date: Re: function in DLL
- Next by Date: Re: function in DLL
- Previous by thread: Re: function in DLL
- Next by thread: Re: function in DLL
- Index(es):
Relevant Pages
|