[Mono-list] CustomMarshaler for structure element using P/Invoke

Bill Medland billmedland at mercuryspeed.com
Mon Nov 14 22:54:57 EST 2005


Can any expert on P/Invoke tell me if what I want to do is 
impossible; it's looking that way to me.

I want to make P/Invoke calls with structures containing strings, 
but unfortunately they aren't quite strings in the usual sense.  
I can almost get there by using ByValTStr on the strings but 
unfortunately I don't want them null-terminated; I want fixed 
well-known lengths (specified by the SizeConst parameter of the 
attribute).

For example in C I have

typedef struct {
unsigned short length;
char mystring1 [8];
signed int myint;
char mystring2 [12];
} mystruct;

void myfunc (const mystruct *input);

I just about see how I could do this if I marshal the whole 
structure myself but I actually want to let the default 
marshaling handle the hard work and just let me marshal the char 
arrays (since actually there are several structures)

I don't see any documentation anywhere that explains in enough 
detail how the custom marshaling occurs to let me do this.  Does 
anyone know?

TIA
-- 
Bill Medland
mailto:billmedland at mercuryspeed.com
http://webhome.idirect.com/~kbmed


More information about the Mono-list mailing list