简体   繁体   中英

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

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_ID, 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM