DLL exporting function names - aliases
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: DLL exporting function names - aliases

  1. #1
    Join Date
    Sep 2009
    Posts
    7

    DLL exporting function names - aliases

    Hi,

    my problem is, that I have to compile a few programs with VS2005 and other programs with Watcom (OpenWatcom to be exact). A lot of DLLs, most of them with stdcall calling convention.

    Watcom is exporting all functions twice, as the dependency walker shows:

    Code:
    Function               EntryPoint
    _grafixLibFileInfo@4   0x000010A7
    grafixLibFileInfo      0x000010A7
    Visual Studio is exporting the functions only once
    Code:
    Function               EntryPoint
    _grafixLibFileInfo@4   0x00011267
    I'm using

    Code:
    #define	DLL_EXPORT	__declspec(dllexport) __stdcall
    long  DLL_EXPORT grafikLibFileInfo(struct GRAFLIBFILE *gLibFile)
    {
    ...
    }
    no def file

    Is there any chance, to export the functions like Watcom does?

    Otherwise I have to change all the GetProcAddress calls from e.g.
    grafixLibFileInfo to _grafixLibFileInfo@4

    Thanks in advance

  2. #2
    Join Date
    Jul 2002
    Posts
    2,494

    Re: DLL exporting function names - aliases

    What about exporting functions once, but without C++ name mangling, grafixLibFileInfo and not _grafixLibFileInfo@4 ?
    This can be done by using extern "C":

    http://msdn.microsoft.com/en-us/libr...3s(VS.80).aspx

  3. #3
    Join Date
    Sep 2009
    Posts
    7

    Re: DLL exporting function names - aliases

    Quote Originally Posted by Alex F View Post
    What about exporting functions once, but without C++ name mangling, grafixLibFileInfo and not _grafixLibFileInfo@4 ?
    This can be done by using extern "C"
    it's plain C - the DLL I'm talking about at least.

    This name decoration with underscore is an old 16 bit thing - afaik.
    Add the @4 is showing the bytecount of the parameters. If two long would be passed, there would be a @8 - it's not a C++ function name.

    But thanks nevertheless for your reply.

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,881

    Re: DLL exporting function names - aliases

    Quote Originally Posted by Alex F View Post
    What about exporting functions once, but without C++ name mangling, grafixLibFileInfo and not _grafixLibFileInfo@4 ?
    This can be done by using extern "C":

    http://msdn.microsoft.com/en-us/libr...3s(VS.80).aspx
    _grafixLibFileInfo@4 already is extern "C".
    Best regards,
    Igor

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,881

    Re: DLL exporting function names - aliases

    Is there any chance, to export the functions like Watcom does?
    Sure, just build it with Watcom.

    Now getting serious. VC++ mangles the function this way, and there is no other way to change the behavior, except one of explicit specifications:
    • .def file or
    • #pragma comment(linker, "/export:grafixLibFileInfo=_grafixLibFileInfo@4")
    Best regards,
    Igor

  6. #6
    Join Date
    Sep 2009
    Posts
    7

    Re: DLL exporting function names - aliases

    Quote Originally Posted by Igor Vartanov View Post
    Sure, just build it with Watcom.
    I'm quite a Watcom-fan :-) the debugger is really great - just missing the possibility to code in teh debugger like in VS and changing from debugging to coding.

    Quote Originally Posted by Igor Vartanov View Post
    • .def file or
    • #pragma comment(linker, "/export:grafixLibFileInfo=_grafixLibFileInfo@4")
    Thanks for responding. I'll give the pragma a try ... curious whether that'll work.

  7. #7
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,881

    Re: DLL exporting function names - aliases

    Quote Originally Posted by FrankieH View Post
    I'll give the pragma a try ... curious whether that'll work.
    I'll be surprized if that won't.

    Code:
    // 17.cpp
    extern "C" __declspec(dllexport) 
    int __stdcall foo(int a) { return 0; }
    
    #pragma comment(linker, "/export:foo=_foo@4")
    Code:
    D:\Temp\17>cl 17.cpp /link /dll /out:17.dll
    Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    17.cpp
    Microsoft (R) Incremental Linker Version 8.00.50727.762
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    /out:17.exe
    /dll
    /out:17.dll
    17.obj
       Creating library 17.lib and object 17.exp
    
    D:\Temp\17>exports 17.dll
    ModuleType:
      PE executable (DLL)
    Subsystem:
      Win32 GUI
    ModuleName:
      17.dll
    Exported Info: BaseOfOrdinals    = 1
                   NumberOfNames     = 2
                   NumberOfFunctions = 2
    
      RelVirtAddr  Ord  Hint   ExportedFuncName
    
      0x00001000     1     0   _foo@4
      0x00001000     2     1   foo
    Best regards,
    Igor

  8. #8
    Join Date
    Sep 2009
    Posts
    7

    Re: DLL exporting function names - aliases

    thanks again - it's working fine ....

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center