2011-08-11 23 views
1

將VB6代碼升級到VB.NET時遇到了錯誤。在 AddressOf WindowProc錯誤:'AddressOf'表達式無法轉換爲'Integer',因爲'Integer'不是委託類型

AddressOf表達發生了錯誤不能被轉換爲 '整數',因爲 '整數' 不是委託類型

我給SetWindowLong聲明爲:

Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"(
        ByVal hWnd As Integer, 
        ByVal nIndex As Integer, 
        ByVal dwNewLong As Integer) As Integer 

變量:

Dim GWL_WNDPROC As Short = -4 
Dim hWnd As Integer 

代碼WindowProc

Function WindowProc(ByVal hw As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer 

    Dim x As Integer 
    Dim a As String 
    Dim wp As Short 
    Dim temp As Object 
    Dim ReadBuffer(1000) As Byte 
    'Debug.Print uMsg, wParam, lParam 
    Select Case uMsg 
     Case 1025 
      Debug.Print(VB6.TabLayout(uMsg, wParam, lParam)) 
      Debug.Print(uMsg & " " & wParam & " " & lParam) 

      e_err = WSAGetAsyncError(lParam) 
      e_errstr = GetWSAErrorString(e_err) 

      If e_err <> 0 Then 
       Debug.Print("Error String returned -> " & e_err & " - " & e_errstr) 
       Debug.Print("Terminating....") 
       do_cancel = True 
       'Exit Function 
      End If 
      Select Case lParam 
       Case FD_READ 'lets check for data 
        x = recv(mysock, ReadBuffer(0), 1000, 0) 'try to get some 
        If x > 0 Then 'was there any? 
         'UPGRADE_ISSUE: Constant vbUnicode was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="55B59875-9A95-4B71-9D6A-7C294BF7139D"' 
         'default 
         'a = StrConv(System.Text.UnicodeEncoding.Unicode.GetString(ReadBuffer), vbUnicode) 'yep, lets change it to stuff we can understand 
         a = System.Text.UnicodeEncoding.Unicode.GetString(ReadBuffer) 'yep, lets change it to stuff we can understand 

         Debug.Print(a) 
         rtncode = Val(Mid(a, 1, 3)) 
         'Debug.Print "Analysing code " & rtncode & "..." 
         Select Case rtncode 
          Case 354, 250 

           Progress = Progress + 1 

           Debug.Print(">>Progress becomes " & Progress) 
          Case 220 
           Debug.Print("Recieved Greenlight") 
           Green_Light = True 
          Case 221 

           Progress = Progress + 1 

           Debug.Print(">>Progress becomes " & Progress) 
          Case 550, 551, 552, 553, 554, 451, 452, 500 
           Debug.Print("There was some error at the server side") 
           Debug.Print("error code is " & rtncode) 
           do_cancel = True 
         End Select 
        End If 
       Case FD_CONNECT 'did we connect? 
        mysock = wParam 'yep, we did! yayay 
        'Debug.Print WSAGetAsyncError(lParam) & "error code" 
        'Debug.Print mysock & " - Mysocket Value" 

       Case FD_CLOSE 'uh oh. they closed the connection 
        Call closesocket(wp) 'so we need to close 
      End Select 
    End Select 
    'let the msg get through to the form 
    WindowProc = CallWindowProc(lpPrevWndProc, hw, uMsg, wParam, lParam) 
End Function 

是什麼錯誤我得到的原因是什麼?我該如何解決問題?

+0

覆蓋的窗口過程在哪一行,你得到的錯誤?上面的代碼有很多錯誤。 – chrissie1

+0

如何定義和設置lpPrevWndProc,hw,uMsg,wParam和lParam? –

+0

@ Hand-E-Food - 'hw','uMsg','wParam'和'lParam'是'WindowProc'函數的參數。 'lpPrevWndProc'大概是存儲'SetWindowLong'的返回值的地方(但是OP當然沒有向我們顯示包含錯誤嘗試使用'SetWindowLong'來覆蓋窗口過程的實際代碼行) –

回答

2

而不是試圖使用P/Invoke來設置窗口過程,你看你的覆蓋窗體的WndProc方法?重寫期間可能需要更多的工作,但最終會得到更好的代碼。從以前的鏈接舉例:

Protected Overrides Sub WndProc(ByRef m As Message) 
     ' Listen for operating system messages 
     Select Case (m.Msg) 
      ' The WM_ACTIVATEAPP message occurs when the application 
      ' becomes the active application or becomes inactive. 
     Case WM_ACTIVATEAPP 

       ' The WParam value identifies what is occurring. 
       appActive = (m.WParam.ToInt32() <> 0) 

       ' Invalidate to get new text painted. 
       Me.Invalidate() 

     End Select 
     MyBase.WndProc(m) 
    End Sub 

您還可能要在System.Net.Sockets命名空間來尋找您的當前插座碼合適的替代品。


我也發現了一篇文章".NET Makes Window Subclassing Easy",如果,例如,你不擁有你想要的子類的窗口,它可能是有用的。無論如何,雖然各地,這是不推薦的方法之一是嘗試使用SetWindowLong

相關問題