jp2code
Joined: 18 Jun 2010 Posts: 2 Location: Longview, TX
|
Posted: Fri Jun 18, 2010 3:36 pm Post subject: P/Invoke Setup Help |
|
|
I have a government supplied library written in C++ that is supplied with the original source code, and the files for this code are included as a separate Project in my Visual Studio 2008 Solution.
I followed examples found online on how to call these native routines from my managed Windows application, but the calls fail.
Here is the definition of one of the methods I need to call:
| Code: |
EXPORT int steadyFor(double Par[], double Inlet[], double Outlet[], char* FileIn, char* FileOut);
|
From looking at the source code, I have learned the following:
Outlet is an array that I allocate and get results back with.
FileIn and FileOut are both paths to files that contain additional parameters.
I tried creating a wrapper for the library in a "GovProj" class using C# syntax, but it did not work:
| Code: |
[DllImport(MODELAPP, EntryPoint = "steadyFor", ExactSpelling = false)]
public static extern int SteadyFor(double[] par, double[] inlet, ref double[] outlet, char[] input, char[] output);
|
The error returned was:
| Quote: |
| Unable to load DLL 'GovProj.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E) |
The "GovProj" is loaded with the rest of my solution, so I guess this means I wrote my Dll Import incorrectly, because the DLL compiles and is included in my solution.
Could someone offer me help with this? I'd love to get on Microsoft's MSDN site, but somehow our old proxy is incompatible with whatever Microsoft is doing. The MSDN sites can't get through our proxy, and work does not care to spend the money for me to have access to code that they feel I should already know how to do. {ugh!}
UPDATE: After more internet research, I found that the GovProj.DLL must be manually copied to my bin/Debug folder. I did that and the "Unable to load DLL" error went away and got replaced with this error:
| Quote: |
| An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B) |
I'd like to add the GovProj's output to my project's list of References, but my attempt to do so results in VS2008 telling me:
| Quote: |
| A reference to '{path}\GovProj.dll' could not be added. Please make sure that the file is accessible, and that it is a valid assembly or COM component. |
So, how do I make sure my DLL is a valid assembly or COM component? _________________ ~Joe
http://avoidsearshomeimprovement.blogspot.com/ |
|