我正在使用 mingw 编译器和代码块 IDE。我面临一个问题,我不明白我的 dll 是如何在没有我使用__declspec(dllexport)
这些函数的情况下导出每个函数的。这是两个示例文件,main.h
和main.cpp
:
main.h
:
#ifndef __MAIN_H__
#define __MAIN_H__
#include windows.h
#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C"
{
#endif
void SomeFunction(const LPCSTR sometext);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
main.cpp
:
#include "main.h"
void SomeFunction(const LPCSTR sometext)
{
MessageBoxA(0, sometext, "DLL fxn Message", MB_OK | MB_ICONINFORMATION);
}
bool flag = false;
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
flag = true;
return TRUE; // succesful
}
在此示例中,SomeFunction
已导出,我可以从外部应用程序动态调用它,尽管我没有将其原型化为
void __declspec(dllexport) SomeFunction(const LPSTR sometext);
不仅如此,甚至全局变量flag
也被导出到自动生成的 .def 文件中。
这里发生了什么?如果我犯了技术错误,请帮助并纠正我。