-
Having problem with StructLayout & MarshalAs in Beta 2
Well I finally got my SCSI DVD drive installed. Then I went through
the mental cruelity of install the Beta 2 on my WIN2K Pro system. Oh
happy thoughts 8-), let's jump right in and try to run one of my Beta 1
programs. What a cruel trick 8-(. The use of StructLayout and
MarshalAs now gives me compiler errors with code that worked in Beta 1.
I
guess that's why they call the blues (sorry, Beta). Any suggestions??
'
' Beta 2 documentation on structure definitions:
'
[ <attrlist> ] [{ Public | Protected | Friend | Protected Friend | Private
}] Structure name
[ variabledeclarations ]
[ proceduredeclarations ]
End Structure
'
' VB Program:
'
Imports System
Imports System.Text
Imports System.Console
Imports System.Runtime.InteropServices.StructLayoutAttribute
Module Module1
Sub Main()
End Sub
End Module
Public Class Class1
<StructLayout(LayoutKind.Sequential)> Public Structure Record1
Public Field1 As Integer
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
Public Field2 () As Byte
End Structure
End Class
'
'Works in Beta1
'
'Public Class Class1
' Public Structure <StructLayout(LayoutKind.Sequential)> Record1
' Public Field1 As Integer
' Public <MarshalAs(UnmanagedType.ByValArray, SizeConst:=8)> _
' Field2 () As Byte
' End Structure
'End Class
'
' Note:
' The ordering of the <StructLayout...> and <MarshalAs...> differ in
' what works in Beta1 and what the documentation states in Beta 2
-
Re: Having problem with StructLayout & MarshalAs in Beta 2
Hi Patrick,
>Imports System
>Imports System.Text
>Imports System.Console
>Imports System.Runtime.InteropServices.StructLayoutAttribute
What you're missing is an Import for just the
System.Runtime.InteropServices namespace. Perhaps that's what you
wanted on the last line, because there's no reason that I can see to
Import StructLayoutAttribute (or any other attribute type).
Mattias
===
Mattias Sjögren (VB MVP)
mattias @ mvps.org
http://www.msjogren.net/dotnet/
-
Re: Having problem with StructLayout & MarshalAs in Beta 2
Mattias,
Thanks, that was a combination I had not tried yet and it does work.
Looking at the Beta1 vs Beta2 code, the order placement of the attribute
clause appears to have changed. Or I suffering under bleary eyed, fingers
typed to the bone delusions?
Code I used in Beta 1
Public Structure <StructLayout(LayoutKind.Sequential)> StrucName ...
whereas Beta 2 requires
<StructLayout(LayoutKind.Sequential)> Public Structure StrucName ...
mattias.dont.want.spam@mvps.org (Mattias Sjögren) wrote:
>Hi Patrick,
>
>>Imports System
>>Imports System.Text
>>Imports System.Console
>>Imports System.Runtime.InteropServices.StructLayoutAttribute
>
>What you're missing is an Import for just the
>System.Runtime.InteropServices namespace. Perhaps that's what you
>wanted on the last line, because there's no reason that I can see to
>Import StructLayoutAttribute (or any other attribute type).
>
>
>Mattias
>
>===
>Mattias Sjögren (VB MVP)
>mattias @ mvps.org
>http://www.msjogren.net/dotnet/
-
Re: Having problem with StructLayout & MarshalAs in Beta 2
"Patrick Ireland" <ireland@airmail.net> wrote:
>
>Mattias,
>
>Thanks, that was a combination I had not tried yet and it does work.
>Looking at the Beta1 vs Beta2 code, the order placement of the attribute
>clause appears to have changed. Or I suffering under bleary eyed, fingers
>typed to the bone delusions?
>
It has changed.
The attribute placement is more consistant now.
-Rob
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks