473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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

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.

Jul 6 '06 #1
2 1442
Can you show some of your code? Without seeing what exactly you are
trying to do, it's very difficult to say.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<tr******@yahoo.comwrote in message
news:11*********************@75g2000cwc.googlegrou ps.com...
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.

Jul 7 '06 #2
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.

Jul 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
1
by: sunil s via DotNetMonster.com | last post by:
Hi, I've got a native C++ app which calls a 3rd parth .NET DLL using the LoadLibrary/GetProcAddress functions. This works fine when the DLL is located in the app directory, but if I move it out...
2
by: joye | last post by:
Hello, My question is how to use C# to call the existing libraries containing unmanaged C++ classes directly, but not use C# or managed C++ wrappers unmanaged C++ classes? Does anyone know how...
13
by: Bern McCarty | last post by:
I have run an experiment to try to learn some things about floating point performance in managed C++. I am using Visual Studio 2003. I was hoping to get a feel for whether or not it would make...
2
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking afterwards with ILDASM at what is visible in those assemblies from a...
14
by: Jon | last post by:
Whether I can compile a class or not, depends on the order of functions in my class. My question is (see example below): 1) Is it a bug that the class 'WillCompile' will compile and execute, or...
0
by: Ken Durden | last post by:
A little more info. I have a unmanaged C++ DLL, compiled without /CLR. Inside a Managed C++ DLL, I have the following class: MarshalWrapper.h ---- #ifdef _MANAGED __nogc #endif
0
by: =?Utf-8?B?UGFy?= | last post by:
Hi I have a question on how to import unmanaged DLLs into Visual Studio 2005, C# environment. The background is that an instrument we bought is controlled through a couple of DLL files. I...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.