2

I have a dll that contains more then 400 function, and my exe file is using only 15 function from the dll, so i need to create a new dll and export the functions and fake their return values to simulate an output of a more complex system.

What i have tried :

 #include "stdafx.h"

//the compiler complains about the '@20'

__declspec ( dllexport ) XLStatus _xlActivateChannel@20(XLportHandle,  XLuint64, unsigned int, unsigned int)
{
    return 0;
} 

// causing the exe to crash

dumpbin /exports vxlapi.dll (original dll): show duplicate function names (not for all functions)

ordinal  name
         _xlActivateChannel@20
14       xlActivateChannel

Note : in the header file of the dll, the functions are declared like so:

DECL_STDXL_FUNC ( xlActivateChannel, XLACTIVATECHANNEL, (
                  XLportHandle  portHandle,
                  XLaccess      accessMask,
                  unsigned int  busType,
                  unsigned int  flags)
                  );

in dumpbin / export dll why there are function names starting with an '_' underscore and ending with '@number' , Note: the exe is using the let's say(decorated) functions, and how can i create a new dll and export functions that contains @,

Stoura
  • 63
  • 5
  • 2
    First, the "@" denotes the number of bytes the parameter list takes up. Second, to get rid of the "@", [see this answer](https://stackoverflow.com/questions/31282683/dll-call-with-stdcall-getprocaddress-in-vs2013/31283377#31283377). In short, you need to use a module definition file in your build of the DLL. – PaulMcKenzie Dec 25 '18 at 05:53
  • @PaulMcKenzie its mentionned that a .def file is not needed when using __declspec(dllexport) https://learn.microsoft.com/en-us/cpp/build/reference/exports?view=vs-2017#remarks – Stoura Dec 25 '18 at 06:35
  • 1
    Of course you don't need a DEF file. You *do* need one if you expect to have your exported function names to use no decoration whatsoever (just a clean function name without any decoration). I am not sure what you're trying to accomplish, but whatever it is, you need to know when, where, and why all of those decorations are done -- isn't that the question you were asking? There is the `C++` name mangling, and the Windows "mangling" -- both are separate, and both handled differently. – PaulMcKenzie Dec 25 '18 at 07:20
  • by a module definition file you mean a header file isn't it ? excuse me im new to this, and c++ – Stoura Dec 25 '18 at 07:24
  • 1
    No, a module definition file is merely a text file that describes your exports, and optionally gives them a "clean" name. That's the only way I know of to accomplish creating exported names using the Visual C++ toolset, and have the exported names show up without any *Windows* decoration (the "@" stuff). This has been the case since I believe the Windows OS was created, even back in the 16-bit days, and it has not changed since. – PaulMcKenzie Dec 25 '18 at 07:25
  • @PaulMcKenzie what i want to accomplish is to redefine the 15 functions in a new dll and substitute the old dll – Stoura Dec 25 '18 at 07:27
  • I don't think you're going about this the right way. The "old" DLL remains as is. Your DLL simply calls the old DLL functions in a new exported function that you defined. Maybe you're overcomplicating this whole thing. All of this stuff with renaming functions, figuring out exports, etc. I don't think any of that is necessary. – PaulMcKenzie Dec 25 '18 at 07:31
  • @PaulMcKenzie you mean dll injection , and then export the newly created functions with the same name using a .def file ? actually i have tried that and it works but the responsible didn't like that.. I'm confused, here is my email: belha99@hotmail.fr I'd need some help(orientation) in this If you mind – Stoura Dec 25 '18 at 07:49
  • No, not DLL injection. You create a "regular" DLL that simply has function(s) that call the original DLL's functions. Can you do that? If so, then just wrap those function you created that calls/wraps the original functions and export those new function. – PaulMcKenzie Dec 25 '18 at 08:14
  • Now its clear to me , I will try that, Thanks a lot!!. – Stoura Dec 25 '18 at 08:59

2 Answers2

2

The "@n" is used by the stdcall calling convention. You don't need to mention it in your declaration, you just need to change your declaration to stdcall so that the compiler knows they need to be decorated with "@n" suffixes. Like this:

__declspec ( dllexport ) XLStatus __stdcall _xlActivateChannel(XLportHandle,  XLuint64, unsigned int, unsigned int)
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
1

Name mangling is typical for C++ etc which is why you see these symbols in the exports. Ansi C exports are not mangled. The @ symbol is not allowed. You might try AT or _AT.

extern "C" is used to remove mangling for C types. Is does not work with class or other C++ types.

I read too fast, but John is more correct.