all groups > vb.net upgrade > september 2003 >
You're in the

vb.net upgrade

group:

Can anyone help me to declare that?



Can anyone help me to declare that? Bernhard Christl
9/22/2003 2:50:48 AM
vb.net 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
RE: Can anyone help me to declare that? misampso NO[at]SPAM online.microsoft.com
9/23/2003 8:42:21 PM
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:

[quoted text, click to view]

<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

[quoted text, click to view]

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.
--------------------
[quoted text, click to view]
RE: Can anyone help me to declare that? Bernhard Christl
9/25/2003 9:44:00 AM
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]

AddThis Social Bookmark Button