Abstract, a method of implementing VB call C language programs - dynamic connection library, gives a general framework for dynamic link library production, and the implementation of dynamic connection libraries and its manufacturing methods, programming steps, this The method has a general meaning. Key words VB Dynamic Library DLL C Pro Program 1 Using the VB development interface friendly, easy to operate only a short time. However, the VB runs slower, for huge scientific calculations, this slow speed of VB will make people feel unbearable. The C language is an internationally popular intermediate programming language that has been widely used in its flexible, efficient advantages. Many applications are written in a DOS environment with C language. So how do you play the advantages of both languages of VB and C, use VB to design a good for Windows interface to call C language programs, that is, implement VB call C language program? Existing documents are only mentioned to dynamic link libraries (hereinafter referred to as DLL) can connect both languages, but there is a modified and programming method for dynamic link library DLL. This article describes the method, steps of making dynamic link libraries and VB calls for DOS dynamic link libraries in the Borland C environment. Second, the method of writing a DLL program with Borland C To implement the VB call C program, first need to write a dynamic connection library DLL program with Borland C (assuming that the DLL program is named). The dynamic link library contains four files: C language source program (.c), module definition file (.def), prototype function file (.h), and engineering file (.prj). The specific structure of these four files is described in detail below. 1. Write the framework of the C language source program: C language source program (Example.c), which includes three functions: portal functions, output functions, and termination functions. The specific structure is as follows: / ************************************ / / * file name: Example .C * // ********************************************************** / # include
The first parameter hinstance is a DLL case handle, and the wdataseg parameter is a data segment (DS) register value, and the CBHEAPSIZE parameter is the size of the heap defined in the module definition file, and libmain uses this value to initialize local heap. The LPSZCMDLINE parameter includes command line information, but it is rarely used by DLL. In general, these four parameters are parameters for making DLL universal. If the DLL data is not allowed to be blocked, you must call UNLOCKDATA to restore normal non-lock status. If the DLL initialization has been successful, the DLL returns 1, and the 0 value is returned if it is not successful, and the DLL exits the system. The output function of the DLL implements the task to be completed by the user, which is the core of the DLL. It differs from the general C language program that there is no Scanf function. All external pointers are far pointer FAR. Painted line functions To use the LINETO function. The DLL includes a termination function, and the termination function is sometimes referred to as an exit function, and its name must be a WEP. And it can be included in the exports segment of the DLL module definition file. 2, the module definition file (.def) structure and the meaning module definition file of each segment is as follows: / ************************ *********** // * file name: example.def * // ********************************** ********** / lIBRARY example / * dLLname * / DESCRIPTION 'example.DLL'EXETYPE WINDOWSCODE PRELOAD MOVEABLE DISCARDABLEDATA PRELOAD MOVEABLE SINGLEHEAPSIZE 1024EXPORTSexample @ 1WEP @ 2 keyword lIBRARY ran this module as a DLL, library The name EXAMPLE followed and must be consistent with the name of the library, the file name of the DLL in DEF. The Description statement uses a string with a length of 128 characters, which usually uses it to save the information described by the module. EXTYPE Windows statements are needed for each Windows application and DLL. DATA statements Define the memory properties of the library data segment, the keyword Moveable allows the memory management program to move the memory segment if necessary, the keyword SINGLE is necessary, because the DLL always has a single data segment, regardless of accessing its application Quantity. The Heapsize statement is used to define an initial size of a DLL local heap. The DLL that performs local memory allocation must initialize the heap when the library starts, the size of the stack is transmitted to the DLL of the Lientry. The Locallnit is used to initialize the local heap of the DLL after the size of the stack. The Exeports statement definition will be used as a program from the application or from other DLL entry points. Windows uses this information to establish a sequence number of portions, the sequence number inlet value is an optimized value, allowing the dynamic connection mechanism to operate more quickly and use less Memory. In general, the structure of the module definition file (.def) is except that the names of the dynamic library are different, and other structures are fixed.
3. The function of establishing the original formal function file (.h) The function of the original form is to further declare the function name and passing parameters of the call function. The form is: / ******************** **************** // * file name: example :.h * // ********************** *************** / EXTERN "C" INT _EXPORT FAR PASCAL EXAMPLE (int Param1, ..., char param n); 4. Establishing a project file (.prj) project file contains two files with example.c, example.def, and then compile the connection to generate a dynamic link library. The above is a framework for making a dynamic connection library, and now introduces a method of making dynamic link libraries through an example. If the program completion function is required to: Open a data file to read the first two data, the two numbers are added to the two parameters transmitted, returning them. The name of the DLL program is Add. Step 1: Edit the .c file, .def file, and .h file in the Borland C environment, and establish a .prj file.
Such as (1) Write C language source program list: / ******************************************* / / * File name: add.c * // *********************************** / # Include