-
Notifications
You must be signed in to change notification settings - Fork 15
/
xalibname.c
92 lines (78 loc) · 2.09 KB
/
xalibname.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*------
* Module: xalibname.c
*
* Description:
* This module gets the (path) name of xalib.
*
*-------
*/
#ifdef _HANDLE_ENLIST_IN_DTC_
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif /* _WIN32_WINNT */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
extern HMODULE s_hModule;
static char xalibpath[_MAX_PATH] = "";
static char xalibname[_MAX_FNAME] = "";
static const char * const PGMFILES = "Program Files";
static const char * const PGMFILESX86 = "Program Files (x86)";
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL IsWow64()
{
static BOOL bCalled = FALSE;
static BOOL bIsWow64 = FALSE;
if (bCalled)
return bIsWow64;
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
GetModuleHandle("kernel32"), "IsWow64Process");
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
//handle error
}
}
bCalled = TRUE;
return bIsWow64;
}
const char *GetXaLibName(void)
{
char dllpath[_MAX_PATH], drive[_MAX_DRIVE], dir[_MAX_DIR],
fname[_MAX_FNAME], ext[_MAX_EXT];
if (!xalibpath[0])
{
size_t pgmflen = strlen(PGMFILESX86);
char *ptr;
GetModuleFileName(s_hModule, dllpath, sizeof(dllpath));
/* In Windows XP SP2, the dllname should be specified */
/* instead of the dll path name, because it looks up */
/* the HKLM\Microfost\MSDTC\XADLL\(dllname) registry */
/* entry for security reason. */
_splitpath(dllpath, drive, dir, fname, ext);
// _snprintf(xalibname, sizeof(xalibname), "%s%s", fname, ext);
strncpy(xalibname, "pgxalib.dll", sizeof(xalibname));
if (IsWow64())
{
if ('\\' == *dir &&
0 == _strnicmp(dir + 1, PGMFILESX86, pgmflen))
{
ptr = dir + 1 + pgmflen;
if ('\\' == *ptr)
_snprintf(xalibpath, sizeof(xalibpath), "%s\\%s%s%s", drive, PGMFILES, ptr, xalibname);
}
}
else
_snprintf(xalibpath, sizeof(xalibpath), "%s%s%s", drive, dir, xalibname);
}
return xalibname;
}
const char *GetXaLibPath(void)
{
GetXaLibName();
return xalibpath;
}
#endif /* _HANDLE_ENLIST_IN_DTC_ */