summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2018-08-13 09:30:51 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-08-13 22:12:22 +0200
commit0db4d9bd46f9173eed09d7b1438b1b7859192656 (patch)
tree0b33367b929aa4aff9d382827b850feeb40ae009
parent1e17e084bf56f5c1b609c0cf0d715a1a7c528fab (diff)
downloadlibssh-0db4d9bd46f9173eed09d7b1438b1b7859192656.tar.gz
libssh-0db4d9bd46f9173eed09d7b1438b1b7859192656.tar.xz
libssh-0db4d9bd46f9173eed09d7b1438b1b7859192656.zip
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 <asn@cryptomilk.org> (cherry picked from commit 4d87256ca77c1b79128a6720df271c6ab827200c)
-rw-r--r--src/init.c23
1 files changed, 23 insertions, 0 deletions
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 */
+
/** @} */