C++ DLL and Excel

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
 
=noco(987654)


but. I was shocked when I discovered that the same declaration
 
=noco(1)

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?
I've found the answer.
I'm not sure why it doesn't work with int, but with double it does.
So, the function is:

1
2
3
4
5
6
7
8
9
10
FXDELTADLL_API double __stdcall CFXdeltaDLL::noco(double callput){
		Option::Type ot_;
		if(callput==1.0){
			ot_=Option::Call;
			return 111;}else if(callput==0){
						ot_=Option::Put;
						return 1000;}else{
						return 12345;}
		return 44443;
	}


and declaration in VBA editor:

 
Declare Function noco Lib "C:/Visual Studio 2010/Projects/FXdeltaDLL/Debug/FXdeltaDLL.dll" (ByVal callput As Double) As Double
Does anyone know what is the reason that if argument is int then sometimes there are problems with it / sometimes not?
Topic archived. No new replies allowed.