On 2003-12-08, Ken Kast <an*******@discussions.microsoft.com> wrote:
I'm using VBFixedString to create fixed length strings.
But I find that the string will merrily allow a string of
greater length to be assigned to it. Is this the way
things are supposed to work?
I've got a more basic question. The reason I'm doing all
this is so I can pass a string buffer to an unmanaged
method in a dll. It's assuming 1 byte/char. Does that
mean that my fixed length should be half the size the
buffer is supposed to be?
Thanks.
Ken
If it is a one byte char to an unmanaged api, then you probably want to
do some thing like:
<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
Structure Struct
Public TheChar As Char
End Struct
Declare Ansi Function MyFunc Lib "MyLib.Dll" _
(ByRef TheStruct As Struct) As Integer
For fixed lenght strings you'll want to use
MarshalAs(UnmanagedType.ByValTStr, SizeConst:=YourSize)
--
Tom Shelton
MVP [Visual Basic]