Hi all,
I've inherited a code-base which uses existing DLLs that contain all of our statistical algorithms. In the .NET development environment, the DLLs execute fine and return as expected. Moreover, when I compile the .NET project to an .exe, I am able to run it locally on the same machine that the development was done on. However, when I attempt to port the executable (along with the DLLs, which I store in the same directory as the .exe) to other machines, the program crashes, with no error message, when the DLL is called (I verified this by removing the DLL call and compiling, and the program ran with no problem). In our Wrapper class (CoreAlgorithms.cs), I have the following code:
[DllImport(@"dcdflib.dll", EntryPoint = "cdft", ExactSpelling = false,
CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe void cdft(int* which, double* p, double* q, double* mult, double* df, int* status, double* bound);
I then call this method as follows:
unsafe
{
CoreAlgorithms.cdft(&which, &p, &q, &mult, &df, &status, &bound);
}
Again, this works fine in .NET and my machine, but fails immediately on other machines. Does anyone have any idea as to I'm doing incorrectly here? Any help or pointers would be greatly appreciated. Thank you for your time.
Loading
Mike GoldPosted Jul 26, 2007, 10:48 PM
It's lucky you had the source code for the statistical dlls.
Thanks for posting how you solved the problem.
Best,
byron wallacePosted Jul 26, 2007, 9:38 AM
Mike GoldPosted Jul 25, 2007, 6:44 PM
Hi Byron,
Is it possible that your machine contains certain dlls that the dllimport dll is dependent on and other machines don't? One thing you can do is use Depends.exe to see if the dll you are importing depends on other dlls. If you run depends on the machine that the unmanaged dll is on, it will tell you which dlls it is dependent on that are missing.
Also make sure that all COM objects used by the dll are registered with regsvr32.exe
byron wallacePosted Jul 25, 2007, 1:11 PM
Update: I have handled the generated exception on the call and output the Exception trace. Here it is:
First, the exception message is: "Unable to load DLL 'dcdflib.dll': This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)"
And the StackTrace:
System.DllNotFoundException: Unable to load DLL 'dcdflib.dll':
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. (Exception from HRESULT: 0x800736B1)
(At the call to the dll method)
The DLL is in the same directory as the executable.
Mike GoldPosted Jul 25, 2007, 12:07 PM
e.g.
[DllImport("cpplib.dll", ExactSpelling = true)]
Best,private static extern void GiveMeADouble(ref double myVal);
Pass it as follows
double myDoubleValue = 15.0d;
GiveMeADouble(ref myDoubleValue);