[EMAIL PROTECTED] wrote on 06/17/2005 02:01:21 PM: > Hi Masters. > > This code on my WinXP crashes perl. > Searched the list , but only the old syle ( Method 1 or Method 2 ) comes up. > I am trying Method 3 , new with .40 onwards. > > Please can somebody point out my "basic" mistake : > > print "TYPE DWORD is known to Win32::API::Type \n" if > Win32::API::Type->is_known('DWORD'); > print "TYPE LPTSTR is known to Win32::API::Type \n" if > Win32::API::Type->is_known('LPTSTR'); > > my $GetTempPathRetVal = Win32::API->Import('kernel32','DWORD GetTempPath( > DWORD nBufferLength, LPTSTR lpBuffer )'); > if($GetTempPathRetVal eq 0) { > die "Can't import API GetTempPath : $^E\n"; > } > > > my $lpBuffer = '-'x80; > my $returnval = GetTempPath(79,$lpBuffer); > my $TempPath = substr($lpBuffer,0,$returnval); > > print "Temp path is : $TempPath !!\n";
This problem was recently discussed. Please check the archives. The fix is # around 158 in Win32::API::Type.pm if you comment these three lines out, # it should work: # if($is_pointer and $packing eq 'c') { # $packing = "p"; # } This now works: use strict; use warnings; use Win32::API; Win32::API->Import('kernel32', 'DWORD GetTempPathA(DWORD ccBuffer, LPSTR lpszBuffer)') or die "Import GetTempPathA: $^E"; my $lpszBuffer = pack 'Z*', ' ' x 80; my $ret = GetTempPathA (80, $lpszBuffer); printf "ret='%s'; lpszBuffer='%s'\n", $ret, substr $lpszBuffer, 0, $ret; __END__ _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs