Akihiro Yokoi
Akihiro Yokoi

Reputation: 3

Can I Load Resource Library (DLL) for x64 build in x86 app?

I want to load unired.dll which used in default Windows Printer driver resource file. I can load unires.dll for Windows Vista x86.

It's located in C:\Windows\System32\spool\drivers\w32x86\3

But now I use Windows 7 Pro x64.

So the same name unires.dll which is located in C:\Windows\System32\spool\drivers\x64\3 cannot be load.

By the following code,GetLastError() returns 193

Is it possible? or impossible ? I use Visual Studio 2005 Pro. try build x64 and x86 but each of them failed.

TCHAR libName[MAX_PATH];
wsprintf(libName , _T("unires.dll"));

HINSTANCE hLibraryInstance = ::LoadLibrary(libName);
DWORD ErrorId=::GetLastError();

std::wofstream out;
out.open(_T("unires.txt"));

for(UINT resKey=0;resKey<100000;resKey++)
{

    TCHAR * resBuf=new TCHAR[CHAR_MAX]; 
    int BufferMaxSize=CHAR_MAX;
    int Result=::LoadString(hLibraryInstance, resKey, resBuf, BufferMaxSize);

    wstring resStr=resBuf;

    if(!resStr.empty())
    {
        out<<resKey;
        out<<" ";
        out<<resStr.c_str();
        out<<endl;
    }

    if(resBuf!=NULL)
    {
        delete [] resBuf;
    }
}

out.close();

Please help me. Best regards!!

Upvotes: 0

Views: 1163

Answers (2)

S3RB31
S3RB31

Reputation: 1

Accordng to the MSDN article covering LoadResource, the first parameter should be optional.

For me LoadResource produces error code 193 when I try to access a resource located in another exe file, without passing the hModule parameter.

Doesn't work:

HRSRC hResource = FindResource(LoadLibrary(strFileName.c_str()), MAKEINTRESOURCE(1), RT_STRING);
HGLOBAL hResHandle = LoadResource(NULL, hResource);

Works like a charm:

HMODULE hExe = LoadLibrary(strFileName.c_str());
HRSRC hResource = FindResource(hExe, MAKEINTRESOURCE(1), RT_STRING);
HGLOBAL hResHandle = LoadResource(hExe, hResource);

Upvotes: 0

CharlesB
CharlesB

Reputation: 90276

As mentioned in the comment link, you can't load a x64 library in a x86 process.

The solution might be to port your program to 64 bit.

Upvotes: 2

Related Questions