CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2009
    Posts
    2

    Stdcall naming convention & Excel

    Hello,

    It's been few hours since I started writing C++ DLL in order to use them in my Excel's worksheets, and I'm dealing with a naming problem.

    When I make a C++ function, I write something like :
    Code:
    extern "C" __declspec (dllexport) int __stdcall 
    getOne() {
        return 1;
    }
    The dll is compiled with VS 2008.

    Then, in Excel (2007), I write :
    Code:
    Declare Function getOne Lib _
    "..PATH..\dll_for_excel.dll" _
    () As Long
    
    Function getOneByC(trigger As Double) As Double
    getOneByC = getOne()
    End Function
    And... it does not work. As a result, I get "#VALUE!", which means that Excel did not find a function named "getOne" in my DLL. So, I run dumpbin /exports and I see that my getOne function has been renamed as "_getOne@0".
    After reading documentation on the Internet, I've come to the conclusion that such a name is a consequence of using __stdcall (@0 because no argument, etc..).

    The only solution to overcome this problem I found is to use a DEF file. If so, all the "declspec(...)" and "extern "C" " are useless!

    Of course, I can't use "_getOne@0" as a name in my Excel's declaration. And it would not be an acceptable solution.

    Does anyone know how to proceed in order to avoid the DEF file and have it working ?

    Thank you

    C.L

  2. #2
    Join Date
    Apr 2003
    Posts
    1,755

    Re: Stdcall naming convention & Excel

    You can set the actual function name using "Alias"
    Code:
    Declare Function getOne Lib "..PATH..\dll_for_excel.dll" Alias "_getOne@0" () As Long
    If you don't want to do that, you can add "/export:getOne" to your linker.

  3. #3
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Stdcall naming convention & Excel

    Quote Originally Posted by naos View Post
    Hello,

    It's been few hours since I started writing C++ DLL in order to use them in my Excel's worksheets, and I'm dealing with a naming problem.
    Why are you avoiding the DEF file? That's what it's used for, and that is to make the exported name "clean".

    Regards,

    Paul McKenzie

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Stdcall naming convention & Excel

    Quote Originally Posted by naos View Post
    The only solution to overcome this problem I found is to use a DEF file. If so, all the "declspec(...)" and "extern "C" " are useless!
    No.

    The extern "C" is required to remove the C++ decoration from the name. It has nothing to do with the "@0" that gets appended by default to a Windows exported function.

    Regards,

    Paul McKenzie

  5. #5
    Join Date
    Apr 2009
    Posts
    2

    Re: Stdcall naming convention & Excel

    Ok, I think I'll use a DEF file...


    Thank you

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured