Failed to call unmanaged functions in C++ dll compiled in Visual 6.0

  • Thread starter Thread starter trantanm
  • Start date Start date
T

trantanm

Hi everybody,
I failed to call unmanaged functions in C++ dll from C# application.
If I compile and produce the C++ dll file in .NET environment, I can
call them from C#. Is the reason that the C++ dll file compiles on the
different platform? Is there any way to correct the problem?
Appreciate your help.
IfOnce.
 
Can you show some of your code? Without seeing what exactly you are
trying to do, it's very difficult to say.
 
Nicholas,
Thank you for your response.


My DriverFunctionTests.cpp has the following:
extern "C" __declspec(dllexport) void __stdcall InitDriver( unsigned
short uChannel )
{
pclDriver = new ClDriverWrap( uChannel );
}

My DataWrapper.cs has these:
[DllImport("DriverLibrary.dll")]
public static extern void InitDriver( ushort uChannel );

[DllImport("DriverLibrary.dll")]
public static extern void ResetDriver();

[DllImport("DriverLibrary.dll")]
public static extern bool IsDriverLoaded( ushort uChannel,
[In(),arshalAs(UnmanagedType.LPArray)] byte [] strMessage );

And my DriverTester.cs has:
static void Main()
{
try
{
Application.Run(new Driver_Tester());
}
catch( Exception ex )
{
MessageBox.Show( "Driver_Tester.Main(): " + ex.Message );
}
}
private void Driver_Tester_Load(object sender, System.EventArgs e)
{
ClDataWrapper.InitDriver(0);
}

To compile the whole solution in .NET, I put DriverFunctionTests.cpp in
the project DriverLibrary, and I put DataWrapper.cs and DriverTester.cs
in anther project DriverTester. After compiling, I copy and paste the
DriverLibrary.dll to the Debug folder of the project DriverTester.

If I compile this solution in .NET, the code works great. However, if I
remove the project DriverLibrary, compile DriverFunctionTests.cpp in
Visual Studio 6.0, copy and paste the dll file, then the C# code throws
the exception saying "Unable to load the DriverLibrary.dll".

Appreciate your help.
 
Back
Top