Created
July 12, 2015 01:40
-
-
Save jlfaucher/78b32211790b7a752290 to your computer and use it in GitHub Desktop.
Rexx : using GCI to call GetShortPathName, GetLongPathName in kernel32 (windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
http://rexx-gci.sourceforge.net/index.html | |
Tested with Regina, ooRexx. | |
GCI must be patched to work under win64 (see end of file). | |
*/ | |
InternalGCI = test_InternalGCI() | |
if \InternalGCI then do | |
ExternalGCI = test_ExternalGCI() | |
if \ ExternalGCI then return | |
end | |
MAX_PATH = 260 | |
if \ declare_GetShortPathName(MAX_PATH) then return | |
if \ declare_GetLongPathName(MAX_PATH) then return | |
-- Needed for Regina | |
call rxfuncadd "sysloadfuncs", "regutil", "sysloadfuncs" | |
call sysloadfuncs | |
call SysFileTree "c:\*.*", "files","O" | |
do i=1 to files.0 | |
file = files.i | |
shortPathName = GetShortPathName(file, MAX_PATH) | |
longPathName = GetLongPathName(shortPathName, MAX_PATH) | |
say file | |
say " "shortPathName | |
say " "longPathName | |
end | |
return | |
test_InternalGCI: procedure | |
InternalGCI = 0 | |
signal on syntax name NotInstalled | |
x = "X" | |
x. = "X" | |
h = RxFuncDefine(x,x,x,x) | |
if h \= 0 & h \= 10005 & DataType(h, "NUM") then InternalGCI = 1 | |
NotInstalled: | |
drop GCI_RC | |
return InternalGCI | |
test_ExternalGCI: procedure | |
h = RxFuncadd(RxFuncDefine, "gci", "RxFuncDefine") | |
return h == 0 | |
declare_GetShortPathName: procedure | |
/* | |
DWORD WINAPI GetShortPathName( | |
_In_ LPCTSTR lpszLongPath, | |
_Out_ LPTSTR lpszShortPath, | |
_In_ DWORD cchBuffer | |
); | |
*/ | |
arg MAX_PATH | |
stem.calltype = "stdcall" | |
stem.0=3 | |
stem.1.type = "indirect string"MAX_PATH | |
stem.2.type = "indirect string"MAX_PATH | |
stem.3.type = "unsigned32" | |
stem.return.type = "unsigned32" | |
h = RxFuncDefine("GetShortPathNameA", "kernel32", "GetShortPathNameA", "stem") | |
return h == 0 | |
GetShortPathName: procedure | |
arg path, MAX_PATH | |
stem.1.value = path | |
stem.2.value = "" | |
stem.3.value = MAX_PATH | |
call GetShortPathNameA "stem" | |
if stem.return.value == 0 then return "<error>" | |
shortPath = stem.2.value | |
if stem.return.value > MAX_PATH then return "<buffer too small>" | |
return shortPath | |
declare_GetLongPathName: procedure | |
/* | |
DWORD WINAPI GetLongPathName( | |
_In_ LPCTSTR lpszShortPath, | |
_Out_ LPTSTR lpszLongPath, | |
_In_ DWORD cchBuffer | |
); | |
*/ | |
arg MAX_PATH | |
stem.calltype = "stdcall" | |
stem.0=3 | |
stem.1.type = "indirect string"MAX_PATH | |
stem.2.type = "indirect string"MAX_PATH | |
stem.3.type = "unsigned32" | |
stem.return.type = "unsigned32" | |
h = RxFuncDefine("GetLongPathNameA", "kernel32", "GetLongPathNameA", "stem") | |
return h == 0 | |
GetLongPathName: procedure | |
arg path, MAX_PATH | |
stem.1.value = path | |
stem.2.value = "" | |
stem.3.value = MAX_PATH | |
call GetLongPathNameA "stem" | |
if stem.return.value == 0 then return "<error>" | |
longPath = stem.2.value | |
if stem.return.value > MAX_PATH then return "<buffer too small>" | |
return longPath | |
/* | |
To compile gci-sources.1.1 for ooRexx under Win32 & Win64, create the file | |
rexxsaa.h in the parent directory of the GCI source directory, which contains : | |
#include "<your path to> rexx.h" | |
typedef void* PVOID ; | |
#define APIRET ULONG | |
typedef CONST char *PCSZ ; | |
Other change in gci_win32.def, to fix a syntax error: | |
4c4 | |
< LIBRARY gci INITINSTANCE | |
--- | |
> LIBRARY gci ; INITINSTANCE | |
Other change in gci_convert.win32.vc, to support 64 bits: | |
89c89,94 | |
< #define GCI_STACK_ELEMENT unsigned | |
--- | |
> #if defined(_M_IX86) | |
> #define GCI_STACK_ELEMENT unsigned __int32 | |
> #else | |
> #define GCI_STACK_ELEMENT unsigned __int64 | |
> #endif | |
> | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment