locked
Problem linking 32-bit DLL on Vista x64 RRS feed

  • Question

  • Hello. I am having some annoying issues attempting to build and (explicitly) link with a DLL. I have application Foo.exe which loads Bar.dll using LoadLibrary and uses GetProcAddress, yadda yadda.

    I'm on Vista x64, using VS 2005. I am trying to build Foo and Bar for Win32.

    When I build Bar.DLL as x64, everything works fine. When I build it as Win32, GetProcAddress in Foo.exe always fails when trying to call a function in Bar. Looking at Bar.DLL in dependancy walker, it is immediately apparent that it is linked to the 64-bit versions of Kernel32.dll, User32.dll, etc..Walker says "Error: Modules with different CPU types were found".

    All modules that Bar is linked to target x64, while it of course targets x86. I'm using the Windows SDK, recent version, and I have removed all x64 libs and tools.

    Why the frack is my DLL linking to all x64 modules? Shouldn't it link to the x86 versions (e.g the ones in SysWOW64 or whatever)?

    Is this a simple linking / library error on my part, or do I have to do something specific to build x86 DLLs? I was under the impression VS 2005 could easily compile x86, and that linking to the correct libraries would be done automatically.

    I apologize if this is a dumb question, but my searches through Google and the MSDN have been fruitless. I just want to build an x86 DLL that works!
    Monday, January 21, 2008 9:25 AM

Answers

  • extern "C" only prevents name mangling for __cedcl functions.

    for __stdcall you have to use a DEF file to prevent name mangling.

     

    Tuesday, January 22, 2008 7:13 AM

All replies

  • Do not trust Dependency Walker here -- it frequently mixes up CPU architectures when examining dependencies. What does GetLastError return after GetProcAddress has failed?

    If it was indeed an x64/x86 problem, the initial call to LoadLibrary should have already failed -- so I suspect this is not the reason.

    --Johannes

    --
    http://int3.de

    Monday, January 21, 2008 11:49 AM
  • Hi Johannes,

    I believe I've found the problem. I was declaring the function in my DLL with __stdcall, which is ignored on x64. On x86 however, __stdcall mangles the name of my function (with parameter size and a '_' prefix). I didn't expect this to happen, as I had declared the function extern 'C'.Silly mistake, I guess.

    Thanks for your help :-)

    Monday, January 21, 2008 8:25 PM
  • extern "C" only prevents name mangling for __cedcl functions.

    for __stdcall you have to use a DEF file to prevent name mangling.

     

    Tuesday, January 22, 2008 7:13 AM