In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "Visual C # how to write DLL", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "Visual C # how to write DLL"!
I. introduction
As an important port for data transmission between computer and external serial equipment, serial communication port has been widely used in various computer systems in the industry because of its simple and convenient use. Due to the wide range of applications, software personnel have accumulated rich programming experience in serial communication. Articles about serial communication appear on the newspaper from time to time, and there are some special discussions.
Serial communication programming books provide rich resources for software personnel, and provide a good example for software developers who are involved in serial programming for the first time.
Although there are many materials about serial port programming, due to the variety of engineering requirements, it is necessary to flexibly control the serial port according to different conditions. in practical application, the commonly used methods are:
(1) use assembly or standard communication functions to read and write data directly to the designated port.
(2) use the MSComm control provided by Visual Studio
(3) use the API function provided by Windows.
This paper is a complete example that the author directly uses the API function provided by Windows to realize a serial communication dynamic link library (DLL) in Visual C # environment according to the actual needs in engineering practice. the example not only gives the writing method of DLL function, but also includes an example of declaring and calling this DLL with other programming tools (VB). In order to make the reader clear at a glance and reduce the amount of code, this example is simplified, but it can be run. Hope to provide a little help to those who need serial communication programming and programming enthusiasts who need to learn to write DLL.
Second, prepare knowledge
1. Visual C # compiles the basic concepts of DLL
Dynamic link library (DLL) is the foundation of the Windows operating system, and all the functions in Windows API are included in DLL. It has many advantages, such as simplifying software project management for division of labor, helping to save memory, easy to share resources and can be written in multiple languages.
There are four types of dynamic links written in VC#: Win32 DLL, MFC regular DLL (dynamic link MFC), MFC regular DLL (static link MFC), MFC extension DLL, and so on. This procedure is written as Win32 DLL.
2. Basic knowledge of serial communication
In the Windows system, the system configures the serial port through a structure called DCB (Device Control Block). The status information of the serial communication port can be obtained by the Windows API GetCommState function, and the serial communication port can be set by using the SetCommState function. The realization of serial communication generally needs to be carried out in the following four steps:
(1) Open serial port. Because the serial port is an exclusive resource, after the application opens the serial port, other applications can no longer open the serial port.
(2) configure serial port. Use the GetCommState function to obtain the current configuration of the serial port, change the parameters in the DCB structure as needed, and then use the SetCommState function to set the serial communication parameters.
(3) data transmission. Send and receive data on the serial port, check it as needed, trigger some events, and so on. The purpose of this serial communication DLL is to send and receive data.
(4) close the serial port. When this serial port is not needed, close the serial port for use by other applications.
3. CALLBACK function
The CALLBACK function is defined in Microsoft's official manual as follows: "CALLBACK functions are defined by the application and called by the operating system." When we write a DLL, it is the function defined by the application and executed by the DLL, and this mechanism is very useful for passing information between the callee (DLL) and the caller (application). This feature is difficult for beginners to understand, but it is a blessing for those who write serial communication programs. it is precisely because of the use of this feature that it is very convenient to implement OnComm events in MSComm controls in the dynamic link library, and can be flexibly controlled as needed.
At this point, I believe you have a deeper understanding of "Visual C # how to write DLL". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.