468,170 Members | 2,149 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 developers. It's quick & easy.

DLL export, decorated function

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
Oct 2 '08 #1
10 1523
Hi Patrick,
... I like to have one export named "C16_DLLCALL".
... but I get ...
C16_DLLCALL = _C16_DLLCALL
when using: extern "C" __declspec(dllexport) [...]
Add a def file to your project

http://msdn.microsoft.com/en-us/libr...sh(VS.80).aspx

--
SvenC
Oct 2 '08 #2
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

"SvenC" wrote:
Hi Patrick,

Add a def file to your project

http://msdn.microsoft.com/en-us/libr...sh(VS.80).aspx

--
SvenC
Oct 2 '08 #3
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 *);
--
SvenC

Oct 2 '08 #4
Hm, sorry but I don't get it :( So before I continue misunderstanding, I'll
post a bit from my code:

C16DLL.def
----
LIBRARY "C16DLL"
EXPORTS
C16_DLLCALL @1
----

C16DLL.h (apart from that only has the standard definition of C16DLL_API
__declspec(dllexport) etc.)
----
extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );
----

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)
----
vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
{
// ...
}
----

Apart from that I only have the default dllmain.cpp which contains BOOL
APIENTRY DllMain

Whatever suggestion I tried until now, I never was able to reduce the export
listed with dumpbin to only C16_DLLCALL resulting in the application not
recognizing the function (it actually returns an error which says that the
entry point was not found).
When I try it with the dll the developers sent to me, it works fine; I also
have the "source" (=.c file only) of that dll but I don't have any settings
for it so I'm probably not able to compile it to test if the problem is maybe
the Studio 2008 compiler (which I believe by now :/).
If it helps within the developers source, the function is defined with:
vERROR WINAPI C16_DLLCALL( vC16_CCB* aCCB )
and instead of the DllMain function they use
vINT APIENTRY LibMain ( ... )
which is the same according to what I read yesterday on the msdn library..

So where is the problem? :|

Patrick Westerhoff
"SvenC" wrote:
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 *);
--
SvenC

Oct 2 '08 #5
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
----
LIBRARY "C16DLL"
EXPORTS
C16_DLLCALL @1
----

C16DLL.h (apart from that only has the standard definition of
C16DLL_API __declspec(dllexport) etc.)
----
extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );
Did you add the def file to your project property settings?

Config Props/Linker/Input/Module Definition File

--
SvenC
Oct 2 '08 #6
Hi SvenC,

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

Patrick

"SvenC" wrote:
Hi Patrick,

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

Config Props/Linker/Input/Module Definition File

--
SvenC
Oct 2 '08 #7

"Patrick Westerhoff" <Pa***************@discussions.microsoft.comha
scritto nel messaggio
news:89**********************************@microsof t.com...
C16DLL.def
----
LIBRARY "C16DLL"
EXPORTS
C16_DLLCALL @1
That is good.

C16DLL.h (apart from that only has the standard definition of C16DLL_API
__declspec(dllexport) etc.)
----
extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );
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)
----
vERROR __stdcall C16_DLLCALL ( vC16_CCB* aCCB )
{
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
Oct 6 '08 #8
Hi Giovanni,

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

"Giovanni Dicanio" wrote:
C16DLL.h (apart from that only has the standard definition of C16DLL_API
__declspec(dllexport) etc.)
----
extern "C" vERROR __stdcall C16_DLLCALL( vC16_CCB* aCCB );

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
Oct 6 '08 #9
Hi Patrick,

"Patrick Westerhoff" <Pa***************@discussions.microsoft.comha
scritto nel messaggio
news:6C**********************************@microsof t.com...
>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?
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
Oct 6 '08 #10
Hi Patrick,
>Did you add the def file to your project property settings?

Config Props/Linker/Input/Module Definition File
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;
}

--
SvenC
Oct 6 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Shawn Mehaffie | last post: by
205 posts views Thread by Jeremy Siek | last post: by
reply views Thread by Shawn Mehaffie | last post: by
4 posts views Thread by Wolfgang Draxinger | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.