Help me marshal this struc please!

  • Thread starter Ant?nio Calado Lopes
  • Start date
A

Ant?nio Calado Lopes

Hi all, I need to marshal this struc. I have an object of this type
that goes as an argument in a dll to which i dont have source code
acess. here is the struc in c++

struct _TSNAPINFO {
UCHAR resolution;
UCHAR quality;
TCHAR filename[100];
int inbufferlen;
unsigned char *imgbuff;
int *outbufferlen;
}

Im trying to declare it in C# as
public class _TSNAPINFO
{
public byte resolution = 0;
public byte quality = 0;
public StringBuilder filename;
public int inbufferlen = 0;
public byte[] imgbuff = null;
public IntPtr outbufferlen;
}

Im declaring the fucntion that needs it as :
[DllImport("SDIOCam",SetLastError=true)]
public static extern bool SDIOCamSnapShot(IntPtr hCam, ref
_TSNAPINFO snapshotinfo);

everytime I call it i get a unsupported exception which is due to the
parameter snapshotinfo for sure. the problem is in marshalling the
structure. Can someone help me out?

thanks in advance
Antonio Calado Lopes
 
C

Chris Tacke, eMVP

It's got an interned array as well as a pointer to a char array. You'll
have to manually marshal this thing as a byte[] and have accessors to get
the members. For the char array, you'll have to allocate and deallocate
memory manually, so there's a risk of memory leaks as well.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
 

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