DEV-CPPMINGW32 Environment Introduction (6)

xiaoxiao2021-03-06  38

DEV-CPP / MINGW32 Environment Introduction (6) Review: above "DEV-CPP / MINGW32 Environment Introduction (5)", we understand how to make a static connection library. Indeed, the last article has been long time. So, I will use more content to read readers this time. Let's talk about how to make a dynamic link library.

Chapter 9 makes your own dynamic link library "I didn't dream, MingW32 can also do Win32 dynamic connection library?" I didn't dream of you, I also didn't say. Below I briefly introduce some dynamic libraries generation and use. Still old, let's open DEV-CPP, then we will build a new project. Select a DLL project. This is our link library. After new construction, we will generate a DLL.H and an engineering name .c file. Among them, saved in dll.h is a function of your dynamic library. Let's take a look at my content.

//dll.h#ifndef _dll_h_ # define _dll_h_

#if building_dll # define dllimport __declspec (dllexport) #ELSE / * NOT building_dll * / # define dllimport __declspec (dllimport) #ENDIF / * NOT building_dll * /

#ENDIF / * _DLL_H_ * /

#include

BOOL APIENTRY DllMain (. HINSTANCE hInst / * Library instance handle * /, DWORD reason / * Reason this function is being called * /, LPVOID reserved / * Not used * /..) {Switch (reason) {case DLL_PROCESS_ATTACH: break;

Case DLL_PROCESS_DETACH: BREAK;

Case DLL_THREAD_ATTACH: BREAK;

Case DLL_THREAD_DETACH: BREAK;

/ * Returns True on success, false on fiveure * / return true;

Dllimport Int HelloWorld (Void);

//dll.h End

Among them, I joined my own function in the last line, HelloWorld.

Let's take a look at my helloWorld.c.

//Helloworld.c#include "dll.h"

Dllimport Int helloworld (void) {Printf ("Hello, World!"); Return (0);}

//HELLOWORLD.C END

Ok, let's compile it. Use the DEV's compile command or with the following command.

We will get two files. A libhelloworld.a, a helloworld.dll. We can use these two files to be programmed.

Text-proof: To tell the truth, this article is indeed a bit longer compared to the first few articles. Since I am very busy with my previous stage, I am sorry for the readers. Below we have to learn how to use dynamic libraries that we have written just now.

Chapter 10 Using your own dynamic link library

Review above: above, we introduced how to generate dynamic libraries. Let's use it below.

New project main.c file is as follows

//main.c

#include #include #include "dll.h" int main () {helloworld (); return (0);

//main.c end

Now copy the dll.h libhelloworld.a helloWorld.dll file in that project to your current project.

Then, we now open the engineering properties. Add to join in the linker column

-L "HelloWorld"

Compile after saving the project. After everything is successful, we have gained the way using the dynamic link library. In the future, we only need to modify the HelloWorld of the Link Library to modify the display in the program. I hope this article can be satisfied.

Textual sound: Indeed, now very busy, so the quality of the article also declines a lot. But I still want to give more understanding. Recently INSM compilation. It was found that EMCAS and NASM were really good. I like it very much. However, c I still pursue. Just, it may be less in the future, but I will use my article to make you more than the content of DEV. This series of articles, endless, to be renewed. Studio Software Development Group (SDT) Studio Development Team Beidou Star (Huang Yuxi)

转载请注明原文地址:https://www.9cbs.com/read-66082.html

New Post(0)