将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/
[解决办法]
[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;
COPYDATASTRUCT cds;
string msg;
//info = "companyid://" & companyid & "//,tel://" & tel & "//,uid://" & uid & "//,linkman://" & linkman &
"//,isout://" & isout & "//";
msg = "tel://" & tel & "//";
buf(byte );
ReDim Preserve buf(LenB(msg));
Call CopyMemory(buf(1), msg, LenB(msg));
cds.lpData = VarPtr(buf(1));
cds.cbData = LenB(msg);
cds.dwData = 0;
// pid
//pid = GetPsPid("CallCenterClient.exe")
FT_hWnd = findWindow(vbNullString, "呼叫中心");
//FT_hWnd = FindProcessWindow(pid)
if ( FT_hWnd != 0 ) {
SendMessage FT_hWnd, WM_COPYDATA, 0, cds;
} else {
MsgBox "呼叫中心未启动!", vbCritical, strSysName;
}
Exit Function;
err:;
MsgBox err.Description, vbCritical, strSysName;
err.Clear;
}
[解决办法]
第一个方法是上面有人说过的,用VB.NET TO C#的在线转换工具。既然你说不好用,那么可以这样:你把VB.NET代码编译了,然后用工具反编译(IL spy,reflector等)成C#代码。
[解决办法]
试试这样
public const uint WM_COPYDATA = 0x004A;[StructLayout(LayoutKind.Sequential)]public struct COPYDATASTRUCT{ public IntPtr dwData; public int cbData; public IntPtr lpData;}[DllImport("kernel32.dll", EntryPoint="RtlMoveMemory")]public static extern void CopyMemory(IntPtr dest, IntPtr src, int size);[DllImport("User32.dll", EntryPoint="FindWindowA")]public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);[DllImport("User32.dll", EntryPoint="SendMessageA")]public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);public void CallCenterCall(string tel){ try { IntPtr FT_hWnd; COPYDATASTRUCT cds; string msg; //info = "companyid:'" & companyid & "',tel:'" & tel & "',uid:'" & uid & "',linkman:'" & linkman & "',isout:'" & isout & "'" msg = "tel:'" + tel + "'"; byte[] buf; buf = new byte[msg.Length]; GCHandle gh = GCHandle.Alloc(buf[1], GCHandleType.Pinned); IntPtr ptr = gh.AddrOfPinnedObject(); gh.Free(); cds.lpData = ptr; cds.cbData = msg.Length; cds.dwData = IntPtr.Zero; //Dim pid //pid = GetPsPid("CallCenterClient.exe") FT_hWnd = FindWindow(null, "呼叫中心"); //FT_hWnd = FindProcessWindow(pid) if(FT_hWnd != IntPtr.Zero) { IntPtr lParam = Marshal.AllocHGlobal(Marshal.SizeOf(cds)); Marshal.StructureToPtr(cds, lParam, true); SendMessage(FT_hWnd, WM_COPYDATA, IntPtr.Zero, lParam); Marshal.FreeHGlobal(lParam); } else { MessageBox.Show("呼叫中心未启动!", strSysName, MessageBoxIcon.Error); } return; } catch (Exception err) { MessageBox.Show(err.Message, strSysName, MessageBoxIcon.Error); }}
[解决办法]
vb6够呛能转....
重写吧..
[解决办法]
public const int WM_COPYDATA = 0x4A;
public enum COPYDATASTRUCT
{
public int dwData;
public int cbData;
public int lpData;
}
[DllImport("kernel32.dll")]
extern static void RtlMoveMemory(object hpvDest,object hpvSource,int cbCopy);
[DllImport("User32.dll")]
extern static IntPtr FindWindow(string lpClassName,string lpWindowName);
[DllImport("User32.dll")]
extern static int SendMessage(IntPtr hWnd,int wMsg,int wParam,object lParam);
public void CallCenterCall(string tel)
{
try
{
IntPtr ftHwnd = IntPtr.Zero;
COPYDATASTRUCT cds = new COPYDATASTRUCT();
string msg = string.Empty;
msg = string.Format("tel:'{0}'",tel);
byte[] buffer = Encoding.Default.GetBytes(msg);
ftHwnd = FindWindow(null,"呼叫中心");
if(ftHwnd.Equal(IntPtr.Zero))
{
SendMessage(ftHwnd,WM_COPYDATA,0,buffer);
}
else
{
MessageBox.Show("呼叫中心未启动",strSysName,MessageBoxButtons.OK,MessageBoxIcons.Error);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message,strSysName,MessageBoxButtons.OK,MessageBoxIcons.Error);
}
}
[解决办法]
小子 跑这儿来要代码来了 公司资源不用