DLL warpper help!! Nick Paldino

B

bob

How to wrap the following function using PInvole-

VARIANT _stdcall retVariantArray(void) {
COleSafeArray saRet;
DWORD numElements[] = {10, 10}; // 10x10

// Create the safe-array...
saRet.Create(VT_R8, 2, numElements);

// Initialize it with values...
long index[2];
for(index[0]=0; index[0]<10; index[0]++) {
for(index[1]=0; index[1]<10; index[1]++) {
double val = index[0] + index[1]*10;
saRet.PutElement(index, &val);
}
}

// Return the safe-array encapsulated in a VARIANT...
return saRet.Detach();
}

PS:: Nick Paldino I learnt you are an expert on interop.
 
N

Nicholas Paldino [.NET/C# MVP]

Bob,

I'm curious where you heard I am an expert on Interop. I'd have to
thank that person. =)

In order to wrap this function, I think you want to do the following:

[DllImport("dllname.dll")]
[return:MarshalAs(UnmanagedType.Struct)]
public static extern object retVariantArray();

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top