![]() |
||
| Home | SwiftForth Archive | SwiftX Archive | |

I needed to know the filename of an already opened file, given only its FID.
Microsoft had the answer, and I ported it to SwiftForth. Not pretty, but useful.
Uses memory at PAD, HERE, and POCKET.
Rick
LIBRARY PSAPI.DLL
6 IMPORT: CreateFileMapping
5 IMPORT: MapViewOfFile
4 IMPORT: GetMappedFileName
1 IMPORT: UnmapViewOfFile
2 IMPORT: GetLogicalDriveStrings
3 IMPORT: QueryDosDevice
: DEVICE>DRIVE ( -- addr len )
1000 PAD 100 + GetLogicalDriveStrings IF
S" C:" HERE ZPLACE
PAD 100 + BEGIN ( a)
DUP C@ WHILE
DUP C@ HERE C!
HERE PAD 100 QueryDosDevice IF
POCKET ZCOUNT PAD ZCOUNT SEARCH NIP NIP IF ( match!)
DROP PAD ZCOUNT NIP
POCKET ZCOUNT ROT /STRING HERE ZAPPEND
HERE ZCOUNT POCKET PLACE POCKET COUNT
EXIT
THEN
THEN
ZCOUNT + 1+
REPEAT DROP
THEN 0 0 ;
: GetFileNameFromHandle ( handle -- addr len )
( h) 0 PAGE_READONLY 0 1 0 CreateFileMapping ?DUP IF ( hmap)
DUP FILE_MAP_READ 0 0 1 MapViewOfFile ( hmap pmem) ?DUP IF
GetCurrentProcess OVER POCKET 256 GetMappedFileName DROP
( pmem) UnmapViewOfFile DROP
THEN
( hmap) CloseHandle DROP
THEN DEVICE>DRIVE ;
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe" to sftalk-request_at_forth.com
For list command help, send subject "help" to sftalk-request_at_forth.com
Message archives are located at http://www.forth.com/archive/sftalk
----------------------------------------------------------------------
This list is a forum for SwiftForth users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Tue Aug 29 2006 - 13:06:12 PDT
This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:40 PST