James Whetstone
2/5/2007 9:22:00 PM
Thanks for the suggestion. I just tried it by adding
[In, Out] to the parameter on the Pinvoke siginiture. So it looked like
this:
public static extern int fun(string name, my_id_t id, [In,Out]my_buffer_t
buffer);
I also changed the class to a struct and changed the pinvoke signiture to
this:
public static extern int fun(string name, my_id_t id, [In,Out] ref
my_buffer_t buffer);
But that didn't work either. Any other thoughts or comments?
Cheers,
JW
"TDC" <NOtcarvinSPAM@lycos.com> wrote in message
news:1170685614.384106.283150@h3g2000cwc.googlegroups.com...
>I think the fact that you are using formatted classes instead of
> structs in your code require you to flag the parameter with the
> InAttribute and OutAttribute ( [In, Out] ). Otherwise it would
> default to In only.
>
>
>
> On Feb 4, 11:18 pm, "James Whetstone" <jameswhetst...@comcast.net>
> wrote:
>> Oops, forgot to add the pinvoke signiture:
>>
>> [DllImport("mylib.dll")]
>>
>> public static extern int fun(string name, my_id_t id, my_buffer_t
>> buffer);
>>
>> So when I run my code, the buffer is corrupted/invalid memory.
>>
>> Can you guys help out with some code or point my in the right direction?
>>
>> Thanks!
>> JW
>>
>> "James Whetstone" <jameswhetst...@comcast.net> wrote in message
>>
>> news:t7WdnSN0HqWVMlvYnZ2dnUVZ_qqrnZ2d@comcast.com...
>>
>>
>>
>> > Hi,
>>
>> > I'm using Pinvoke and C# interop to interface to a C DLL. The DLL
>> > function signiture is as follows:
>>
>> > int fun(char *name, my_id_t *id, my_buffer_t *buffer);
>>
>> > The user defined types (in C) are as follows:
>>
>> > struct my_id_t
>> > {
>> > unsigned char guid[16];
>> > }
>>
>> > struct my_subbuffer_t
>> > {
>> > int format;
>> > }
>>
>> > struct my_buffer_t
>> > {
>> > int count;
>> > my_subbuffer_t **bufferArray;
>> > }
>>
>> > So I'm having trouble with the 3rd argument---my_buffer_t.
>>
>> > This is what I've got so far in C#:
>>
>> > [StructLayout(LayoutKind.Sequential)]
>> > public class my_id_t
>> > {
>> > [MarshalAs(UnManagedType.ByValArray, SizeConst=16)]
>> > public byte[] myGuid;
>> > }
>>
>> > [StructLayout(LayoutKind.Sequential)]
>> > public class my_subbuffer_t
>> > {
>> > public int format;
>> > }
>>
>> > [StructLayout(LayoutKind.Sequential)]
>> > public class my_buffer_t
>> > {
>> > public int count;
>> > my_subbuffer_t [] buffers;
>> > }- Hide quoted text -
>>
>> - Show quoted text -
>
>