0

我从 pinvoke 网站复制并粘贴了以下 VB.NET 结构。

http://www.pinvoke.net/default.aspx/Structures/BITMAPINFOHEADER.html

但是,当我将它粘贴到这样的模块名称下的模块中时,VB.NET 告诉我需要声明:

Option Strict Off
Option Explicit On

Imports System
Imports System.Diagnostics
Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Runtime.InteropServices
Imports System.Windows.Forms

Module modDrawing

    StructLayout(LayoutKind.Explicit)>Public Structure BITMAPINFOHEADER
    <FieldOffset(0)> Public biSize As Int32
    <FieldOffset(4)> Public biWidth As Int32
    <FieldOffset(8)> Public biHeight As Int32
    <FieldOffset(12)> Public biPlanes As Int16
    <FieldOffset(14)> Public biBitCount As Int16
    <FieldOffset(16)> Public biCompression As Int32
    <FieldOffset(20)> Public biSizeImage As Int32
    <FieldOffset(24)> Public biXPelsperMeter As Int32
    <FieldOffset(28)> Public biYPelsPerMeter As Int32
    <FieldOffset(32)> Public biClrUsed As Int32
    <FieldOffset(36)> Public biClrImportant As Int32
End Structure

请问我哪里做错了?非常感谢你。

4

2 回答 2

1

看看这个:(不是完整的代码)

    Module modDrawing

        <StructLayout(LayoutKind.Explicit)> _
        Public Structure BITMAPINFOHEADER
            <FieldOffset(0)> Public biSize As Int32
            <FieldOffset(4)> Public biWidth As Int32
            <FieldOffset(8)> Public biHeight As Int32
            <FieldOffset(12)> Public biPlanes As Int16
            <FieldOffset(14)> Public biBitCount As Int16
            <FieldOffset(16)> Public biCompression As Int32
            <FieldOffset(20)> Public biSizeImage As Int32
            <FieldOffset(24)> Public biXPelsperMeter As Int32
            <FieldOffset(28)> Public biYPelsPerMeter As Int32
            <FieldOffset(32)> Public biClrUsed As Int32
            <FieldOffset(36)> Public biClrImportant As Int32
        End Structure

   End Module
于 2012-11-14T17:05:28.330 回答
0

pinvoke.net 代码中的错误是该属性缺少初始的<. 代替

StructLayout(LayoutKind.Explicit)>

它应该读

<StructLayout(LayoutKind.Explicit)>

但是,LayoutKind.Explicit在这里并不是很明智。当然你可以指定所有的字段偏移量,但为什么要让自己很难呢?使用LayoutKind.Sequential. 由于这是默认设置,您可以简单地省略该属性。

Public Structure BITMAPINFOHEADER
    Public biSize As Int32
    Public biWidth As Int32
    Public biHeight As Int32
    Public biPlanes As Int16
    Public biBitCount As Int16
    Public biCompression As Int32
    Public biSizeImage As Int32
    Public biXPelsperMeter As Int32
    Public biYPelsPerMeter As Int32
    Public biClrUsed As Int32
    Public biClrImportant As Int32
End Structure
于 2012-11-14T17:50:01.483 回答