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);
In reply to what is exactly HANDL is by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |