From 320fa9d596e06ce8b151eb7e5c432dccea9a755a Mon Sep 17 00:00:00 2001 From: Joao Matos Date: Fri, 30 Sep 2016 17:03:54 +0100 Subject: [PATCH] Implemented get_current_executable_path() for Windows. --- support/mono_managed_to_native.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/support/mono_managed_to_native.c b/support/mono_managed_to_native.c index bd4f892..fd364e1 100644 --- a/support/mono_managed_to_native.c +++ b/support/mono_managed_to_native.c @@ -40,6 +40,10 @@ #include #endif +#ifdef _WIN32 +#include +#endif + #include #include #include @@ -80,7 +84,7 @@ int mono_m2n_destroy(mono_m2n_context_t* ctx) static GString* get_current_executable_path() { -#ifdef __APPLE__ +#if defined(__APPLE__) int ret; pid_t pid; char pathbuf[PROC_PIDPATHINFO_MAXSIZE]; @@ -89,8 +93,14 @@ static GString* get_current_executable_path() ret = proc_pidpath (pid, pathbuf, sizeof(pathbuf)); return (ret > 0) ? g_string_new(pathbuf) : 0; +#elif defined(_WIN32) + HMODULE hModule = GetModuleHandleW(0); + CHAR pathbuf[MAX_PATH]; + DWORD ret = GetModuleFileNameA(hModule, pathbuf, MAX_PATH); + + return (ret > 0) ? g_string_new(pathbuf) : 0; #else - return 0; + g_assert_not_reached(); #endif }