//拨打
private void call()
{
if (this.numText.Text == "")
{
MessageBox.Show("号码不能为空");
return;
}
if (flag != 0)
{
close();
}
long ret = -1;
UInt32 dw = 0;
UInt32 ver = 0x00020000;
line.dwTotalSize = (uint)Marshal.SizeOf(line);
line.dwOptions = 0x00000002;
ret = lineInitializeEx(out h, IntPtr.Zero, IntPtr.Zero, "Tapi", out dw, ref ver, ref line);
if (ret != 0)
{
MessageBox.Show("初始化失败");
return;
}
LINEEXTENSIONID lineext;
UInt32 dwCallbackInstance = 0;
for (int dwD = 0; dwD < dw; dwD++)
{
ret = lineNegotiateAPIVersion(h, dwD, 0x00020000, 0x00020001, out ver, out lineext);
if (ret == 0)
{
ret = lineOpen(h, dwD, out hLine, ver, 0, dwCallbackInstance, 0x00000001, 0, 0);
break;
}
}
if (ret == 0)
{
//tag.dwBearerMode = 0;
ret = lineMakeCall(hLine, out hCall, "189********", 0, 0);
if (ret > 0)
{
flag = 1;
callButton.Enabled = false;
}
}
}
// 挂机
public void close()
{
lineDrop(hCall, IntPtr.Zero, 0);
lineClose(hLine);
lineShutdown(h);
callButton.Enabled = true;
flag = 0;
}
public struct LINEEXTENSIONID
{
public IntPtr dwExtensionID0;
public IntPtr dwExtensionID1;
public IntPtr dwExtensionID2;
public IntPtr dwExtensionID3;
}
public struct LINEINITIALIZEEXPARAMS
{
public uint dwTotalSize;
public uint dwNeededSize;
public uint dwUsedSize;
public uint dwOptions;
public System.IntPtr hEvent;
public System.IntPtr hCompletionPort;
public uint dwCompletionKey;
}
#region Invoked Native Functions
[DllImport("coredll.dll")]
private static extern int lineInitializeEx(
out IntPtr hLineApp,
IntPtr hAppHandle,
IntPtr lCallBack,
string FriendlyAppName,
out System.UInt32 NumDevices,
ref System.UInt32 APIVersion,
ref LINEINITIALIZEEXPARAMS lineExInitParams);
[DllImport("coredll")]
private static extern int lineNegotiateAPIVersion(IntPtr m_hLineApp, int
dwDeviceID, int dwAPILowVersion, int dwAPIHighVersion, out System.UInt32 lpdwAPIVersion,
out LINEEXTENSIONID lpExtensionID);
[DllImport("coredll")]
public static extern int lineOpen(IntPtr m_hLineApp, int dwDeviceID, out
IntPtr lphLine, uint dwAPIVersion, int dwExtVersion, System.UInt32
dwCallbackInstance,
int dwPrivileges, int dwMediaModes, int lpCallParams);
[DllImport("coredll")]
public static extern int lineMakeCall(IntPtr lphLine, out IntPtr hCall, string number, int a, int b);
[DllImport("coredll")]
public static extern int lineDrop(IntPtr hCall, IntPtr c, int d);
[DllImport("coredll")]
public static extern int lineClose(IntPtr hLine);
[DllImport("coredll")]
public static extern int lineShutdown(IntPtr m_hLineApp);
#endregion