I am about to transfer a project written in Applescript and Objective C to Excel/VBA/dll. I have started with the Objective C functions that I want to place in a dll and call via VBA. The Objective C is C with a thin dusting of special Obejctive C code to have it talk with Applescript and the rest of the project so in theory it should be easy to make dlls written in C from it.
But I have already problems with the tiniest of all functions.
Here is my original Objective C code:
and here is what I am trying to use in Visual Studio (minfil.c):
Here is what the code is supposed to do:
If games = 0 and gameskifte =1, return 1
If games = 0 (and by default gameskifte is not 1), return 2
If games < 3 and gameskifte =1, return games + 2
If games < 3 (and by defalut gameshift is not 1), return games + 4
If games > 2 and gameskifte =1, return games + 3
If games > 2 and gameskifte =2, return games + 5
What it does is ignore the value of gameshift and ALWAYS returns games + 4 as highligted.
I have tried to change the code ever so slightly and it seems like every time the code test if the variables games or gameshift are equal to some number it throws a false and every time it asks if they are smaller than some numer it throws a true
I use a .def file (defFile.def):
In VBA I have placed the following:
Any idea whats going wrong here?
But I have already problems with the tiniest of all functions.
Here is my original Objective C code:
Code:
- (NSNumber *)game:(NSNumber *)games gamechange:(NSNumber *)gameskifte
{
int gamesab = [games intValue];
int gameskifteab = [gameskifte intValue];
int gamesud = 0;
if (gamesab == 0){
if (gameskifteab == 1) gamesud=1;
else gamesud=2;}
else{
if (gamesab<3){
if (gameskifteab==1)gamesud=gamesab+2;
else gamesud=gamesab+4;}
else{
if (gameskifteab==1)gamesud=gamesab+3;
else gamesud=gamesab+5;
}
}
return [NSNumber numberWithInt:gamesud];
}
and here is what I am trying to use in Visual Studio (minfil.c):
Code:
int _stdcall spil(int *games, int *gameskifte)
{
if (*games < 1){
if (*gameskifte < 1) return *games + 1;
else return *games + 2;}
else{
if (*games < 3){
if (*gameskifte==1) return *games + 2;
[B] else return *games + 4;}[/B]
else{
if (*gameskifte<2) return *games + 3;
else return *games + 5;
}
}
return 0;
}
Here is what the code is supposed to do:
If games = 0 and gameskifte =1, return 1
If games = 0 (and by default gameskifte is not 1), return 2
If games < 3 and gameskifte =1, return games + 2
If games < 3 (and by defalut gameshift is not 1), return games + 4
If games > 2 and gameskifte =1, return games + 3
If games > 2 and gameskifte =2, return games + 5
What it does is ignore the value of gameshift and ALWAYS returns games + 4 as highligted.
I have tried to change the code ever so slightly and it seems like every time the code test if the variables games or gameshift are equal to some number it throws a false and every time it asks if they are smaller than some numer it throws a true
I use a .def file (defFile.def):
Code:
LIBRARY "minfil"
EXPORTS
game = spil
In VBA I have placed the following:
Code:
Private Declare Function game Lib "c:\users\musholm\documents\visual studio 2013\Projects\mitprojekt\Debug\mitprojekt.dll" (ByRef games As Integer, ByRef gameskifte As Integer) As Integer
Function game1(games As Integer, gamesskifte As Integer) As Integer
game1 = game(games, gamesskifte)
End Function
Any idea whats going wrong here?