Click to See Complete Forum and Search --> : Stdcall naming convention & Excel


naos
April 20th, 2009, 03:30 PM
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 :

extern "C" __declspec (dllexport) int __stdcall
getOne() {
return 1;
}


The dll is compiled with VS 2008.

Then, in Excel (2007), I write :

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

rxbagain
April 20th, 2009, 04:35 PM
You can set the actual function name using "Alias"

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.

Paul McKenzie
April 21st, 2009, 12:17 AM
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

Paul McKenzie
April 21st, 2009, 12:23 AM
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

naos
April 21st, 2009, 04:18 AM
Ok, I think I'll use a DEF file...


Thank you