none
LoadLibrary fails in 64 bit O.S.

    Question

  • Hi,

     

    I am using LoadLibrary to load a Win32 DLL. The code works well on 32 bit O.S. But the same code returns 0. I tried to get the last error using Marshal.GetLastWin32Error(), but just got an error code 0.

     

    Is this an known issue? Could experts here suggest a solution or workaround for this?

     

    Thanks a lot,

    Yimin

    Wednesday, October 31, 2007 7:58 PM

Answers

  • You're running an x64 app, calling LoadLibrary on an x64 dll? That shouldn't fail. If you're mixing and matching; that won't work.
    Wednesday, October 31, 2007 8:42 PM
  • Are you 100% certain that you're running a 32bit app?  .NET 2.0 apps that are compiled as "Any CPU" will automatically be 64-bit apps on a 64-bit OS.  You can tell from Task Manager whether your process is 32 bit or not (32 bit processes have *32 appended to the process name).

    Wednesday, October 31, 2007 9:44 PM

All replies

  • You're running an x64 app, calling LoadLibrary on an x64 dll? That shouldn't fail. If you're mixing and matching; that won't work.
    Wednesday, October 31, 2007 8:42 PM
  •  

    No. I am running win32 app and loadlibrary on a Win32 DLL. This works well on 32 bit OS, but fails on 64 bit OS.

     

    Thanks,

    Yimin

    Wednesday, October 31, 2007 9:10 PM
  • Are you 100% certain that you're running a 32bit app?  .NET 2.0 apps that are compiled as "Any CPU" will automatically be 64-bit apps on a 64-bit OS.  You can tell from Task Manager whether your process is 32 bit or not (32 bit processes have *32 appended to the process name).

    Wednesday, October 31, 2007 9:44 PM
  • Yeah. I found out that the process was run as 64 application, because I was building with Win32 | Any CPU combination. It works fine after building the app as a pure win32 one.

     

    Thanks,

    Yimin

    Wednesday, October 31, 2007 10:47 PM