PDA

View Full Version : Passing Structure pointer to windows dll call fails



NewsArchive
12-06-2001, 01:00 AM
I am using the OLE Array to SafeArray code from the online help to generate
a pointer to a user defined structure.

The call to the fucntion in the windows dll is crashing.

string s1(128);
string s2(128);

typedef foo
begin
number n1;
number n2;
pointer p1;
pointer p2;
number n3;
end;

foo pointer pfoobar;
foo bar;
bar.p1 = &s1;
bar.p2 = &s2;

I pass bar to the function call below like so

pfoobar = ArrayToPointer(bar);

WindowsDLLFunctionCall(pfoobar); ?? BAM!!!

and pass the returned pointer to my function call in a dll.
wndows shuts down the setup when I make the call.
Any ideas???

then from the online help

/* Define a data structure that mirrors the safearray format. */
typedef _SAFEARRAY
begin
SHORT cDims;
SHORT fFeatures;
LONG cbElements;
LONG cLocks;
POINTER pvData;
end;

/* Define a data structure that mirrors the OLE Automation VARIANT format.
*/
typedef _VARIANT
begin
SHORT vt;
SHORT wReserved1;
SHORT wReserved2;
SHORT wReserved3;
NUMBER nData;
end;

prototype POINTER ArrayToPointer(BYREF VARIANT);

function POINTER ArrayToPointer(array)
_VARIANT POINTER pVariant;
_SAFEARRAY POINTER pArray;
begin
/* Cast a pointer to the array as an OLE VARIANT pointer. */
pVariant = &array;
/* Get a pointer to the safearray. */
pArray = pVariant->nData;
/* Return a pointer to the array data. */
return pArray->pvData;
end;