DLL export, decorated function

  • Thread starter Patrick Westerhoff
  • Start date
P

Patrick Westerhoff

Hello,

I'm currently working on a small DLL that will be used as an extension to a
working application. It is required that the DLL has only one export named
"C16_DLLCALL". So I started creating a DLL in Visual C++ 2008 using the Win32
application wizard for DLLs and changed it so it would work for our
application.
However when I build the DLL file and look at it using dumpbin.exe /exports,
the exported function is not exactly called "C16_DLLCALL". Depending on the
function declaration I get one of the following export names:

?C16_DLLCALL@@YAHPAUvC16_CCB@@@Z = ?C16_DLLCALL@@YAHPAUvC16_CCB@@@Z (int
__cdecl C16_DLLCALL(struct vC16_CCB *))
when using: __declspec(dllexport) [...]

C16_DLLCALL = _C16_DLLCALL
when using: extern "C" __declspec(dllexport) [...]

I have got a example DLL from the application developers and when I look at
it using dumpbin, it exactly has the required name, without equally signs or
other characters, just a plain "C16_DLLCALL" - and in that case the
application finds the entry point within the dll. However with any of my
DLLs, it fails.
How can I export the function without having its export name changed at all?

Thank you,
Patrick Westerhoff
 
P

Patrick Westerhoff

Hi SvenC,

thank you for your answer. I tried that now but received the following
exports:

C16_DDLCALL = ?C16_DLLCALL@@CAHPAUvC16_CCB@@@Z (int __cdecl
C16_DLLCALL(struct vC16_CCB *))
when using only the .def file without any additional things in the function
declaration
and
C16_DDLCALL = _C16_DDLCALL
when using the .def with extern "C" __declspec(dllexport)

both don't work in the application :(

Patrick Westerhoff
 
S

SvenC

Hi Patrick,
thank you for your answer. I tried that now but received the following
exports

Reread the article and find:
"If you are *not using* the __declspec(dllexport) keyword to export
the DLL's functions, the DLL requires a .def file."

Instead you should specify the calling convention explicitly in your
header so that you do not depend on vc project defaults.

extern "C" __stdcall C16_DDLCALL(struct vC16_CCB *);
 
S

SvenC

Hi Patrick,
Hm, sorry but I don't get it :( So before I continue
misunderstanding, I'll post a bit from my code:

C16DLL.def

Did you add the def file to your project property settings?

Config Props/Linker/Input/Module Definition File
 
P

Patrick Westerhoff

Hi SvenC,

yes, it was added there automatically when I created it.

Patrick
 
G

Giovanni Dicanio

"Patrick Westerhoff" <[email protected]> ha
scritto nel messaggio
C16DLL.def

That is good.

C16DLL.h (apart from that only has the standard definition of C16DLL_API
__declspec(dllexport) etc.)

OK.
(But I would prefer useinga #ifdef __cplusplus guard here...)

C16DLL.cpp (includes also stdafx.h which is including some header files
for
the different types/structs I have to use so that they work with the
target
application)

I think the problem is here.
This is a .CPP file, so I think that you should add 'extern "C"' explicitly
here:

// Function implementation in .cpp file
extern "C" vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
{
...
}

HTH,
Giovanni
 
P

Patrick Westerhoff

Hi Giovanni,

thank you for your answer, however sadly it didn't solve the problem either..

Giovanni Dicanio said:
OK.
(But I would prefer useinga #ifdef __cplusplus guard here...)

I actually tried that in between, but it will probably not change the
results if it doesn't work without.
I think the problem is here.
This is a .CPP file, so I think that you should add 'extern "C"' explicitly
here:

// Function implementation in .cpp file
extern "C" vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
{
...
}

When I try this explicitely, it gives me
C16_DDLCALL = _C16_DDLCALL@4
Does it help if I would change the file extensions to .c or change the
compiler settings so that it would compile as a C project?

Thank you,
Patrick Westerhoff
 
G

Giovanni Dicanio

Hi Patrick,

"Patrick Westerhoff" <[email protected]> ha
scritto nel messaggio
When I try this explicitely, it gives me
C16_DDLCALL = _C16_DDLCALL@4
Does it help if I would change the file extensions to .c or change the
compiler settings so that it would compile as a C project?

You could change the extension to .c, but I think it is not necessary; I
mean: you can still use C++ and have a "pure-C" interface.

Note that my answer is an addition to correct Sven's suggestion of using
..def files for exporting.

I will do a test...

Giovanni
 
S

SvenC

Hi Patrick,
yes, it was added there automatically when I created it.

I do expect the same as Giovanni and I guess his test project
should work for you.

Maybe you should give us a minimal sample, which includes the
missing types: vERROR and vC16_CCB.

extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );

Maybe some weird preprocessor side effects are going on?

What happens when you put this test function in your header:

extern "C" int __stdcall TestFoo(int);


And this in your cpp:

extern "C" int __stdcall TestFoo(int x)
{
return x;
}
 

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