السلام عليكم
سبق وأبرزت كيفية الحصول علي بعض المعلومات حول حاسوب الكف بلغة السي والآن أضيف كيفية الحصول على معلومات أخرى بلغة السي شارب.
هذه المعطيات تتمثل في manufacture, model, revision, serial number, subscriber id لحاسوب الكف و تعتمد على الدوال الأصلية التالية:
كود
// Line Init
[DllImport("coredll")]
public static extern int lineInitializeEx(out IntPtr lpm_hLineApp,
IntPtr hInstance,
IntPtr lpfnCallback,
string lpszFriendlyAppName,
out int lpdwNumDevs,
ref int lpdwAPIVersion,
ref LINEINITIALIZEEXPARAMS lpLineInitializeExParams);
// Line open
[DllImport("coredll")]
public static extern int lineOpen(IntPtr m_hLineApp,
int dwDeviceID,
out IntPtr lphLine,
int dwAPIVersion,
int dwExtVersion,
IntPtr dwCallbackInstance,
int dwPrivileges,
int dwMediaModes,
IntPtr lpCallParams);
// Line Navigate
[DllImport("coredll")]
public static extern int lineNegotiateAPIVersion(IntPtr m_hLineApp,
int dwDeviceID,
int dwAPILowVersion,
int dwAPIHighVersion,
out int lpdwAPIVersion,
out LINEEXTENSIONID lpExtensionID);
// Line retreive Infos
[DllImport("cellcore")]
public static extern int lineGetGeneralInfo(IntPtr hLine,
byte[] bytes);
// Line close
[DllImport("coredll")]
public static extern int lineClose(IntPtr hLine);
// Line shutdown
[DllImport("coredll")]
public static extern int lineShutdown(IntPtr m_hLineApp);
علما أن النوع LINEEXTENSIONID يعرف كما يلي:
كود
public struct LINEEXTENSIONID
{
public IntPtr dwExtensionID0;
public IntPtr dwExtensionID1;
public IntPtr dwExtensionID2;
public IntPtr dwExtensionID3;
}
والنوع LINEGENERALINFO يمكن تعريفه بالشكل التالي:
كود
public class LINEGENERALINFO
{
public int dwManufacturerOffset;
public int dwManufacturerSize;
public int dwModelOffset;
public int dwModelSize;
public int dwNeededSize;
public int dwRevisionOffset;
public int dwRevisionSize;
public int dwSerialNumberOffset;
public int dwSerialNumberSize;
public int dwSubscriberNumberOffset;
public int dwSubscriberNumberSize;
public int dwTotalSize;
public int dwUsedSize;
}
والدالة الرئيسية التي توفر هذه التفاصيل هي
كود
public void details()
{ IntPtr hLine;
int dwNumDev;
int num1 = 0x20000;
LINEINITIALIZEEXPARAMS lineInitializeParams = new LINEINITIALIZEEXPARAMS();
lineInitializeParams.dwTotalSize = (uint)Marshal.SizeOf(lineInitializeParams);
lineInitializeParams.dwNeededSize = lineInitializeParams.dwTotalSize;
lineInitializeParams.dwOptions = 2;
lineInitializeParams.hEvent = IntPtr.Zero;
lineInitializeParams.hCompletionPort = IntPtr.Zero;
// lineInitializeEx
int result = Tapi.lineInitializeEx(out hLine, IntPtr.Zero, IntPtr.Zero, null, out dwNumDev, ref num1, ref lineInitializeParams);
if (result != 0)
{
MessageBox.Show(string.Format("lineInitializeEx failed!\n\nError Code:{0}", result.ToString()));
this.Close();
return;
}
// lineNegotiateAPIVerison
int version;
int dwAPIVersionLow = 0x10004;
int dwAPIVersionHigh = 0x20000;
LINEEXTENSIONID lineExtensionID;
result = Tapi.lineNegotiateAPIVersion(hLine, 0, dwAPIVersionLow, dwAPIVersionHigh, out version, out lineExtensionID);
// navigation failed
if (result != 0)
{
MessageBox.Show(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString()));
this.Close();
return;
}
// lineOpen
IntPtr hLine2 = IntPtr.Zero;
result = Tapi.lineOpen(hLine, 0, out hLine2, version, 0, IntPtr.Zero, 0x00000002, 0x00000004, IntPtr.Zero);
// lineOpen failed
if (result != 0)
{
MessageBox.Show(string.Format("lineNegotiateAPIVersion failed!\n\nError Code: {0}", result.ToString()));
this.Close();
return;
}
// lineGetGeneralInfo
int structSize = Marshal.SizeOf(new LINEGENERALINFO());
byte[] bytes = new byte[structSize];
byte[] tmpBytes = BitConverter.GetBytes(structSize);
for (int index = 0; index < tmpBytes.Length; index++)
{ bytes[index] = tmpBytes[index]; }
// make initial query to retrieve necessary size
result = Tapi.lineGetGeneralInfo(hLine2, bytes);
// get the needed size
int neededSize = BitConverter.ToInt32(bytes, 4);
// resize the array
bytes = new byte[neededSize];
// write out the new allocated size to the byte stream
tmpBytes = BitConverter.GetBytes(neededSize);
for (int index = 0; index < tmpBytes.Length; index++)
{ bytes[index] = tmpBytes[index]; }
// fetch the information with properly size buffer
result = Tapi.lineGetGeneralInfo(hLine2, bytes);
if (result != 0)
{
MessageBox.Show(Marshal.GetLastWin32Error().ToString());
this.Close();
return;
}
int size;
int offset;
// Now all the required information are stored in the variable "bytes"
// which we well have to parse.
// manufacture
size = BitConverter.ToInt32(bytes, 12);
offset = BitConverter.ToInt32(bytes, 16);
manufacture = Encoding.Unicode.GetString(bytes, offset, size);
manufacture = manufacture.Substring(0, manufacture.IndexOf(''));
// model
size = BitConverter.ToInt32(bytes, 20);
offset = BitConverter.ToInt32(bytes, 24);
model = Encoding.Unicode.GetString(bytes, offset, size);
model = model.Substring(0, model.IndexOf(''));
// revision
size = BitConverter.ToInt32(bytes, 28);
offset = BitConverter.ToInt32(bytes, 32);
revision = Encoding.Unicode.GetString(bytes, offset, size);
revision = revision.Substring(0, revision.IndexOf(''));
// serial number
size = BitConverter.ToInt32(bytes, 36);
offset = BitConverter.ToInt32(bytes, 40);
serialNumber = Encoding.Unicode.GetString(bytes, offset, size);
serialNumber = serialNumber.Substring(0, serialNumber.IndexOf(''));
// subscriber id
size = BitConverter.ToInt32(bytes, 44);
offset = BitConverter.ToInt32(bytes, 48);
subscriberID = Encoding.Unicode.GetString(bytes, offset, size);
subscriberID = subscriberID.Substring(0, subscriberID.IndexOf(''));
// lineClose for hLine2
Tapi.lineClose(hLine2);
// lineShutdown for hLine
Tapi.lineShutdown(hLine);
}
ويكن الحصول على الكود كامل في الملف المرفوق
والله أعلم