Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

LoadLibrary fails in 64 bit O.S.

Hi,
I am using Delphi5. I have used LoadLibrary to load a dll which works fine in all kinds of Win O.S except 64 bit O.S. Handle returned by LoadLibrary is 0(zero). I have tried to trace the problem using GetLastError and FormatMessage. But GetlastError also returns 0 (Zero).


Why so? Is there any setting I need to do?

Plz reply.

Comments

  • zibadianzibadian Posts: 6,349Member
    : Hi,
    : I am using Delphi5. I have used LoadLibrary to load a dll which works fine in all kinds of Win O.S except 64 bit O.S. Handle returned by LoadLibrary is 0(zero). I have tried to trace the problem using GetLastError and FormatMessage. But GetlastError also returns 0 (Zero).
    :
    :
    : Why so? Is there any setting I need to do?
    :
    : Plz reply.
    :
    :
    The LoadLibrary(), which is natively used in the Windows unit, is loaded from kernel32.dll, a 32-bit library loader. Since the entry codes will probably (don't know for sure) be different for 32-bit and 64-bit, the LoadLibrary() fails with an unknown error (forward compatibility is still a bit of a problem). A solution might be to import the LoadLibrary() from the 64-bit kernel.
  • Chaitanya_PuneChaitanya_Pune Posts: 87Member
    : : Hi,
    : : I am using Delphi5. I have used LoadLibrary to load a dll which works fine in all kinds of Win O.S except 64 bit O.S. Handle returned by LoadLibrary is 0(zero). I have tried to trace the problem using GetLastError and FormatMessage. But GetlastError also returns 0 (Zero).
    : :
    : :
    : : Why so? Is there any setting I need to do?
    : :
    : : Plz reply.
    : :
    : :
    : The LoadLibrary(), which is natively used in the Windows unit, is loaded from kernel32.dll, a 32-bit library loader. Since the entry codes will probably (don't know for sure) be different for 32-bit and 64-bit, the LoadLibrary() fails with an unknown error (forward compatibility is still a bit of a problem). A solution might be to import the LoadLibrary() from the 64-bit kernel.
    :
    -----------------------------------------------------------------------

    Thanks for reply.
    I have placed GetLastError at wrong place. Now I have placed GetLastError just after the call to LoadLibrary(). So It returns error code 193 which according to MSDN means 'is not a valid Win32 application'. Also I have treid to load some other Dll which I have made. I can load that one. But the problem is in the previous one which is not mine.

    Now you can understand the whole problem. Do you have any better suggession ? Mean while I am trying your solution.
  • zibadianzibadian Posts: 6,349Member
    : : : Hi,
    : : : I am using Delphi5. I have used LoadLibrary to load a dll which works fine in all kinds of Win O.S except 64 bit O.S. Handle returned by LoadLibrary is 0(zero). I have tried to trace the problem using GetLastError and FormatMessage. But GetlastError also returns 0 (Zero).
    : : :
    : : :
    : : : Why so? Is there any setting I need to do?
    : : :
    : : : Plz reply.
    : : :
    : : :
    : : The LoadLibrary(), which is natively used in the Windows unit, is loaded from kernel32.dll, a 32-bit library loader. Since the entry codes will probably (don't know for sure) be different for 32-bit and 64-bit, the LoadLibrary() fails with an unknown error (forward compatibility is still a bit of a problem). A solution might be to import the LoadLibrary() from the 64-bit kernel.
    : :
    : -----------------------------------------------------------------------
    :
    : Thanks for reply.
    : I have placed GetLastError at wrong place. Now I have placed GetLastError just after the call to LoadLibrary(). So It returns error code 193 which according to MSDN means 'is not a valid Win32 application'. Also I have treid to load some other Dll which I have made. I can load that one. But the problem is in the previous one which is not mine.
    :
    : Now you can understand the whole problem. Do you have any better suggession ? Mean while I am trying your solution.
    :
    You could try to use LoadLibraryEx() and specify, that the application should not run the entry codes.
    Alternatively, this article might provide an answer if the dll is 16-bit: http://www.thedelphimagazine.com/samples/thunk/article.htm
  • Chaitanya_PuneChaitanya_Pune Posts: 87Member
    : : : : Hi,
    : : : : I am using Delphi5. I have used LoadLibrary to load a dll which works fine in all kinds of Win O.S except 64 bit O.S. Handle returned by LoadLibrary is 0(zero). I have tried to trace the problem using GetLastError and FormatMessage. But GetlastError also returns 0 (Zero).
    : : : :
    : : : :
    : : : : Why so? Is there any setting I need to do?
    : : : :
    : : : : Plz reply.
    : : : :
    : : : :
    : : : The LoadLibrary(), which is natively used in the Windows unit, is loaded from kernel32.dll, a 32-bit library loader. Since the entry codes will probably (don't know for sure) be different for 32-bit and 64-bit, the LoadLibrary() fails with an unknown error (forward compatibility is still a bit of a problem). A solution might be to import the LoadLibrary() from the 64-bit kernel.
    : : :
    : : -----------------------------------------------------------------------
    : :
    : : Thanks for reply.
    : : I have placed GetLastError at wrong place. Now I have placed GetLastError just after the call to LoadLibrary(). So It returns error code 193 which according to MSDN means 'is not a valid Win32 application'. Also I have treid to load some other Dll which I have made. I can load that one. But the problem is in the previous one which is not mine.
    : :
    : : Now you can understand the whole problem. Do you have any better suggession ? Mean while I am trying your solution.
    : :
    : You could try to use LoadLibraryEx() and specify, that the application should not run the entry codes.
    : Alternatively, this article might provide an answer if the dll is 16-bit: http://www.thedelphimagazine.com/samples/thunk/article.htm
    :
    ------------------------------------------------------------------------

    Hi Zibadian,
    I tried LoadLibraryEx but it also fails on 64 bit machine with same error code i.e. 193. As far as the link ; you have provided ;is concerned it is complicated. I am trying.

    By the way thanks for your co-operation and help.

    Please let me know if you have other solution.

    Bye.

Sign In or Register to comment.