Thread: DLL Function Decoration

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    5

    DLL Function Decoration

    I have a question based on an experience I recently had over on StackOverflow:

    If I declare functions in my win32 dll like this:
    Code:
    #ifdef __cplusplus
    extern "C" {       
    #endif
    
    __declspec(dllexport) HWND      gethwnd(void);
    __declspec(dllexport) HINSTANCE getinst(void);
    __declspec(dllexport) int       getid(void);
    __declspec(dllexport) LRESULT CALLBACK dllProc(HWND, UINT, WPARAM, LPARAM );
    
    #ifdef __cplusplus
    }
    #endif
    A session in dumpbin for the DLL shows the exports as:
    Code:
    gethwnd
    getinst
    getid
    _dllProc@16
    Why doesn't the <extern "C"> declarator un-decorate the CALLBACK (__stdcall) function as well as the __cdecl functions (all the 'get' functions are __cdecl)?

    It was suggested that a def file may have forced a name change on the __cdecl exports, however, there is no def or lib file involved in any of this, the dll is loaded and it's exports parsed internally by the caller (ala Matt Pietrek) which then gets pointers to the functions of interest.

    It was also suggested that the __stdcall convention always lists the argument-bytes (@16) because the callee pops the args off the stack, so this decoration behavior is normal for __stdcall functions.

    I'd like to know that the decoration behavior is consistent (one way or the other) since the caller depends on this.
    .
    Last edited by morongo; 12-06-2010 at 10:46 AM.

  2. #2
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    extern "C" specifies just the linkage, the linkage + calling convention specifies the default decoration and Microsoft decided that stdcall exports default to having an underscore prefix and the number of parameter bytes as a suffix. If you don't change it, that's what you get. You need to use a def file to specify a 'normal' plain name.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    5
    Quote Originally Posted by adeyblue View Post
    ...the linkage + calling convention specifies the default decoration...
    Thank you, adeyblue, for making this clear.

    In my case, it doesn't matter either way just so it's consistent (and even then, any decoration could be worked-around if push came to shove).

    Thanks again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  4. Problem in returning value from the dll exported function
    By dattaforit in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2006, 04:30 AM
  5. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM