日期:2014-05-18  浏览次数:21405 次

将VB代码转换为C#代码
以下是VB代码 如何转为C#代码 主要是调用api时Any不知道在C#如何表示等 求完整 麻烦了 谢谢
Public Const WM_COPYDATA As Integer = &H4A
Public Type COPYDATASTRUCT
  dwData As Long
  cbData As Long
  lpData As Long
End Type

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal 
cbCopy As Long)

Public Declare Function findWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal 
lpWindowName As String) As Long

Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As 
Long, ByVal wParam As Long, lParam As Any) As Long

'调用方法  
Public Function CallCenterCall(tel As String)
On Error GoTo err:
  Dim FT_hWnd As Long
  Dim cds As COPYDATASTRUCT
  Dim msg As String
  'info = "companyid:'" & companyid & "',tel:'" & tel & "',uid:'" & uid & "',linkman:'" & linkman & 

"',isout:'" & isout & "'"
  msg = "tel:'" & tel & "'"
  Dim buf() As Byte
  ReDim Preserve buf(LenB(msg))
   
  Call CopyMemory(buf(1), ByVal msg, LenB(msg))
  cds.lpData = VarPtr(buf(1))
  cds.cbData = LenB(msg)
  cds.dwData = 0
   
  'Dim pid
   
  'pid = GetPsPid("CallCenterClient.exe")
   
  FT_hWnd = findWindow(vbNullString, "呼叫中心")
  'FT_hWnd = FindProcessWindow(pid)
   
  If FT_hWnd <> 0 Then
  SendMessage FT_hWnd, WM_COPYDATA, 0, cds
  Else
  MsgBox "呼叫中心未启动!", vbCritical, strSysName
  End If
  Exit Function
   
err:
  MsgBox err.Description, vbCritical, strSysName
  err.Clear
End Function



------解决方案--------------------
在这个网址去转换,不完全准确
http://www.developerfusion.com/tools/convert/vb-to-csharp/
------解决方案--------------------
C# code


        [DllImport("user32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
        [DllImport("user32.dll")]
        public static extern int FindWindow(string cls, string wndwText);

------解决方案--------------------
VB.Net to C# Converter
------解决方案--------------------
那几个API到http://www.pinvoke.net/上去找现成的
------解决方案--------------------
public const int WM_COPYDATA = &H4A;
public struct COPYDATASTRUCT
long dwData;
long cbData;
long lpData;
}

public [DllImport("GAIS", SetLastError=true)] static extern void CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Any hpvDest, Any hpvSource, {
long cbCopy);

public [DllImport("GAIS", SetLastError=true)] static extern findWindow Lib "User32" Alias "FindWindowA" ( string lpClassName, {
string long lpWindowName);

private [DllImport("GAIS", SetLastError=true)] static extern SendMessage Lib "User32" Alias "SendMessageA" ( long hWnd, wMsg As {
long, long wParam, Any long lParam);

//调用方法
public CallCenterCall(string tel) {
On Error GoTo err:;
long FT_hWnd;