From 4d87256ca77c1b79128a6720df271c6ab827200c Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Mon, 13 Aug 2018 09:30:51 +0200 Subject: [PATCH] init: Add a library constructor and destructor for VC If we compile with Visual Studio, we need a DllMain() for running init and finialize which is the same as a constructor and destructor. Signed-off-by: Andreas Schneider --- src/init.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/init.c b/src/init.c index 49999cce..ea3e6432 100644 --- a/src/init.c +++ b/src/init.c @@ -222,4 +222,27 @@ int ssh_finalize(void) { return _ssh_finalize(0); } +#ifdef _WIN32 + +#ifdef _MSC_VER +/* Library constructor and destructor */ +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + int rc; + + if (fdwReason == DLL_PROCESS_ATTACH) { + rc = ssh_init(); + } else if (fdwReason == DLL_PROCESS_DETACH) { + rc = ssh_finalize(); + } + + if (rc != 0) { + return FALSE; + } + return TRUE; +} +#endif /* _MSC_VER */ + +#endif /* _WIN32 */ + /** @} */