Merge branch 'master' of git://github.com/awakecoding/FreeRDP

This commit is contained in:
Benoît LeBlanc 2013-11-07 13:58:54 -05:00
commit 04cf7d301e
5 changed files with 90 additions and 5 deletions

View File

@ -46,12 +46,17 @@ WINPR_API HMODULE LoadLibraryW(LPCWSTR lpLibFileName);
WINPR_API HMODULE LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
WINPR_API HMODULE LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
WINPR_API DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
WINPR_API DWORD GetModuleFileNameW(HMODULE hModule, LPWSTR lpFilename, DWORD nSize);
#ifdef UNICODE
#define LoadLibrary LoadLibraryW
#define LoadLibraryEx LoadLibraryExW
#define LoadLibrary LoadLibraryW
#define LoadLibraryEx LoadLibraryExW
#define GetModuleFileName GetModuleFileNameW
#else
#define LoadLibrary LoadLibraryA
#define LoadLibraryEx LoadLibraryExA
#define LoadLibrary LoadLibraryA
#define LoadLibraryEx LoadLibraryExA
#define GetModuleFileName GetModuleFileNameA
#endif
WINPR_API FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);

View File

@ -155,6 +155,8 @@ WINPR_API int lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2);
#define sprintf_s snprintf
#define _scprintf(_fmt, ...) snprintf(NULL, 0, _fmt, ## __VA_ARGS__)
#define _scprintf(_fmt, ...) snprintf(NULL, 0, _fmt, ## __VA_ARGS__)
/* Unicode Conversion */
WINPR_API int MultiByteToWideChar(UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr,

View File

@ -21,6 +21,9 @@
#include "config.h"
#endif
#include <winpr/crt.h>
#include <winpr/platform.h>
#include <winpr/library.h>
/**
@ -62,7 +65,10 @@
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
DLL_DIRECTORY_COOKIE AddDllDirectory(PCWSTR NewDirectory)
{
@ -146,5 +152,58 @@ BOOL FreeLibrary(HMODULE hLibModule)
return TRUE;
}
/**
* GetModuleFileName:
* http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197/
*
* Finding current executable's path without /proc/self/exe:
* http://stackoverflow.com/questions/1023306/finding-current-executables-path-without-proc-self-exe
*/
DWORD GetModuleFileNameW(HMODULE hModule, LPWSTR lpFilename, DWORD nSize)
{
return 0;
}
DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
{
#ifdef __linux__
int status;
int length;
char path[64];
if (!hModule)
{
char buffer[4096];
sprintf(path, "/proc/%d/exe", getpid());
status = readlink(path, buffer, sizeof(buffer));
if (status < 0)
return 0;
buffer[status] = '\0';
length = strlen(buffer);
if (length < nSize)
{
CopyMemory(lpFilename, buffer, length);
lpFilename[length] = '\0';
}
else
{
CopyMemory(lpFilename, buffer, nSize - 1);
lpFilename[nSize - 1] = '\0';
}
return 0;
}
#endif
return 0;
}
#endif

View File

@ -10,7 +10,8 @@ set(${MODULE_PREFIX}_TESTS
TestLibrarySetDefaultDllDirectories.c
TestLibraryLoadLibrary.c
TestLibraryFreeLibrary.c
TestLibraryGetProcAddress.c)
TestLibraryGetProcAddress.c
TestLibraryGetModuleFileName.c)
create_test_sourcelist(${MODULE_PREFIX}_SRCS
${${MODULE_PREFIX}_DRIVER}

View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include <winpr/library.h>
int TestLibraryGetModuleFileName(int argc, char* argv[])
{
char ModuleFileName[4096];
GetModuleFileNameA(NULL, ModuleFileName, sizeof(ModuleFileName));
printf("GetModuleFileNameA: %s\n", ModuleFileName);
return 0;
}