13.3. Call an Unmanaged Function That Uses a Structure
Problem
You need to call an unmanaged function, such as GetVersionEx, that accepts a structure as a parameter.
Solution
Define the structure in your VB .NET code. Use the attribute System.Runtime.InteropServices.StructLayoutAttribute to configure how the structure fields are laid out in memory. Use the Shared SizeOf method of the System.Runtime.InteropServices.Marshal class if you need to determine the size of the unmanaged structure in bytes.
How It Works
In VB .NET code, you are not able to directly control how type fields are laid out once the memory is allocated. Instead, the CLR is free to arrange fields to optimize performance, especially in the context of moving memory around during ...
Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.