Solved
c# to C++ - transfer an array of int*
Posted on 2004-10-12
So I was in a hurry the other day and couldn't figure out the *right* way to do something. Instead I ended up with this lovely funtion in my .cpp library:
int HoldEmLibrary::CompareSixHands(Deck handA, Deck handB,
Deck handC,
Deck handD,
Deck handE,
Deck board,
int *retCount,
int *retHandACount,
int *retHandBCount,
int *retHandCCount,
int *retHandDCount,
int *retHandECount,
int *retTieCount,
int *HandsA0,
int *HandsA1,
int *HandsA2,
int *HandsA3,
int *HandsA4,
int *HandsA5,
int *HandsA6,
int *HandsA7,
int *HandsA8,
int *HandsB0,
int *HandsB1,
int *HandsB2,
int *HandsB3,
int *HandsB4,
int *HandsB5,
int *HandsB6,
int *HandsB7,
int *HandsB8,
int *HandsC0,
int *HandsC1,
int *HandsC2,
int *HandsC3,
int *HandsC4,
int *HandsC5,
int *HandsC6,
int *HandsC7,
int *HandsC8,
int *HandsD0,
int *HandsD1,
int *HandsD2,
int *HandsD3,
int *HandsD4,
int *HandsD5,
int *HandsD6,
int *HandsD7,
int *HandsD8,
int *HandsE0,
int *HandsE1,
int *HandsE2,
int *HandsE3,
int *HandsE4,
int *HandsE5,
int *HandsE6,
int *HandsE7,
int *HandsE8
)
Which is called like this from an unsafe funtion in C#:
int* iHandsA = stackalloc int[9];
int* iHandsB = stackalloc int[9];
for (int icnt = 0; icnt <9; icnt++)
{
iHandsA[icnt] = 0;
iHandsB[icnt] = 0;
}
int iCount = lib.CompareTwoHands(d1,d2,d3,&iCnt,&iH1,&iH2,&iTie,
&(iHandsA[0]),&iHandsA[1],&iHandsA[2],&iHandsA[3],&iHandsA[4],&iHandsA[5],&iHandsA[6],&iHandsA[7],&iHandsA[8],
&(iHandsB[0]),&iHandsB[1],&iHandsB[2],&iHandsB[3],&iHandsB[4],&iHandsB[5],&iHandsB[6],&iHandsB[7],&iHandsB[8]);
-------------------------
Obviously this is fugly and leads to ugliness on both ends...but for the life of me, I couldn't figure out the right way to do it. Help?
-Jon