I have a C++ dll that I am trying to call in another section of code (happens to be C#)

currently I am getting the following error:

Additional information: Unable to load DLL 'MATLABThreadLibrary.dll': The specified module could not be found.

even though I believe I've got all the correct paths defined...

anyone have any suggestions? Google has proven fruitless.

As far as I can tell, the C# gui is not finding my C++ DLL -- does anyone know how to wrap C++ code to export into C#? Or is that more a C# forum question?

copy the dll into the windows installation directory such as c:\windows and see if that fixes the problem. If it does fix it then you just need to put the dll into one of the paths that is in your PATH environment variable.

my PATH environment contains the folder that the DLL is being placed into... er... by that I mean I added the DLL's path to the additional dependencies directory...?

by that I mean I added the DLL's path to the additional dependencies directory...?

PATH does not mean the 'additional dependencies directory'. Windows searches for the .dll at run-time as specified in Dynamic-Link Library Search Order

PS. You can check your PATH environment variable simply by typing PATH in a command prompt, every path displayed by the command will be used for loading .dlls.

my PATH environment contains the folder that the DLL is being placed into... er... by that I mean I added the DLL's path to the additional dependencies directory...?

I see you failed to do the test I asked you to do, consequently what you did was useless. The additional dependencies path in your compiler's IDE means nothing at runtime.

I hesitated to do this because I can't install the DLL on all of the machines that will need to run this code. I understand that what I did is useless, but I'm not convinced it'll be useful to go around manually dragging a DLL into everybody's c:\windows directory either

... especially seeing as doing just that did nothing -- with the DLL in c:\windows I'm still getting the same error.

I'll eventually need to be able to ship the DLL with the file itself or add in a line of code that will add my DLL to the PATH directory.

This is my first DLL... is there some sort of initialization function you have to use to dynamically load a DLL? Or is that stuff set up by the compiler? I bet I need to write some sort of DLL init(); don't I?

I hesitated to do this because I can't install the DLL on all of the machines that will need to run this code. I understand that what I did is useless, but I'm not convinced it'll be useful to go around manually dragging a DLL into everybody's c:\windows directory either

That suggestion was for testing purposes on your development computer only. Final release version you should install the DLL in your program's application directory then add the path to that directory to the computer's PATH environment variable.

... especially seeing as doing just that did nothing -- with the DLL in c:\windows I'm still getting the same error.

At the command prompt enter the word PATH, press <Enter> key, and look to see if c:\windows is one of the paths that your computer displays. If not, put the dll in another directory that is in the PATH.

When I write a program that uses a DLL I link the program with the DLL's *.lib file which was created by the compiler when you compiled the DLL.

C:\WINDOWS is there

In the meantime I've been poking around trying to figure out how to wrap my original C++ DLL with a managed C++ class... I think that if the code is managed I'll have an easier time calling it with C#?

This article has been dead for over six months. Start a new discussion instead.