471,306 Members | 1,238 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 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 1395
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Rachel Suddeth | last post: by
1 post views Thread by Sparhawk | last post: by
6 posts views Thread by marek | last post: by
6 posts views Thread by Stephen Walch | last post: by
9 posts views Thread by Amit Dedhia | last post: by
2 posts views Thread by Jon Slaughter | last post: by

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.