Nahum Cohen wrote: > Hi, > > I'm using Win32::API::Prototype to run GetModuleFileName(). > Does anyone knows why I get a GPF when running this code:
Why do I have to keep telling people the same thing - ALWAYS supply the smallest COMPLETE FAILING snippet that reproduces your problem. This seems to work for me with no problems: use strict; use warnings; use Win32::API::Prototype; ApiLink 'kernel32.dll', 'HMODULE GetModuleHandle(LPCTSTR lpModuleName)' or die "APILink GetModuleHandle: $! ($^E)"; my $lpModuleName = 'kernel32.dll'; my $hModule = GetModuleHandle ($lpModuleName) or die "GetModuleHandle: $! ($^E)"; print "handle for kernel32 = '$hModule'\n"; ApiLink 'kernel32.dll', 'DWORD GetModuleFileName (HMODULE hModule, LPTSTR lpFilename, DWORD nSize)' or die "APILink GetModuleFileName: $! ($^E)"; my $nSize = 256; my $lpFilename = NewString ($nSize); my $ret = GetModuleFileName ($hModule, $lpFilename, $nSize); print "Module File Name: '", substr ($lpFilename, 0, $ret), "'\n"; ApiLink 'kernel32.dll', 'DWORD GetCurrentDirectory (DWORD nBufferLength, LPTSTR lpBuffer)' or die "APILink GetCurrentDirectory: $! ($^E)"; my $nBufferLength = 256; my $lpBuffer = NewString ($nBufferLength); $ret = GetCurrentDirectory ($nBufferLength, $lpBuffer); print "Current Directory = '", substr ($lpBuffer, 0, $ret), "'\n"; __END__ > ApiLink( 'kernel32.dll', 'DWORD GetModuleFileName (HMODULE hModule, > LPTSTR lpFilename, DWORD nSize)' ) || die; > $nSize = 256; > $lpFilename = NewString ($nSize); > GetModuleFileName (NULL, $lpFilename, $nSize); > print "The module file name is: \"$lpFilename\"\n"; > > while this example (from Win32::API::Prototype documentation) works fine: > > ApiLink( 'kernel32.dll', 'DWORD GetCurrentDirectory (DWORD > nBufferLength, LPTSTR lpBuffer)' ) || die; > $nBufferLength = 256; > $lpBuffer = NewString ($nBufferLength); > GetCurrentDirectory ($nBufferLength, $lpBuffer ); > print "The current directory is: \"$lpBuffer\"\n"; -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/ -/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff) _______________________________________________ Perl-Win32-Admin mailing list Perl-Win32-Admin@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs