DLL exported functions Issue

M

Mohammad Omer

I am writing code for creating DLL using vs2k5. My project is using
Crypto++ lib project, which has a function (ComputeHash), and with the
same name of function I have written in project with a little bit
change as follows

Crypto++ function:
protected: unsigned int __thiscall
CryptoPP::Deflator::ComputeHash(unsigned char const *)const

My function:
unsigned char * __stdcall ComputeHash(char *)

For exporting function I am using "__declspec(dllexport)", by using
declspec my exported functions will be name mangled (right??) and if I
do a function over loading of the same function, it also works fine.

If I want to export functions with out name mangling, using def file it
result in a link error. My understanding is that error comes because
over loading is not allowed using unmangled exported function, is that
right?
But, if I use
extern "C" unsigned char * __stdcall ComputeHash(char *)

Name mangling will be removed against this function extern "C" will
be the part of function signatures. If I have two functions, they
overload each other and wants to export these functions with out name
mangling the question is how to full fill this need? I seen that if one
function exported by def and other function exported by using extern
"C", both will be export successfully and will not be name mangled.
My first question, what is the difference of exporting function by
using extern "C" and def files?

Regards,

-aims
 
B

Bruno van Dooren [MVP VC++]

My function:
unsigned char * __stdcall ComputeHash(char *)

For exporting function I am using "__declspec(dllexport)", by using
declspec my exported functions will be name mangled (right??)

If you do nothing else, then yes. All names will be mangled.
If I want to export functions with out name mangling, using def file it
result in a link error. My understanding is that error comes because
over loading is not allowed using unmangled exported function, is that
right?

Indeed. you can export overloaded functions, but not without name mangling
because name mangling is used by the compiler to determne which function to
call.
But, if I use
extern "C" unsigned char * __stdcall ComputeHash(char *)

Name mangling will be removed against this function extern "C" will
be the part of function signatures.

Nope. extern "C" only behaves like that for functions that are __cdecl.
For __stdcall it won't work, and your function will still be mangled.
You can verify this with depends.exe
overload each other and wants to export these functions with out name
mangling the question is how to full fill this need?

Not.
As I explained above, name mangling is essential to overloading.


--

Kind regards,
Bruno van Dooren
(e-mail address removed)
Remove only "_nos_pam"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top