开发者

How to load a string from the resource of a different process?

开发者 https://www.devze.com 2023-01-09 08:50 出处:网络
I need to load a string which is placed in the resource dll of a different process, provided that the process will be running at the time of call.

I need to load a string which is placed in the resource dll of a different process, provided that the process will be running at the time of call.

I tried following code -

    HMODULE hRes = ::LoadLibrary(_T("SomeResource.dll"));

    TCHAR buffer[50];
    ::LoadString(hRes, IDS_SOME_I开发者_如何学GoD, buffer, 50);

This code is working fine while running in debug mode. But in release mode LoadLibrary returns zero. Why?

Am I missing something? Please help me.

I am using VC7.1 compiler.


It might be a problem of finding "SomeResource.dll". When you run from the debugger, the executable is started from the project's path. If the DLL can be found from there. it's fine. When you run from outside the IDE, the executable is started from a different folder. It migh be that the DLL cannot be found from there.


I'm not pretended on answer, but could please add following code to diagnose problem:

if( hRes == 0 ){
LPVOID lpMsgBuf;
DWORD dw = GetLastError();

FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER | 
    FORMAT_MESSAGE_FROM_SYSTEM,
    NULL,
    dw,
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    (LPTSTR) &lpMsgBuf,
    0, NULL );


MessageBox(NULL, (LPTSTR)lpMsgBuf, "Error", MB_OK);

LocalFree(lpMsgBuf);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消