I’m trying to write a WPF application which uses a function defined in C++. The C++ application is compiled as a DLL.
What I’m doing is using the DllImport attribute to import the function and use it. This works fine on my machine but when I attempt to run my WPF application on another machine it gives a “cannot find the DLL” error.
An excerpt of my C# (WPF) code:
[DllImport("Dll.dll")]
public static extern int MyFunc();
public MainWindow()
{
InitializeComponent();
MessageBox.Show("Starting");
try
{
MessageBox.Show(MyFunc().ToString());
}
catch (Exception exc)
{
while (exc != null)
{
MessageBox.Show(exc.Message);
exc = exc.InnerException;
}
}
My C++ code:
extern "C" __declspec(dllexport) int MyFunc() {
return 3;
}
Can anyone see where my error might be?
Thanks in advance for your help!
EDIT: It would appear that the issue is that the dependency “MSVCR100D” isn’t present. My understanding is that this is a file in the VC++ Redistributable package which I have installed by to no avail.
Your DLL might depend on other DLLs that are not installed on the other machine. You can check the dependencies with Dependency Walker.
Typical missing dependencies are the Visual Studio C/C++ Runtime libraries. If they are missing, just google for it. Microsoft offers redistributable packages for them.