DLL file
// dllmain.cpp: defines the entry point of the DLL application.
#include "pch.h"
// Declare the export function-> Export this function to
extern “C” __declspec (dllexport) void c ();
// Used as the exported function: interface
void c ()
{
}
// Things to do
void a ()
{
}
// Clean up
void b ()
{
}
BOOL APIENTRY DllMain (HMODULE hModule,
// handle of DLL module handle
DWORD ul_reason_for_call,
// the reason why DLLmain is called
LPVOID lpReserved
// reserved items, which are
reserved parameters of windows // reserved parameters, parameters that windows do not want us to know
)
{
Switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
// when the DLL is loaded DLLmain process is called
A ();
case DLL_THREAD_ATTACH:
// have to be called when the thread is created DLLmain
case DLL_THREAD_DETACH:
// DLLmain has been called the end of the thread when the
case DLL_PROCESS_DETACH:
// DLLmain is called when the DLL is unloaded by the process
b ();
break;
}
return TRUE;
}
Export function
Provide an interface for external applications to call
extern "C"
The main function of extern "C" is to be able to correctly implement C ++ code to call other C language code. After adding extern "C", the compiler will be instructed to compile this part of the code according to C language, not C ++. Since C ++ supports function overloading, the compiler will add the function parameter type to the compiled code during the function compilation process, not just the function name, and the C language does not support function overloading, so compile C The function of the language code is not to bring the parameter type of the function, generally only includes the function name
This feature is very useful, because before the advent of C ++, a lot of code was written in C language, and the very low-level library was also written in C language. In order to better support the original C code and the written C language library, it is necessary to support C as much as possible in C ++, and extern "C" is one of the strategies
In short, it is to prevent the function name from being modified or crushed by the compiler after compilation
Mainly used in the following situations:
C ++ code calls C language code
Used in C ++ header files
When multiple people assist in development, some people may be good at C language, and some people are good at C ++, which is also useful in this case.
__declspec(dllexport)
Declare the export function and open the function from DLL to other applications
dllimport/dllexport
dllexport: If you want a function to be part of an interface, you must declare the function definition in other modules as dllexport
Communication method between application program and DLL export function
Static library
Static library means that in our application, there are some common codes that need to be used repeatedly, and these codes are compiled into "library" files. In the linking step, the linker will obtain the required code from the library file and copy it to the generation Such libraries in the executable file
Program compilation generally requires preprocessing, compilation, assembly and linking several steps, static library
MessageBoxA (handle, display content, title, MB_OK);
The handle can be NULL, indicating the handle of the current form.
The last parameter is the type of button displayed in the prompt box;
MB_ABOKTRETRYIGNORE
MB_OKCANCEI
MB_RETRYCANCEI
MB_YESNO
MB_YESNOCANCEI
MB_OK
Can choose any logo