一般是用非托管的
具體形式如下:[DllImport("WZFSE.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
下面緊接著他的申明函數
public static extern void InitDll(IntPtr handle, bool methodAddress);
申明一個函數就要引用下他的dll
IntPtr這個類型可以申明為其他語言的句柄,指針等。
若要實現其他語言類似C++的函數指針形式 這時我們考慮用C#的委托來實現
將dephi的窗體簽入到自己的C#系統裡 還有一點比較重要,我們是調用dephi的窗體,此時顯示在我們C#窗體中會有dephi的窗體
這時我們怎麼辦呢 怎麼去除dephi中的窗體呢 這時我們就需要用API函數了 API函數在dephi有 C#中也有
在C#中是這麼引用的 [DllImport("user32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern void MoveWindow(IntPtr handler, int x, int y, int width, int height, bool repaint);
下面插入一個類 這裡面包含了怎麼引用dephi的dll 以及怎麼申明
代碼
1 public class CompliancePlatDLL
2 {
3 public static string strPath = "";
4 /// <summary>
5 /// 初始化
6 /// </summary>
7 /// <param name="handle"></param>
8 /// <param name="methodAddress"></param>
9 [DllImport("WZFSE.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
10 public static extern void InitDll(IntPtr handle, bool methodAddress);
11 /// <summary>
12 /// 加載相應的服務
13 /// </summary>
14 /// <param name="str"></param>
15 /// <param name="str2"></param>
16 /// <param name="i"></param>
17 /// <returns></returns>
18 [DllImport("WZFSE.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
19 public static extern IntPtr wzLoadModule(string str, string str2, int i);
20 /// <summary>
21 /// 去除相應的服務
22 /// </summary>
23 /// <param name="handle"></param>
24 /// <returns></returns>
25 [DllImport("WZFSE.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
26 public static extern bool wzUnloadModule(IntPtr handle);
27
28 #region API函數
29 /// <summary>
30 /// API函數 設置主輔窗體
31 /// </summary>
32 /// <param name="child"></param>
33 /// <param name="parent"></param>
34 [DllImport("user32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
35 public static extern void SetParent(IntPtr child, IntPtr parent);
36 /// <summary>
37 /// API函數 移動窗體
38 /// </summary>
39 /// <param name="handler"></param>
40 /// <param name="x"></param>
41 /// <param name="y"></param>
42 /// <param name="width"></param>
43 /// <param name="height"></param>
44 /// <param name="repaint"></param>
45 [DllImport("user32.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
46 public static extern void MoveWindow(IntPtr handler, int x, int y, int width, int height, bool repaint);
47
48 [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
49 public static extern long GetWindowLong(IntPtr hwnd, int nIndex);
50 /// <summary>
51 /// API函數 去除窗體的標題欄
52 /// </summary>
53 /// <param name="hwnd"></param>
54 /// <param name="nIndex"></param>
55 /// <param name="dwNewLong"></param>
56 /// <returns></returns>
57 [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
58 public static extern long SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
59 public const int GWL_EXSTYLE = -16;
60 public const int WS_EX_TRANSPARENT = 0x20;
61 public const