Added DllMain() function to Windows "shared" library (DLL).

This commit is contained in:
LoRd_MuldeR 2022-12-03 02:21:53 +01:00
parent c57fce910e
commit a1d8935b2b
5 changed files with 37 additions and 4 deletions

View File

@ -24,7 +24,7 @@ endif
endif
ifeq ($(firstword $(filter %-mingw32 %-cygwin,$(DUMPMACHINE))),)
DLL_LDFLAGS = -fPIC -shared
DLL_LDFLAGS = -shared
DLL_SUFFIX := .so
else
DLL_LDFLAGS = -shared -Wl,--out-implib,$@.a

View File

@ -1,6 +1,6 @@
include ../config.mk
CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -Iinclude $(XCFLAGS)
CFLAGS = -std=c99 -D_DEFAULT_SOURCE -Wpedantic -Iinclude -fPIC $(XCFLAGS)
SRC_PATH := src
OBJ_PATH := obj
@ -21,9 +21,9 @@ test: build
build: $(ALL_PATH) $(LIB_FILE) $(DLL_FILE)
$(LIB_FILE): $(OBJ_FILE)
$(AR) rcs $@ $^
$(AR) rcs $@ $(filter-out $(OBJ_PATH)/dll%,$^)
$(DLL_FILE): $(SRC_FILE)
$(DLL_FILE): $(OBJ_FILE)
$(CC) $(CFLAGS) $(DLL_LDFLAGS) -o $@ $^
$(OBJ_FILE):

View File

@ -46,6 +46,7 @@
<ClInclude Include="src\generic_hash_set.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\dll_main.c" />
<ClCompile Include="src\hash_map_16.c" />
<ClCompile Include="src\hash_map_32.c" />
<ClCompile Include="src\hash_map_64.c" />

View File

@ -53,5 +53,8 @@
<ClCompile Include="src\hash_set_16.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\dll_main.c">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

29
libhashset/src/dll_main.c Normal file
View File

@ -0,0 +1,29 @@
/******************************************************************************/
/* HashSet for C99, by LoRd_MuldeR <MuldeR2@GMX.de> */
/* This work has been released under the CC0 1.0 Universal license! */
/******************************************************************************/
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
#elif defined(__GNUC__)
void __attribute__((constructor)) libhashet_init(void) { /*noop*/ }
void __attribute__((destructor)) libhashet_exit(void) { /*noop*/ }
#endif