Tech Off Thread

16 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Problem in calling Visual c++ LoadLibrary() function

Back to Forum: Tech Off
  • User profile image
    ranjeetg

    Hi, i have created a DLL(win32) in visual c++( say myDLL) which is using some other DLL. I load these DLL using visual c++ LoadLibrary() function. And then i am using this DLL(myDLL) in a C# application (Released as Any CPU). This application is working fine on windows XP 32 system.

               For windows 7 64bit i  created a DLL(x64)  in visual c++( say my64DLL) which is using some other DLL. I load these DLL using visual c++ LoadLibrary() function. And then i am using this DLL(my64DLL) in a C# application (Released as Any CPU). Problem is when control goes to LoadLibrary() it return 0. That is it didn't load the third party DLL. I am unable to understand where is the problem. Please help me in resolving this issue. 

        For whole development i am using windows XP 32 bit system.

    Thank in advance.

  • User profile image
    Ion Todirel

    how are you running 64-bit code on a 32-bit system? and then, anycpu really means run as whatever  

  • User profile image
    cheong

    @ranjeetg:I suggest see if your application process has a "*" attach to it's process name in task manager under Win7 x64. That's simple verification that whether the process is running as 32-bit process or not (32-bit processes have "*")

    Let's eliminate that possibility before continue.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    ranjeetg

    @cheong:  Process is running as a 64bit application there is no any process name containing "*" .

  • User profile image
    ranjeetg

    @cheong:@cheong:  Process is running as a 64bit application there is no any process name containing "*" 

  • User profile image
    ranjeetg

    @Ion Todirel: I am not running i am only developing DLL(in visual c++ released as X64) and c# application(released as anyCPU and using my DLL) which will run on a windows 7 64bit machine. 

  • User profile image
    cheong

    Then, since you mentioned it's Visual C++, did you staticly linked everything, or remember to install the VC++ runtime on target machine? I remember if VC++ runtime is missing the libraries won't load.

    Try copy the "depends.exe"  and run that on Win7 with problem, load the DLL to see if it says anything is missing.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    ranjeetg

    @cheong:Hi cheong

    After using Dependency Walker i getting problem in below location

    c:\windows\system32\API-MS-WIN-CORE-DEBUG-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-ERRORHANDLING-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-FIBERS-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-FILE-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-HANDLE-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-HEAP-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-IO-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-LIBRARYLOADER-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-LOCALIZATION-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-MEMORY-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-MISC-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-NAMEDPIPE-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-PROCESSENVIRONMENT-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-PROCESSTHREADS-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-PROFILE-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-RTLSUPPORT-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-STRING-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-SYNCH-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-SYSINFO-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-THREADPOOL-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-CORE-UTIL-L1-1-0.DLL
    c:\windows\system32\API-MS-WIN-SECURITY-BASE-L1-1-0.DLL
    c:\windows\system32\KERNEL32.DLL
    c:\windows\system32\KERNELBASE.DLL
    c:\windows\system32\NTDLL.DLL

     

    I think these are the DLL of windows XP 32 bit OS and creating problem in windows 7 64 bit system.

    Please help me to solve this problem.

    Thanks in advance.

  • User profile image
    ranjeetg

    @cheong:Hi cheong Sorry above error occurs because i was using dependency walker x86.

    Dependency walker 64 bit didn't show any error.

    But still i am unable to resolve my problem. 

  • User profile image
    ranjeetg

    @cheong: Hi cheong once again i am explaining my problem.

    In myDLL application:

    myHeader.h contains

    #ifdef _DEBUG
      
       #define TOKEN_LIBRARY_DISCOVERY_DEBUG_DLL_PATH _T("../bin/Common/Lib/windows/discovery.dll")
     
    #else
       #define TOKEN_LIBRARY_DISCOVERY_RELEASE_DLL_PATH _T("../bin/Common/Lib/Windows/discovery.dll")
     
    #endif

    body.cpp contains

    hinstLibDiscovery = LoadLibrary(TOKEN_LIBRARY_DISCOVERY_RELEASE_DLL_PATH);

     

    //problem is LoadLibrary returns a valid value in a 32 bit system. but returns 0 in a 64 bit system

    .

     

  • User profile image
    cheong

    Wait... since so far I haven't seen you mentioned anything about the 64-bit version of 3rd party libraries, are you using 32-bit version of "the other DLL" on the 64-bit machine?

    You can't load 32 bit-DLLs in 64-bit process, that's precisely the reason why x64 Windows have to include 32-bit version of libraries in SysWOW64 folder.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    ranjeetg

    @cheong:Hi cheong.Thanks for your reply.

    But when i created a simple vc++ console() application (released as win32) its working fine on both machine(windows xp 32bit and windows 7 64bit).

  • User profile image
    ranjeetg

    @cheong:Hi cheong,

    You are correct my test vc++ console() application (released as win32) running as a 32bit application on windows7 64bit system.

  • User profile image
    ranjeetg

    @cheong: Hi please suggest me a way to solve this problem in developing application for windows 64bit system. I am only having 32bit version of 3rd party DLL .

     

    Thanks for your help.

  • User profile image
    cheong

    If that's not possible, you have to set your library to target x86 then. Which also means your library can't be used by applications that compiles with target = x64.

    My advice would be try to see if you can get 64-bit runtime from vendors (some software vendors make it possible to use newer version of runtime with old license, just that it won't enter design mode. If you're running out of budget, it's be wise to just check and see if that move is possible.)

    Btw, it'd be justifiable expense to buy software that your code is rely on. Try to ask your boss.

    Recent Achievement unlocked: Code Avenger Tier 4/6: You see dead program. A lot!
    Last modified
  • User profile image
    ranjeetg

    @cheong: Hi cheong.

    Thank you so much for your valuable response. I tried it and its working fine.

    But x86 creates some new problem like i have used Shell32.ShellSpecialFolderConstants.ssfDESKTOP and other things which working fine in a AnyCPU release system but creating problem in x86. 

    I am trying to resolve these problems.

    Ones again thanks a lot for your support. 

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.