Fixed length buffers

P

Paul

I'm doing some Pinvoke stuff. How do I deal with functions that
pass/receive structures that have fixed length char buffers?

I see this:

public struct MyArray // This code must appear in an unsafe block
{
public fixed char pathName[128];
}

in the docs, but this is upposed to be for c#2.0. I am presuming C#2.0
is not what I am using with VS .Net circa 2003. Is that right?

Any advice much appreciated...

Paul
 
T

Tom Shelton

I'm doing some Pinvoke stuff. How do I deal with functions that
pass/receive structures that have fixed length char buffers?

I see this:

public struct MyArray // This code must appear in an unsafe block
{
public fixed char pathName[128];
}

in the docs, but this is upposed to be for c#2.0. I am presuming C#2.0
is not what I am using with VS .Net circa 2003. Is that right?

Any advice much appreciated...

Paul

// change charset to proper type for your application...
[StructLayout (LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct MyArray
{
[MarshalAs (UnmanagedType.ByValTStr, SizeConst=128)]
public string pathName;
}

If you have a specific declaration, it would be much easier to answer :)
 

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