vb .net,将枚举值作为函数参数传递

时间:2012-12-27 20:06:39

标签: vb.net

这编译没有错误,但是当我运行此代码部分时会出现一些奇怪的错误:

检测到FatalExecutionEngineError 消息:运行时遇到致命错误。在线程0xd7c上,错误的地址为0x792062fb。错误代码是0xc0000005。此错误可能是CLR中的错误,也可能是用户代码的不安全或不可验证部分中的错误。此错误的常见来源包括COM-interop或PInvoke的用户封送错误,这可能会破坏堆栈。

我尝试以下内容:

    Public Enum PipePolicyType
        SHORT_PACKET_TERMINATE = 1
        AUTO_CLEAR_STALL = 2
        PIPE_TRANSFER_TIMEOUT = 3
        IGNORE_SHORT_PACKETS = 4
        ALLOW_PARTIAL_READS = 5
        AUTO_FLUSH = 6
        RAW_IO = 7
        RESET_PIPE_ON_RESUME = 9
    End Enum

...
...

        Dim a As UInt32 = 3000

        SetPolicy(1, PIPE_TRANSFER_TIMEOUT, a)

...
...
Public Sub SetPolicy(ByVal ep As Integer, ByVal PolicyType As PipePolicyType, ByVal PolicyValue As UInt32)


end sub

出了什么问题?

2 个答案:

答案 0 :(得分:2)

好的,我发现问题完全在别的地方,我不明白。我的枚举完全没有问题,在一些包装中出现了一些奇怪的错误:

    Dim PUnmanagedDetailedInterfaceDataStructure As IntPtr = IntPtr.Zero
    PUnmanagedDetailedInterfaceDataStructure = Marshal.AllocHGlobal(StructureSize)

几天前我就这样缩短了这个

    Dim PUnmanagedDetailedInterfaceDataStructure As IntPtr = Marshal.AllocHGlobal(StructureSize)

第二次申报有什么问题?!

答案 1 :(得分:0)

您需要使用PipePolicyType.PIPE_TRANSFER_TIMEOUT

来调用它
Public Class Form1
    Public Sub SetPolicy(ByVal ep As Integer, ByVal PolicyType As PipePolicyType, ByVal PolicyValue As UInt32)

    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        Dim a As UInt32 = 3000

        SetPolicy(1, PipePolicyType.PIPE_TRANSFER_TIMEOUT, a)
    End Sub
End Class

Public Enum PipePolicyType
    SHORT_PACKET_TERMINATE = 1
    AUTO_CLEAR_STALL = 2
    PIPE_TRANSFER_TIMEOUT = 3
    IGNORE_SHORT_PACKETS = 4
    ALLOW_PARTIAL_READS = 5
    AUTO_FLUSH = 6
    RAW_IO = 7
    RESET_PIPE_ON_RESUME = 9
End Enum