C#使用Dllmport来调用dephi的dll
一般是用非托管的
具体形式如下:[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 co
补充:软件开发 , C# ,