|
-
April 20th, 2009, 03:30 PM
#1
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
-
April 20th, 2009, 04:35 PM
#2
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.
-
April 21st, 2009, 12:17 AM
#3
Re: Stdcall naming convention & Excel
 Originally Posted by naos
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
-
April 21st, 2009, 12:23 AM
#4
Re: Stdcall naming convention & Excel
 Originally Posted by naos
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
-
April 21st, 2009, 04:18 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|