Thanks for the reply. I tried your suggestions and also
was browsing through MSDN again but still dont't come to
a result.
Based on your examples I created the following minimal
definition for some testing:
<StructLayout(LayoutKind.Sequential)> _
Public Structure struct1
<MarshalAs(UnmanagedType.ByValTStr, SizeConst:=2)> _
Public svar1 As String
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> _
Public struc2array() As struct2
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure struct2
Public ivar1 As System.Int32
Public ivar2 As System.Int32
'Public structvar3 As struct3
End Structure
<StructLayout(LayoutKind.Sequential)> _
Public Structure struct3
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> _
Public iarray() As Int32
Public ivar3 as System.Int16
End Structure
When I now call the DLL which is declared with just one
input parameter (ByRef as structure1) I get the following
error:
Can not marshal field struc2array of type struct1: This
type can not be marshaled as a structure field.
I get this error in both cases with the "Public
structvar3 As struct3" commented out and not. I was
reading on the net that it is not yet possible to marshal
arrays in a struct, could this be the problem?
I also tried to redim all arrays (including all arrays in
the arrays) according to there size but that was also of
little help.
Any hint?
Thanks, Bernhard
[quoted text, click to view] >-----Original Message-----
>This link on the MSDN is a good reference.
>
>
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/cpguide/htm
>l/cpcondefaultmarshalingforarrays.asp?frame=true
>
>As far as your specific case, here is a good place to
start:
>
>>
>>Type DS_FLT_INFO
>> Name As String * 100
>> HasProperties As Long
>> lpISPP As Long
>> lpIFB As Long
>>End Type
>>
>
><StructLayout(LayoutKind.Sequential)> _
>Public Structure DS_FLT_INFO
> <MarshalAs(UnmanagedType.ByValTStr, SizeConst := 100)
> _
> Public Name as String
> Public HasProperties as System.Int64
> Public lplSPP as System.Int64
> Public lplFB as System.Int64
>End Structure
>
>>Type DS_DISPLAY
>> HdrVer As Long
>> hParentWindow As Long
>> hVideoWindow As Long
>> dwOrigWidth As Long
>> dwOrigHeight As Long
>> dwAspectRatio As Long
>> State As Long
>> FullScreen As Long
>> pIGraphBuilder As Long
>> dummy1 As Long
>> dummy2 As Long
>> XGRName As String * 500
>> FilterCount As Long
>> Filter(20) As DS_FLT_INFO
>>End Type
>>
>
>The interesting one here is the array so I'll show you
that:
>...
><MarshalAs(UnmanagedType.ByValArray, SizeConst := 20)> _
>Public Filter() as DS_FLT_INFO
>...
>
>If you need more information, check out the other topics
under Blittable
>and Non-blittable types in that part of the MSDN. It
contains good
>information about how to use attributes to marshal
structures.
>
>Michal Sampson
>VB .Net Developer
>--
>
>This posting is provided "AS IS" with no warranties, and
confers no rights.
>Use of included script samples are subject to the terms
specified at
>
http://www.microsoft.com/info/cpyright.htm >
>Note: For the benefit of the community-at-large, all
responses to this
>message are best directed to the newsgroup/thread from
which they
>originated.
>--------------------
>>Content-Class: urn:content-classes:message
>>From: "Bernhard Christl" <bernhard.christl@netbase.at>
>>Sender: "Bernhard Christl" <bernhard.christl@netbase.at>
>>Subject: Can anyone help me to declare that?
>>Date: Mon, 22 Sep 2003 02:50:48 -0700
>>Lines: 34
>>Message-ID: <091c01c380ef$004c3800$a301280a@phx.gbl>
>>MIME-Version: 1.0
>>Content-Type: text/plain;
>> charset="iso-8859-1"
>>Content-Transfer-Encoding: 7bit
>>X-Newsreader: Microsoft CDO for Windows 2000
>>X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
>>Thread-Index: AcOA7wBMU5p6rC1WToSvSWKm/9JCTA==
>>Newsgroups: microsoft.public.dotnet.languages.vb.upgrade
>>Path: cpmsftngxa06.phx.gbl
>>Xref: cpmsftngxa06.phx.gbl
>microsoft.public.dotnet.languages.vb.upgrade:5312
>>NNTP-Posting-Host: TK2MSFTNGXA11 10.40.1.163
>>X-Tomcat-NG:
microsoft.public.dotnet.languages.vb.upgrade
>>
>>I have some structure which I have to pass to a
unmanaged
>>dll which expects the data to be in memory just as it
has
>>been in VB6. My problem is marchaling fixed length
>>strings and arrays correctly. Can anybody help to get
me
>>on the right track?
>>
>>Thanks
>>Bernhard
>>
>>
>>Type DS_FLT_INFO
>> Name As String * 100
>> HasProperties As Long
>> lpISPP As Long
>> lpIFB As Long
>>End Type
>>
>>Type DS_DISPLAY
>> HdrVer As Long
>> hParentWindow As Long
>> hVideoWindow As Long
>> dwOrigWidth As Long
>> dwOrigHeight As Long
>> dwAspectRatio As Long
>> State As Long
>> FullScreen As Long
>> pIGraphBuilder As Long
>> dummy1 As Long
>> dummy2 As Long
>> XGRName As String * 500
>> FilterCount As Long
>> Filter(20) As DS_FLT_INFO
>>End Type
>>
>>
>
>.
>