After an IRC chat with haratron I made this sample code of how to use Win32::MMF raw C style. Without the proprietary Storeable cough cough RPC layer that doesn't let you normally use Win32::MMF for non Perl to Perl IPC communications. The 2 scripts must be in the same folder for them to work. Watch out for buffer overflows, I ALMOST have one in this line "$function->Call($ptr, ("hello MMF".("\x00" x 256)), 256);". mmfwrite.pl __________________________________________________________ use strict; use Win32::MMF qw/ MapViewOfFile CreateFileMapping CloseHandle UnmapViewOfFile /; use Win32; use Win32::API;
*GetLastError = *Win32::GetLastError; our $hnd = CreateFileMapping(undef, 256, 'MyFileMappingObject'); if( !$hnd ) { die "CFM failed GLR=".GetLastError()."\n";} our $ptr = MapViewOfFile($hnd, 0,256); if( !$ptr ) { die "MVOF failed GLR=".GetLastError()."\n";} my $function = Win32::API->new( 'kernel32.dll', 'VOID RtlMoveMemory( DWORD Destination, LPSTR Source, SIZE_T Length)', ); $function->Call($ptr, ("hello MMF".("\x00" x 256)), 256); system($^X." mmfread.pl "); END{ if($ptr) {UnmapViewOfFile($ptr);} if($hnd) {CloseHandle($hnd);} } _______________________________________________________________ mmfread.pl _______________________________________________________________ use strict; use Win32::MMF qw/ MapViewOfFile CreateFileMapping CloseHandle UnmapViewOfFile /; use Win32; use Data::Dumper 'Dumper'; *GetLastError = *Win32::GetLastError; our $hnd = CreateFileMapping(undef, 256, 'MyFileMappingObject'); if( !$hnd ) { die "CFM failed GLR=".GetLastError()."\n";} our $ptr = MapViewOfFile($hnd, 0,256); if( !$ptr ) { die "MVOF failed GLR=".GetLastError()."\n";} my $memblock = unpack('P[256]', pack('J', $ptr)); print "In mmfread.pl\n"; print Dumper($memblock); print "end of mmfread.pl\n"; END{ if($ptr) {UnmapViewOfFile($ptr);} if($hnd) {CloseHandle($hnd);} } ______________________________________________________________ _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs