0
votes

note: First of all i am using visual studio 2010.

Usually i need dll with some exported functions that i need to use from outside apps..

Normally this is how my dll header looks...

#define DLLAPI extern "C" __declspec(dllexport)

DLLAPI BOOL WINAPI FUNCTION1(...);
DLLAPI BOOL WINAPI FUNCTION2(...);

I don't add any commands to the project or anything, all i do to export them is this in the headers + add DLLAPI to functions in the source file ofc.

Now when i need to get the function name from my outside app its making me problems because its always something like FUNCTION1xa1@assu79sax_ or something like that...

I saw a project which uses .DEF file and makes its headers like...

// INCLUDE FILE generated by "Pelles C for Windows, version 3.00".

#ifndef _HOOK_H
#define _HOOK_H

#ifdef _HOOK_
#define HOOKAPI  __declspec(dllexport)
#else
#define HOOKAPI  __declspec(dllimport)
#endif /* _HOOK_ */

#ifndef WINAPI
#define WINAPI  __stdcall
#endif

HOOKAPI int WINAPI SampleFunction(int, int);

#endif /* _HOOK_H */

and it's .def file looks like...

EXPORTS
    SetValuesCBT
    SetValuesKey
    SetValuesMouse
    MouseProc
    KeyProc
    CBTProc

SECTIONS
    .shared READ WRITE SHARED

This results in very clear function names exported aka just as they are called(as proven by dumpbin.exe) btw if matters, it also has .pjj file with following content...

# 
# PROJECT FILE generated by "Pelles C for Windows, version 5.00".
# WARNING! DO NOT EDIT THIS FILE.
# 

POC_PROJECT_VERSION = 5.00.1#
POC_PROJECT_TYPE = 1#
POC_PROJECT_ARGUMENTS = #
CC = pocc.exe#
AS = #
RC = porc.exe#
LINK = polink.exe#
SIGN = posign.exe#
CCFLAGS = -Tx86-coff -Ot -W1 -Ze -Gz#
ASFLAGS = -c -nologo -coff -W1 -Cu#
RCFLAGS = -r#
LINKFLAGS = -machine:ix86 -subsystem:windows kernel32.lib user32.lib gdi32.lib comctl32.lib comdlg32.lib advapi32.lib delayimp.lib -dll#
WizCreator = Pelle Orinius#
SIGNFLAGS = -location:CU -store:MY -timeurl:http://timestamp.verisign.com/scripts/timstamp.dll -errkill#
INCLUDE = $(PellesCDir)\Include\Win;$(PellesCDir)\Include#
LIB = $(PellesCDir)\Lib\Win;$(PellesCDir)\Lib#

.SILENT:

# 
# Build hook.dll.
# 
hook.dll: \
    output\DLL.obj \
    EXPORTS.DEF
    $(LINK) $(LINKFLAGS) -out:"$@" $**

# 
# Build DLL.obj.
# 
output\DLL.obj: \
    DLL.C
    $(CC) $(CCFLAGS) "$!" -Fo"$@"

.EXCLUDEDFILES:

I don't know how should i emulate this in my VS 2010 project so when i build my dll function names are simple and precise?

1

1 Answers

1
votes

Just create the DEF file as you've shown above with just your two functions and go into the link options and specify to use this def file.

From http://msdn.microsoft.com/en-us/library/34c30xs1%28v=vs.80%29.aspx

The /DEF option passes a module-definition file (.def) to the linker. Only one .def file can be specified to LINK. For details about .def files, see Module-Definition Files. To set this linker option in the Visual Studio development environment

  1. Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
  2. Click the Linker folder.
  3. Click the Input property page.
  4. Modify the Module Definition File property.

To specify a .def file from within the development environment, you should add it to the project along with other files and then specify the file to the /DEF option.