C # Use Dllmport to call dephi dll

Source: Internet
Author: User

Generally, it is not hosted.
The specific format is as follows: [DllImport ("WZFSE. dll", CharSet = CharSet. Ansi, CallingConvention = CallingConvention. StdCall)]
The following is his declarative function.
Public static extern void InitDll (IntPtr handle, bool methodAddress );
Declare a function to reference its dll
IntPtr can be declared as a handle or pointer in other languages.
To implement a function pointer similar to C ++ in other languages, we should use the C # Delegate to implement
It is also important to check the dephi form into your C # system. We call the dephi form. The dephi form is displayed in the C # form.
In this case, what should we do? How can we remove the form in dephi? Now we need to use the API function, and the API function is also available in dephi C #.
In 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 );
Insert a class below. Here, the package contains how to reference dephi dll and how to declare it.
Code
1 public class CompliancePlatDLL
2 {
3 public static string strPath = "";
4 /// <summary>
5 // Initialization
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 // load the corresponding service
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 // remove the corresponding service
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 functions
29 /// <summary>
30 // API function settings
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 Function Mobile Form
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 // remove the Form title bar using the API Function
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.