Calling win32 C++ dll from C#

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi there,

I need to make a call into an unmanaged DLL from a C# application, and I am
getting a SafeArrayTypeMismatchException which basically means that either
what I am sending to the DLL is incorrect, or what I am getting out is not
what the C# code expects.

My question is this: How do I know which array is the troublesome one?
Within the call there are numerous arrays all contained within different
structs.

Regards,

FV
 
Can you post the function prototype? I'd guess there's some sort of
pointer to a buffer and a length parameter as a minimum?
 
FrancoisViljoen said:
[DllImport("filename.dll", EntryPointentrypointname")]
private static extern int DoStuff(ref Series pData, ref StdStat
pStdstat, ref Settings pSettings, ref EXSM pExSm, ref BOXJ pBj, ref SMA pSma,
ref Dscr pDsc, ref Croston pCroston);

where each of the parameters is a struct of which some contain arrays.




DeveloperX said:
Can you post the function prototype? I'd guess there's some sort of
pointer to a buffer and a length parameter as a minimum?

It's best that you can also post your code to show us how you call it.
 
FrancoisViljoen said:
[DllImport("filename.dll", EntryPointentrypointname")]
private static extern int DoStuff(ref Series pData, ref StdStat
pStdstat, ref Settings pSettings, ref EXSM pExSm, ref BOXJ pBj, ref SMA
pSma,
ref Dscr pDsc, ref Croston pCroston);

where each of the parameters is a struct of which some contain arrays.

When you define those structs in C#, you probably need to be using the
"fixed" keyword, otherwise C# assumes they are SAFEARRAYs.
 

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

Back
Top