Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
the code could pass the check, but when I run it, it throws: "mmap failed!!: The handle is invalid at ccc.pl line 29." It seems that the handle I passed from $fh is not correct. My question is what the windows Handle is, and how I get in perl?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> 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(fileno($fh), $size, 0x04) or die "mmap failed!!: $^E "; my $test_str = "Hello Windows mmap!"; syswrite($fh, $test_str); unmap_region($addr, $size) or die "fail to unmap";
Beside: here is the typemap
BOOL T_IV LONG T_IV HANDLE T_IV HWND T_IV HMENU T_IV HKEY T_IV SECURITY_INFORMATION T_UV DWORD T_UV UINT T_UV REGSAM T_UV WPARAM T_UV LPARAM T_IV LPVOID T_UV HANDLE T_UV SIZE_T T_UV DibSect * O_OBJECT ###################################################################### +####### INPUT T_UV $var = ($type)SvUV($arg) ###################################################################### +####### OUTPUT T_UV sv_setuv($arg, (UV)$var);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: what is exactly HANDL is
by ikegami (Patriarch) on Apr 27, 2025 at 17:01 UTC | |
by Anonymous Monk on Apr 28, 2025 at 05:28 UTC | |
Re: what is exactly HANDL is
by pfaut (Priest) on Apr 27, 2025 at 17:11 UTC | |
Re: what is exactly HANDL is
by Fletch (Bishop) on Apr 28, 2025 at 15:47 UTC | |
by etj (Priest) on Apr 30, 2025 at 11:41 UTC | |
Linux example of mmap
by bliako (Abbot) on Apr 28, 2025 at 12:16 UTC |