Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/monodroid/jni/monodroid-glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <shlobj.h>
#include <objbase.h>
#include <knownfolders.h>
#include <shlwapi.h>
#endif

#include <sys/stat.h>
Expand Down Expand Up @@ -535,6 +536,28 @@ get_xamarin_android_msbuild_path (void)
return msbuild_folder_path;
}

static char *libmonoandroid_directory_path = NULL;

// Returns the directory in which this library was loaded from
static char*
get_libmonoandroid_directory_path ()
{
wchar_t module_path[MAX_PATH];
HMODULE module = NULL;

if (libmonoandroid_directory_path != NULL)
return libmonoandroid_directory_path;

DWORD flags = GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT;
if (!GetModuleHandleExW (flags, (void*)&libmonoandroid_directory_path, &module))
return NULL;

GetModuleFileNameW (module, module_path, sizeof (module_path) / sizeof (module_path[0]));
PathRemoveFileSpecW (module_path);
libmonoandroid_directory_path = utf16_to_utf8 (module_path);
return libmonoandroid_directory_path;
}

static int
setenv(const char *name, const char *value, int overwrite)
{
Expand Down Expand Up @@ -656,6 +679,10 @@ get_libmonosgen_path ()
return libmonoso;
free (libmonoso);

#ifdef WINDOWS
TRY_LIBMONOSGEN (get_libmonoandroid_directory_path ())
#endif

TRY_LIBMONOSGEN (SYSTEM_LIB_PATH)

#ifdef RELEASE
Expand Down
2 changes: 1 addition & 1 deletion src/monodroid/monodroid.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<_HostUnixCFlags>$(_CommonCFlags) -Wa,--noexecstack</_HostUnixCFlags>
<_HostUnixLdFlags>-Wall -lstdc++ -lz -shared -fpic</_HostUnixLdFlags>
<_HostCommonWinCFlags>$(_CommonCFlags) -DWINDOWS -DNTDDI_VERSION=NTDDI_VISTA -D_WIN32_WINNT=_WIN32_WINNT_VISTA -fomit-frame-pointer</_HostCommonWinCFlags>
<_HostCommonWinLdFlags>-Wall -lstdc++ -lz -shared -fpic -ldl -lmman -pthread -lwsock32 -lole32 -luuid</_HostCommonWinLdFlags>
<_HostCommonWinLdFlags>-Wall -lstdc++ -lz -shared -fpic -ldl -lmman -pthread -lwsock32 -lole32 -luuid -lshlwapi</_HostCommonWinLdFlags>
<_UnixAdditionalSourceFiles>$(MonoSourceFullPath)\support\nl.c jni\debug.c jni\monodroid-networkinfo.c jni\xamarin_getifaddrs.c</_UnixAdditionalSourceFiles>
<_LinuxFlatPakBuild Condition="Exists('/.flatpak-info')" >-DLINUX_FLATPAK</_LinuxFlatPakBuild>
</PropertyGroup>
Expand Down