473,325 Members | 2,860 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,325 software developers and data experts.

Unmanaged C++ DLL use in C#

I made a simple DLL in C++ application and exported the
fnQuickTimeWrapper that returns the value 42.
I the C# application I do the following:
[DllImport("C:\\Work\\QuickTimeStreamer\\QuickTimeW rapper\\Debug\\QuickTimeWrapper.dll")]
private static extern int fnQuickTimeWrapper();

When I try to get the 42 value of fnQuickTimeWrapper() from the DLL it
says that the entry point was not found but the DLL was loaded
correctly. (DepedencyWalker says that the function is exported as
?fnQuickTimeWrapper and I don't see any problem in this)

I hope C# behaves correctly with C++ DLL's as well as with COM DLL's.

Does anyone, who has done such DLL's, know what the problem is?

Thank you.

Feb 11 '06 #1
1 1432
I met your problem before, it is because c# doesn't recognise the name
of your exported function, go to dos and type:

dumpbin /exports yourdll.dll

you should see the name of your exported function. What happens is
visual c++ "decorated" the name of your fonction for example if your
function name is GetWindowTitle VC++ will export under the mangled name
: ?GetWindowTitle@@blahblah so C# is clueless...

msdn says :

The Microsoft C++ compilers encode the names of symbols in C++ programs
to include type information in the name. This is called "name
decoration", or "name mangling". The purpose of this is to ensure
type-safe linking. The C++ language allows function overloading where
functions with the same name are only distinguished from one another by
the data types of the arguments to the functions. Name decoration
enables the linker to distinguish between different versions of
overloaded functions because the names of the functions are encoded or
decorated differently.

ONE POSSIBLE SOLUTION:

All you have to do is to create and add a file : yourdll.def

you type in it :

; Yourdll.def - defines the exports for yourdll.dll

LIBRARY yourdll
DESCRIPTION 'A C++ dll that can be called from c#'

EXPORTS
YourFunction
Your recompile your dll project to create the updated dll

try again

dumpbin /exports yourdll.dll

You will see your function with the proper name ;)

What you did with the .def file is : you told C# that the name
associated with
[DllImport("C:\\Work\\QuickTimeStreamer\\QuickTimeW rapper\\Debug\\QuickT
imeWrapper.dll")]
private static extern int fnQuickTimeWrapper(); is YourFunction and not
the VC++ decorated name :)

Hope I could help you :) I am sure you will make it!
IRNBRU


*** Sent via Developersdex http://www.developersdex.com ***
Feb 12 '06 #2

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...
2
by: Paul Kenny | last post by:
Hi, I am trying to expose the functionality of an unmanaged C++ class to the other languages available in the .NET Framework. I have decided to do this by wrapping the unmanaged C++ class in a...
4
by: Rachel Suddeth | last post by:
What is the difference between a managed/unmanaged resource, and how do you tell which is which? I'm trying to understand how to write some Dispose() methods, and we are supposed to put code that...
3
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
1
by: Sparhawk | last post by:
Hi, my company is going to migrate a large VC++ application to .NET to make use of Windows Forms (the old class library is not updated any more). We are not planning to migrate the rest of the...
6
by: marek | last post by:
Hello All, we are doing a quite a big project that contains at the lowest level an unmenaged c++ classes. Above it there are managed wrappers and at the top there are ASP.NET pages. Can anyone...
6
by: Stephen Walch | last post by:
Our application environment consists of three basic layers: 1. Third-party unmanaged DLLs that were written before the CLR was invented and maintain a significant amount of information (including...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
5
by: akash | last post by:
I'm having problems calling an unmanaged class from a managed wrapper. I suspect I'm missing something obvious, as I'm unfamiliar with C++ and classes are very simple. My unmanaged class is as...
2
by: Jon Slaughter | last post by:
How difficult is it for one to integrate unmanaged C++ into C#? I know for functions one can use DLLimport but how does one go about doing it for classes? Do I have to completely reimplement the...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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: 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
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.