2012-12-27 123 views
1

此編譯沒有錯誤,但是當運行此代碼段出現一些奇怪的錯誤:VB .NET,傳遞枚舉值作爲函數參數

檢測FatalExecutionEngineError 消息:運行時遇到致命錯誤。錯誤的地址爲0x792062fb,線程0xd7c。錯誤代碼是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 

有什麼不好?

+0

嘗試SetPolicy(1,3,a)並查看是否給出錯誤。 – theGD

+0

另請嘗試'SetPolicy(1,PipePolicyType.PIPE_TRANSFER_TIMEOUT,a)' –

+0

如果您指出這是一個您正在調用的Win32函數將會很好 –

回答

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 
+0

我很贊,因爲它很完美,謝謝你的努力。我發現問題完全在其他地方(見下圖) – user1797147

2

好的稱呼它,我發現這個問題完全別的地方,我不明白。有一個與我的枚舉一點問題都沒有,有些好奇的錯誤在一些包裝非託管:

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

這是由我縮短了前幾天這樣

Dim PUnmanagedDetailedInterfaceDataStructure As IntPtr = Marshal.AllocHGlobal(StructureSize) 

什麼是第二個聲明問題?!