Click here to Skip to main content
14,637,542 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have developed VSTO Adding to Word with VS2010 C#, and it is having Native DLL developed with Embercardeo c++ 10, problem is my C++ DLL load another native DLL via LoadLibrary("lib2.dll") this command not working, but when i use absolute path as LoadLibrary("E:\\DMSUSER\\bin\\Debug\\lib2.dll") it is load and run correctly.

note: all DLLs are in same directory, and LoadLibrary("lib2.dll") working successfully in VS debug running. my codes are following.

What I have tried:

//not loading code
HINSTANCE DllInst = NULL;
if (DllInst == NULL) DllInst = LoadLibrary("lib2.dll");
if (DllInst)
{//my code}




//working code with absolute file path
HINSTANCE DllInst = NULL;
if (DllInst == NULL) DllInst = LoadLibrary("E:\\DMSUSER\\bin\\Debug\\lib2.dll");
if (DllInst)
{//my code}
Posted
Updated 12-Jul-20 21:56pm
Comments
11917640 Member 20-Mar-19 2:32am
   
https://docs.microsoft.com/en-us/windows/desktop/Dlls/dynamic-link-library-search-order Dynamic-Link Library Search Order, see Standard Search Order for Desktop Applications.
1. The directory from which the application loaded (exe directory). 2. The system directory. 3. The Windows directory. 4. The current directory. 5. PATH
11917640 Member 20-Mar-19 2:33am
   
If it works under debugger, the difference is probably in the current directory.
JMMS Karunarathne 20-Mar-19 6:29am
   
all dlls are in same directory, if i deploy with absolute path is works, problem is if some user install to custom directory dll not loading.
Rick York 20-Mar-19 15:42pm
   
His first comment is VERY important and is the key to your problem. You have three options : 1. require that the DLLs are in one of the 5 places listed above; 2. have the user tell you where they are through a configuration option if not in one of those places; 3. search the drive(s) and find them yourself. There are no other options available.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You must learn about program execution. It is a complex field, so you may start in the Microsoft documentation.

Every process is running in some directory and it may NOT be the directory of the module. Look into the project settings where it is, because the debugger controls that with some settings.

Important: in a complete solution your exe use the COMPLETE path for dll loading, so you are app is safe against dll injection attacks!!!
   
Comments
JMMS Karunarathne 20-Mar-19 6:27am
   
all dll are same directory, note, if I use complete dll path it works, problem is when any user install to custom directory dll not loading and system fails.
Rate this:
Please Sign up or sign in to vote.

Solution 2

There are a few things to check here...

1) Are all the DLLs the same bitness (32 or 64 bit - but you can't mix them).
2) What dependencies do they have? What C++ / C runtime DLLs are they linked against? Are they installed.
3) Try running your program, monitored by Sysinternals Process Monitor. Watch what it's trying to do when it tries to load the DLLs.
4) Check GetLastError when trying to load the DLL.
5) PS What OS (and what bitness) are you using?

Good luck

Mike
   
Comments
JMMS Karunarathne 20-Mar-19 6:25am
   
thank mike for your comment, all dll are 32bit and no any dependencies for c++ dlls. os is windows 7 32bit. i will try your 3 and 4 and comment result.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Thank you all for your all comments, i have figured it out and solved it. thanks for all.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100