Create DLL with undecorated names

  • Thread starter Thread starter Doug Gordon
  • Start date Start date
D

Doug Gordon

I want to create an "MFC DLL" with VC.NET that will be explicitly loaded
when needed. That is, the main application will do a "LoadLibrary" call and
then a series of "GetProcAddress" calls to set up the entry points. What I
want is to be able to refer to the entry points as simple names, e.g.,
"MyFunction", as opposed to the "decorated" names that C++ generates by
default. So what I am asking about is the syntax for declaring the functions
in the DLL code.

I think I've done this in the distant past, and all I remember is stringing
together a lot of declarations and macros like "__dllexport", "WINAPI",
"__stdcall", etc. Does anyone have an example of how to do what I am looking
for here? Thanks.

Doug G
 
Doug said:
I want to create an "MFC DLL" with VC.NET that will be explicitly loaded
when needed. That is, the main application will do a "LoadLibrary" call and
then a series of "GetProcAddress" calls to set up the entry points. What I
want is to be able to refer to the entry points as simple names, e.g.,
"MyFunction", as opposed to the "decorated" names that C++ generates by
default. So what I am asking about is the syntax for declaring the functions
in the DLL code.

I think I've done this in the distant past, and all I remember is stringing
together a lot of declarations and macros like "__dllexport", "WINAPI",
"__stdcall", etc. Does anyone have an example of how to do what I am looking
for here? Thanks.

Doug G

extern "C" is the only answer that you will get from this newsgroup.
__dllexport, et al. will need to be addressed in a Windows specific newsgroup.
 
Julie said:
extern "C" is the only answer that you will get from this newsgroup.
__dllexport, et al. will need to be addressed in a Windows specific newsgroup.

Scratch that! I thought I was in comp.lang.c++ -- sorry!

Here is what you need to do:

#ifdef __cplusplus
extern "C" {
#endif

__dllexport void YourFunctionHere(int some, int another);

#ifdef __cplusplus
}
#endif

That should do the trick for you.
 
(from MSDN)
There are three methods for exporting a definition, listed in recommended
order of use:

__declspec(dllexport) in the source code
An EXPORTS statement in a .def file
An /EXPORT specification in a LINK command

All three methods can be used in the same program. When LINK builds a
program that contains exports, it also creates an import library, unless an
..exp file is used in the build.

LINK uses decorated forms of identifiers. The compiler decorates an
identifier when it creates the .obj file. If entryname is specified to the
linker in its undecorated form (as it appears in the source code), LINK
attempts to match the name. If it cannot find a unique match, LINK issues an
error message. Use the DUMPBIN tool to get the decorated names form of an
identifier when you need to specify it to the linker.
.....

(or use to extern "C" to "undecorated" the name)
Each one has it's plus ans minus.

Reagrds Jan
 
Julie said:
Scratch that! I thought I was in comp.lang.c++ -- sorry!

Here is what you need to do:

#ifdef __cplusplus
extern "C" {
#endif

__dllexport void YourFunctionHere(int some, int another);

#ifdef __cplusplus
}
#endif

That should do the trick for you.

I'm striking out on this one: replace __dllexport with __declspec(dllexport).
 
Back
Top