hi,
I've created DLL to use some functions from QuantLib library in Excel.
I've just try something to see how it works and discovered that if I use
switch()case in my C++ function, these code coud result in different ways.
The C++ function noco(int) is coded in DLL this way:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
FXDELTADLL_API double __stdcall CFXdeltaDLL::noco(int callput){
Option::Type ot_;
switch(callput){
case 1:
ot_=Option::Call;
return 111;break;
case 0:
ot_=Option::Put;
return 1000;break;
default:
return 12345;
break;}
return 44443;
}
|
I've declared it in the VBA editor:
|
Declare Function noco Lib "C:/Visual Studio 2010/Projects/FXdeltaDLL/Debug/FXdeltaDLL.dll" (ByVal callput As Integer) As Double
|
and then I can use it in MS Excel just like ordinary function, typing
but. I was shocked when I discovered that the same declaration
returns me sometimes what I want for argument=1 (111, and this is obviously OK),
but sometimes returns the default 12345. The same with 0. What is the reason? Maybe I should call it ByRef?