![]() |
| |||||||
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 |
| Registered User Join Date: Jun 2009 Location: Madrid, Spain.
Posts: 4
| How to export functions of a DLL in Visual Studio 2008 with the actual name? Code: __declspec (dllexport) int WINAPI foo(int foo2) {
return 0;
}
Then I tried this: Code: extern "C" __declspec (dllexport) int WINAPI foo(int foo2) {
return 0;
}
Is there any way that the exported name of the function is just foo? Thanks for your time. Last edited by Kall; 06-14-2009 at 12:49 PM. |
| Kall is offline | |
| | #2 |
| Guest Join Date: Aug 2001
Posts: 4,923
| __declspec (dllexport) should only be defined when compiling the dll. You could do something like this: Code: #ifndef DLL_HPP
#define DLL_HPP
#include <windows.h>
#ifdef __cplusplus
#define EXTERN_C extern "C"
#else
#define EXTERN_C
#endif
#ifdef BUILDING_DLL
#ifdef USE_DEFAULT_DLL_MAIN
BOOL APIENTRY DllMain( HINSTANCE, DWORD, LPVOID )
{
return TRUE;
}
#endif
#define DYNAMIC EXTERN_C __declspec ( dllexport )
#else
#define DYNAMIC EXTERN_C
#endif
#endif /* DLL_HPP */
Code: // foo.hpp #ifndef FOO_HPP #define FOO_HPP #include "dll.hpp" DYNAMIC int WINAPI foo(int); #endif /* FOO_HPP */ Code: // foo.cpp
#define BUILDING_DLL
#define USE_DEFAULT_DLLMAIN
#include "dll.hpp"
#include "foo.hpp"
DYNAMIC int WINAPI foo(int foo2) {
return 0;
}
|
| Sebastiani is offline | |
| | #3 |
| Registered User Join Date: Jun 2009 Location: Madrid, Spain.
Posts: 4
| Thank you very much for the info! Doing it that way makes it more maintainable, but the results are the same. I keep getting a dll with that function exported but with the name of "_foo@4" instead of "foo". I generated that dll with the actual foo function, just as you wrote it. Thanks for everything and your time, Kall. |
| Kall is offline | |
| | #4 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Yes, the naming convention of the function is based on the calling convention. Since DLL's are (normally) called by STDCALL calling convention, it appends a @X where X is the number of bytes cleaned up by the calling function. This avoids problems where the caller passes N parameters, and the function cleans up the space of M parameters and M != N. In the CDECL calling convention, it's the caller cleaning up the stack, so the compiler in itself is responsible for both putting the arguments ON the stack and taking them OFF the stack when the function has returned. This means that there is no need to keep track of the number of bytes passed to the function in itself in the same way (e.g. passing an extra argument won't cause the stack to go out of whack). Why do you care what the function name is? I'm sure you have good reasons, I'm asking to understand what the right solution may be, not because I don't think you have a good reason. Edit: I should point out that WINAPI will become stdcall calling convention once the compiler sees the code. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. Last edited by matsp; 06-14-2009 at 04:57 PM. |
| matsp is offline | |
| | #5 | |
| Registered User Join Date: Jun 2009 Location: Madrid, Spain.
Posts: 4
| Quote:
. I'm trying to write a plugin for a closed source program (so I can't access its sources). The program looks for a certain function in plugins DLLs in runtime which represents an interface with it, that's why the exported name needs to be exactly the same what they say. That function returns a pointer to a structure composed by some flags and several defined functions so that it can interact with the plugin.In the SDK there is an example of how that function is (or may be) and they use WINAPI as calling convention. Thanks for everything and your time, Kall. | |
| Kall is offline | |
| | #6 |
| Cat without Hat Join Date: Apr 2003
Posts: 8,439
| You can use linker definition scripts (.def) to export functions with unmangled names.
__________________ All the buzzt! CornedBee"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code." - Flon's Law |
| CornedBee is offline | |
| | #7 | |
| Registered User Join Date: Jun 2009 Location: Madrid, Spain.
Posts: 4
| Thanks! Quote:
If it is because of the calling conventions, can I remove WINAPI safely as it becomes stdcall in the end? I've noticed that removing it the name of the functions is the correct name, but I wonder if the program could load it correctly. Thanks for everything, Kall. | |
| Kall is offline | |
![]() |
| Tags |
| dll, export, symbols, visual studio 2008 |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| New to Visual Studio 2008 | bargomer | C++ Programming | 5 | 09-19-2008 02:16 PM |
| Visual Studio crashed with using java.exe to load DLL | George2 | C Programming | 1 | 08-14-2007 02:38 AM |
| Visual Studio Express 2008 problems. | Normac | C++ Programming | 2 | 08-08-2007 10:41 AM |
| using classes | krazykrisi | C++ Programming | 9 | 11-22-2006 10:41 AM |
| Visual Studio Express for free | Frobozz | C# Programming | 2 | 04-29-2006 09:59 PM |