in reply to what is exactly HANDL is

In this case, it's what's returned by CreateFile.

With MS's C libary, you can use _get_osfhandle to return what you need from a C/unix file descriptor (returned by fileno). I don't know what other C libraries provide, if anything.

Replies are listed 'Best First'.
Re^2: what is exactly HANDL is
by Anonymous Monk on Apr 28, 2025 at 05:28 UTC
    Thanks ikegami, after add _get_osfhandle function, I can get the addr mapping. Before I copy the contents of the address point to to a new SV, Is there a easy way to print the content of the address by perl directly?
    use strict; use warnings; use Fcntl; use Inline C => Config => LIBS => '-lkernel32', BUILD_NOISY => 1, type +maps => 'typemap'; use Inline C => <<'END_OF_C_CODE'; #include <windows.h> #include <winbase.h> #include <io.h> HANDLE get_handle(int fileno){ return _get_osfhandle(fileno); } void* map_region(int filehandle, DWORD size, DWORD prot){ HANDLE hMap = CreateFileMapping((HANDLE)filehandle, NULL, prot, 0, + size, NULL); LPVOID addr = MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, size) +; CloseHandle(hMap); return addr; } int unmap_region(void* addr, DWORD size){ return UnmapViewOfFile(addr); } END_OF_C_CODE my $test_file = 'test_mmap.bin'; sysopen(my $fh, $test_file, O_RDWR|O_CREAT|O_TRUNC) or die "can't open: $!"; binmode $fh; my $size = 4096; my $addr = map_region(get_handle(fileno($fh)), $size, 0x04) or die "mmap failed!!: $^E "; my $test_str = "Hello Windows mmap!"; syswrite($fh, $test_str); print $addr; #How print the contents without XS? unmap_region($addr, $size) or die "fail to unmap"; sysseek($fh, 0, 0); my $buf; sysread($fh, $buf, length($test_str)); print "validate: ", ($buf eq $test_str ? "success" : "failed"), "\n"; close $fh; unlink $test_file;