Re: FW: Win32::API help
Bullock, Howard A. wrote: Also, I checked the Win32::API docs and the MSDN web and could not find any information about memcpy that would lead me to: Win32::API('ntdll.dll', 'memcpy', 'PNN', 'V', '_cdecl'); where can I get more information about why this was constructed in this manner? memcpy uses the C calling convention, hence the '_cdecl' ... it is an extension to Win32::API i added some time ago. memcpy normally takes 2 pointers, and an integer length value. the trick is to specify one of the pointers as an integer, and pass it the pointer to something you got from another api, as integer value. willem ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Win32::API help
I am still trying to learn to use the Win32::API module. This attempt is listed below. I have the following questions: 1. The API wants the server name in UNICODE. I have looked at the Unicode module docs but do not understand how they relate to this task. How do I change my standard text name to UNICODE for use with this function? 2. Is the unpacking of the buffer correct for DWORDs? 3. When unpacking the returned data, what is the difference between the LONG and DWORD? Aren't they both 4 bytes? http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt /netmgmt/netremotetod.asp http://support.microsoft.com/kb/249716/EN-US/ Any help in assisting me to better understand these issues and the use of Win32::API in general would be greatly appreciated. #-- use Win32::API; $GetTOD = new Win32::API('Netapi32','NetRemoteTOD','PP','N'); if(not defined $GetTOD) { die Can't import API NetRemoteTOD: $!\n; } $lpBuffer = x 48; $rc = $GetTOD-Call('berd4px01.tycoelectronics.net', $lpBuffer); print $rc . \n; #typedef struct _TIME_OF_DAY_INFO { #DWORD tod_elapsedt; #DWORD tod_msecs; #DWORD tod_hours; #DWORD tod_mins; #DWORD tod_secs; #DWORD tod_hunds; #LONG tod_timezone; #DWORD tod_tinterval; #DWORD tod_day; #DWORD tod_month; #DWORD tod_year; #DWORD tod_weekday; #} TIME_OF_DAY_INFO, *PTIME_OF_DAY_INFO, *LPTIME_OF_DAY_INFO; $tod_month = unpack (L, substr($lpBuffer, 37, 4)); $tod_day = unpack (L, substr($lpBuffer, 33, 4)); $tod_year = unpack (L, substr($lpBuffer, 41, 4)); $tod_hours = unpack (L, substr($lpBuffer, 9, 4)); $tod_mins = unpack (L, substr($lpBuffer, 13, 4)); $tod_secs = unpack (L, substr($lpBuffer, 17, 4)); $tod_timezone = unpack (L, substr($lpBuffer, 25, 4)) * 60 print $tod_month .\n; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32::API help
Bullock, Howard A. wrote: 1. The API wants the server name in UNICODE. I have looked at the Unicode module docs but do not understand how they relate to this task. How do I change my standard text name to UNICODE for use with this function? use Encode qw(encode); printf(%s, encode(UCS-2LE, 'asdadasdads')); 2. Is the unpacking of the buffer correct for DWORDs? 3. When unpacking the returned data, what is the difference between the LONG and DWORD? Aren't they both 4 bytes? yes. DWORD is an unsigned 32 bit integer, LONG a signed 32 bit integer. $tod_month = unpack (L, substr($lpBuffer, 37, 4)); $tod_day = unpack (L, substr($lpBuffer, 33, 4)); $tod_year = unpack (L, substr($lpBuffer, 41, 4)); $tod_hours = unpack (L, substr($lpBuffer, 9, 4)); $tod_mins = unpack (L, substr($lpBuffer, 13, 4)); $tod_secs = unpack (L, substr($lpBuffer, 17, 4)); $tod_timezone = unpack (L, substr($lpBuffer, 25, 4)) * 60 why do you use the odd offsets? from the struct in the comments in your code everything seems perfecty aligned to dwords. you should write this with one unpack call, like this: ( undef, undef, $tod_hours, $tod_mins, $tod_secs, undef, $tod_timezone, undef, $tod_day, $tod_month, $tod_year, undef )= unpack(L6lL5, $lpBuffer); willem ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32::API help
With the help of willem my new code follows. It returns zero (0) as the return code but the buffer does not appear to contain the expected data. Any additional insights would be appreciated. Results: Returncode = 0 tod_elapsedt = 388696 - this val always the same tod_msecs= 0 tod_hours= 0 tod_mins = 0 tod_secs = 0 tod_hunds= 0 tod_timezone = 0 tod_tinterval= 0 tod_day = 0 tod_month= 0 tod_year = 0 tod_weekday = 0 # use Win32::API; use Encode qw(encode); $GetTOD = new Win32::API('Netapi32','NetRemoteTOD','PP','N'); if(not defined $GetTOD) { die Can't import API NetRemoteTOD: $!\n; } $lpBuffer = \x00 x 48; $native_string = server; #Windows 2003 $Unicode_String = encode(UCS-2LE, uc($native_string)); $rc = $GetTOD-Call($Unicode_String, $lpBuffer); print Returncode = . $rc . \n; #typedef struct _TIME_OF_DAY_INFO { #DWORD tod_elapsedt; #DWORD tod_msecs; #DWORD tod_hours; #DWORD tod_mins; #DWORD tod_secs; #DWORD tod_hunds; #LONG tod_timezone; #DWORD tod_tinterval; #DWORD tod_day; #DWORD tod_month; #DWORD tod_year; #DWORD tod_weekday; #} TIME_OF_DAY_INFO, *PTIME_OF_DAY_INFO, *LPTIME_OF_DAY_INFO; ( $tod_elapsedt, $tod_msecs, $tod_hours, $tod_mins, $tod_secs, $tod_hunds, $tod_timezone, $tod_tinterval, $tod_day, $tod_month, $tod_year, $tod_weekday ) = unpack(L6lL5, $lpBuffer); print tod_elapsedt = $tod_elapsedt tod_msecs= $tod_msecs tod_hours= $tod_hours tod_mins = $tod_mins tod_secs = $tod_secs tod_hunds= $tod_hunds tod_timezone = $tod_timezone tod_tinterval= $tod_tinterval tod_day = $tod_day tod_month= $tod_month tod_year = $tod_year tod_weekday = $tod_weekday; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32::API help
Bullock, Howard A. wrote: With the help of willem my new code follows. It returns zero (0) as the return code but the buffer does not appear to contain the expected data. Any additional insights would be appreciated. tod_elapsedt = 388696 - this val always the same if you read the msdn docs, you will see that this is a pointer to the timeofday struct. you can obtain the contents of it using the same 'memcpy(P,N,N)' trick i posted before. willem . use Win32::API; use Encode qw(encode); $GetTOD = new Win32::API('Netapi32','NetRemoteTOD','PP','N'); $native_string = server; #Windows 2003 $Unicode_String = encode(UCS-2LE, uc($native_string)); $todptr= \x00 x 4; $rc = $GetTOD-Call($Unicode_String, $todptr); print Returncode = . $rc . \n; $todptr= unpack(V, $todptr); my $toddata= \x00 x 48; my $memcpy= new Win32::API('ntdll.dll', 'memcpy', 'PNN', 'V', '_cdecl'); $memcpy-Call($toddata, $todptr, length($toddata)); now you can unpack $toddata ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
FW: Win32::API help
The list was originally omitted from the email. [Bullock, Howard A.] I have tried all sorts of interations. Perl 5.8.7.815 blows up every time I execute memcpy-Call. At this point I am not sure where to go. Can anyone confirm that this approach actually works? Also, I checked the Win32::API docs and the MSDN web and could not find any information about memcpy that would lead me to: Win32::API('ntdll.dll', 'memcpy', 'PNN', 'V', '_cdecl'); where can I get more information about why this was constructed in this manner? Willem wrote: if you read the msdn docs, you will see that this is a pointer to the timeofday struct. you can obtain the contents of it using the same 'memcpy(P,N,N)' trick i posted before. . use Win32::API; use Encode qw(encode); $GetTOD = new Win32::API('Netapi32','NetRemoteTOD','PP','N'); $native_string = server; #Windows 2003 $Unicode_String = encode(UCS-2LE, uc($native_string)); $todptr= \x00 x 4; $rc = $GetTOD-Call($Unicode_String, $todptr); print Returncode = . $rc . \n; $todptr= unpack(V, $todptr); my $toddata= \x00 x 48; my $memcpy= new Win32::API('ntdll.dll', 'memcpy', 'PNN', 'V', '_cdecl'); $memcpy-Call($toddata, $todptr, length($toddata)); now you can unpack $toddata ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32::API Help
Bullock, Howard A. wrote: Thanks to both of you for the feedback. Unfortunately, I could get neither to work. I did find a two call workaround using Win32::Lanman methods. In the long run I really would like to understand how to get this and other API calls to works. Thanks again. looking at the msdn docs a bit beeter, it returns a pointer to a memory block, allocated by the api. ... i don't have any domain controlers here to test the DsEnumerateDomainTrusts function, so i use another function that allocates memory for you to show how you could solve this: i use a memcpy with one int param instead of a ptr, to copy the contents of the allocated buffer to a perl string. this example prints the message for error code '0' : 'The operation completed successfully.' willem use constant { FORMAT_MESSAGE_ALLOCATE_BUFFER=0x0100, FORMAT_MESSAGE_IGNORE_INSERTS =0x0200, FORMAT_MESSAGE_FROM_STRING=0x0400, FORMAT_MESSAGE_FROM_HMODULE =0x0800, FORMAT_MESSAGE_FROM_SYSTEM=0x1000, FORMAT_MESSAGE_ARGUMENT_ARRAY =0x2000, FORMAT_MESSAGE_MAX_WIDTH_MASK =0x00FF, }; my $msgptr=\x00 x 4; my $errcode= 0; my $FormatMessage = new Win32::API('kernel32.dll', 'FormatMessage', 'PNN', 'N') or die fmtmsg: $!\n; my $rc= $FormatMessage-Call(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 0, $errcode, 0, $msgptr, 0, 0); $msgptr= unpack(V, $msgptr); printf(rc=%d msg=%08lx\n, $rc, $msgptr); my $msg= \x00 x $rc; my $memcpy= new Win32::API('ntdll.dll', 'memcpy', 'PNN', 'V', '_cdecl') or die memcpy: $!\n; $memcpy-Call($msg, $msgptr, $rc); printf(msg: %s\n, $msg); my $LocalFree= new Win32::API('kernel32.dll', 'LocalFree', 'N', 'V') or die fmtmsg: $!\n; $LocalFree-Call($msgptr); ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32::API Help
- Original Message - From: Bullock, Howard A. [EMAIL PROTECTED] To: perl-win32-users perl-win32-users@listserv.ActiveState.com Sent: Thursday, February 16, 2006 1:29 AM Subject: Win32::API Help I can't seems to get the API call to work. Can someone give me some guidance? . . Not sure ... and I'm not really set up to test ... try something like: use Win32::API; use strict; use warnings; use constant DS_DOMAIN_DIRECT_INBOUND = 2; use constant DS_DOMAIN_DIRECT_OUTBOUND = 2; use constant DS_DOMAIN_IN_FOREST = 1; use constant DS_DOMAIN_NATIVE_MODE = 16; use constant DS_DOMAIN_PRIMARY = 8; use constant DS_DOMAIN_TREE_ROOT = 4; use constant DS_DOMAIN_VALID_FLAGS = 63; my ($domains, $domainCount) = ('' x 500, '' x 100); my $DsEnumerateDomainTrusts = new Win32::API('Netapi32', 'DsEnumerateDomainTrusts', 'PNPP', 'N'); if(! $DsEnumerateDomainTrusts) { die Can't import API DsEnumerateDomainTrusts: $^E; } my $ret = $DsEnumerateDomainTrusts-Call ('bullockha3', DS_DOMAIN_DIRECT_INBOUND, $domains, $domainCount); print Return: $ret\nDomains: $domains\nDomain Count: $domainCount\n; if($ret 1004) {print ERROR: ERROR_INVALID_FLAGS\n} if($ret 1311) {print ERROR: ERROR_NO_LOGON_SERVERS\n} if($ret 1786) {print ERROR: ERROR_NO_TRUST_LSA_SECRET\n} if($ret 1787) {print ERROR: ERROR_NO_TRUST_SAM_ACCOUNT\n} if($ret 50) {print ERROR: ERROR_NOT_SUPPORTED\n} if(!$ret) {print No error\n} __END__ Cheers, Rob ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32::API Help
Thanks to both of you for the feedback. Unfortunately, I could get neither to work. I did find a two call workaround using Win32::Lanman methods. In the long run I really would like to understand how to get this and other API calls to works. Thanks again. From: Sisyphus [mailto:[EMAIL PROTECTED] Sent: Thursday, February 16, 2006 7:09 AM Subject: Re: Win32::API Help -- Let me know if that gets it for you. -- ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Win32::API Help
Sisyphus wrote: my $DsEnumerateDomainTrusts = new Win32::API('Netapi32', 'DsEnumerateDomainTrusts', 'PNPP', 'N'); in my netapi32.dll there is no DsEnumerateDomainTrusts, it contains a DsEnumerateDomainTrustsW and DsEnumerateDomainTrustsA version of this call. willem ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32::API Help
Willem Wrote: in my netapi32.dll there is no DsEnumerateDomainTrusts, it contains a DsEnumerateDomainTrustsW and DsEnumerateDomainTrustsA version of this call. From the Win32::API docs: Also note that many Win32 APIs are exported twice, with the addition of a final A or W to their name, for - respectively - the ASCII and the Unicode version. When a function name is not found, Win32::API will actually append an A to the name and try again; if the extension is built on a Unicode system, then it will try with the W instead. So our function name will be: $GetTempPath = new Win32::API('kernel32', 'GetTempPath', ... In our case GetTempPath is really loaded as GetTempPathA. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32::API Help
---8-- in my netapi32.dll there is no DsEnumerateDomainTrusts, it contains a DsEnumerateDomainTrustsW and DsEnumerateDomainTrustsA version of this call. From the Win32::API docs: Also note that many Win32 APIs are exported twice, with the addition of a final A or W to their name, for - respectively - the ASCII and the Unicode version. When a function name is not found, Win32::API will actually append an A to the name and try again; if the extension is built on a Unicode system, then it will try with the W instead. So our function name will be: $GetTempPath = new Win32::API('kernel32', 'GetTempPath', ... In our case GetTempPath is really loaded as GetTempPathA. ---8-- I've used Win32::API once, fortunately the dll was documented well enough such that I could call its functionality. Thereafter I've always wondered how you expose a dll's functionality and their respective prototypes that don't have any docs? Is there a dll exposer of some sort that you use? Anyone able to share any freeware, docs, or weblinks? Thanks Just in ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Win32::API Help
I can't seems to get the API call to work. Can someone give me some guidance? use Win32::API; use strict; my ($domains, $domaincount); my $DsEnumerateDomainTrusts = new Win32::API('Netapi32', 'DsEnumerateDomainTrusts', 'PNPP', 'N'); if(not defined $DsEnumerateDomainTrusts) { die Can't import API DsEnumerateDomainTrusts: $!\n; } $DsEnumerateDomainTrusts-Call('bullockha3', DS_DOMAIN_DIRECT_OUTBOUND, $domains, $domainCount); http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ad/ad/d senumeratedomaintrusts.asp DS_DOMAIN_DIRECT_OUTBOUND is listed as a flag(s) or zero. I have tried zero (0) I get nothing back. ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
More Win32::API Help....
Hi All, Can anyone see what's wrong with the following? Doesn't seem to matter what filename I pass in, I still get the same result, error 123 (The filename, directory name, or volume label syntax is incorrect.). As far as I can tell from the debug output, the structs are getting set up correctly. Am I passing the filename in properly? Tried appending a \0 but that didn't help either :( Function definition is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp Cheers, Paul use Win32::API; $Win32::API::DEBUG = 1; Win32::API::Struct-typedef(FILETIME, qw( DWORD dwLowDateTime; DWORD dwHighDateTime; )); Win32::API::Struct-typedef(WIN32_FIND_DATA, qw( DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[260]; TCHAR cAlternateFileName[14]; )); Win32::API-Import(kernel32, HANDLE FindFirstFile( LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData )) or die; my $FileName = C:\\WINNT; my $FileInfo = Win32::API::Struct-new(WIN32_FIND_DATA); my $handle = FindFirstFile($FileName, $FileInfo); print Handle returned is $handle\n; printf(Error is %d - %s,Win32::GetLastError(), Win32::FormatMessage(Win32::GetLastError())); * Gloucester Research Limited believes the information provided herein is reliable. While every care has been taken to ensure accuracy, the information is furnished to the recipients with no warranty as to the completeness and accuracy of its contents and on condition that any errors or omissions shall not be made the basis for any claim, demand or cause for action. * ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: More Win32::API Help....
Paul Sobey wrote: Hi All, Can anyone see what's wrong with the following? Doesn't seem to matter what filename I pass in, I still get the same result, error 123 (The filename, directory name, or volume label syntax is incorrect.). As far as I can tell from the debug output, the structs are getting set up correctly. Am I passing the filename in properly? Tried appending a \0 but that didn't help either :( Function definition is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp It doesn't seem to like the impoirt method for me. Try the code at the end and see if it makes a difference. use Win32::API; $Win32::API::DEBUG = 1; Win32::API::Struct-typedef(FILETIME, qw( DWORD dwLowDateTime; DWORD dwHighDateTime; )); Win32::API::Struct-typedef(WIN32_FIND_DATA, qw( DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[260]; TCHAR cAlternateFileName[14]; )); Win32::API-Import(kernel32, HANDLE FindFirstFile( LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData )) or die; my $FileName = C:\\WINNT; my $FileInfo = Win32::API::Struct-new(WIN32_FIND_DATA); my $handle = FindFirstFile($FileName, $FileInfo); print Handle returned is $handle\n; printf(Error is %d - %s,Win32::GetLastError(), Win32::FormatMessage(Win32::GetLastError())); use strict; use Win32::API; use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; $Win32::API::DEBUG = 0; Win32::API::Struct-typedef('FILETIME', qw( DWORD dwLowDateTime; DWORD dwHighDateTime; )); # 8 bytes use constant FILE_ATTRIBUTE_READONLY = 0x0001; use constant FILE_ATTRIBUTE_HIDDEN = 0x0002; use constant FILE_ATTRIBUTE_SYSTEM = 0x0004; use constant FILE_ATTRIBUTE_DIRECTORY = 0x0010; use constant FILE_ATTRIBUTE_ARCHIVE = 0x0020; use constant FILE_ATTRIBUTE_NORMAL = 0x0080; use constant FILE_ATTRIBUTE_TEMPORARY = 0x0100; use constant FILE_ATTRIBUTE_COMPRESSED = 0x0800; use constant MAX_PATH = 260; Win32::API::Struct-typedef('WIN32_FIND_DATA', qw( DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[260]; TCHAR cAlternateFileName[14]; )); # 4+8+8+8+4+4+4+4+260+14=318 bytes Win32::API-Import('kernel32', 'HANDLE FindFirstFile (LPCTSTR lpFileName, ' . 'LPWIN32_FIND_DATA lpFindFileData)') or die Import FindFirstFile: $!($^E); # added the old non-import call my $FindFirstFile = new Win32::API('kernel32', 'FindFirstFile', 'PS', 'N') or die Find FindFirstFile: $^E; my $FileName = 'C:\\WINNT'; # my $FileName = D:\\Windows; # for my test on XP my $FileInfo = Win32::API::Struct-new('WIN32_FIND_DATA'); print Data::Dumper-Dump([$FileName, $FileInfo], [qw($FileName $FileInfo)]); # changed to -Call format # my $handle = FindFirstFile ($FileName, $FileInfo); my $handle = $FindFirstFile-Call($FileName, $FileInfo); print Handle returned is $handle\n; if ($handle 0) { printf Error is %d - %s\n, Win32::GetLastError (), Win32::FormatMessage (Win32::GetLastError ()); } else { print Data::Dumper-Dump([$FileInfo], [qw($FileInfo)]); } __END__ -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: More Win32::API Help....
You're a genius - thankyou. I wonder why the prototype method doesn't work? Seems a bit frustrating! P. -Original Message- From: $Bill Luebkert [mailto:[EMAIL PROTECTED] Sent: 17 November 2004 13:37 To: Paul Sobey Cc: [EMAIL PROTECTED] Subject: Re: More Win32::API Help Paul Sobey wrote: Hi All, Can anyone see what's wrong with the following? Doesn't seem to matter what filename I pass in, I still get the same result, error 123 (The filename, directory name, or volume label syntax is incorrect.). As far as I can tell from the debug output, the structs are getting set up correctly. Am I passing the filename in properly? Tried appending a \0 but that didn't help either :( Function definition is here: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp It doesn't seem to like the impoirt method for me. Try the code at the end and see if it makes a difference. use Win32::API; $Win32::API::DEBUG = 1; Win32::API::Struct-typedef(FILETIME, qw( DWORD dwLowDateTime; DWORD dwHighDateTime; )); Win32::API::Struct-typedef(WIN32_FIND_DATA, qw( DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[260]; TCHAR cAlternateFileName[14]; )); Win32::API-Import(kernel32, HANDLE FindFirstFile( LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData )) or die; my $FileName = C:\\WINNT; my $FileInfo = Win32::API::Struct-new(WIN32_FIND_DATA); my $handle = FindFirstFile($FileName, $FileInfo); print Handle returned is $handle\n; printf(Error is %d - %s,Win32::GetLastError(), Win32::FormatMessage(Win32::GetLastError())); use strict; use Win32::API; use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; $Win32::API::DEBUG = 0; Win32::API::Struct-typedef('FILETIME', qw( DWORD dwLowDateTime; DWORD dwHighDateTime; )); # 8 bytes use constant FILE_ATTRIBUTE_READONLY = 0x0001; use constant FILE_ATTRIBUTE_HIDDEN = 0x0002; use constant FILE_ATTRIBUTE_SYSTEM = 0x0004; use constant FILE_ATTRIBUTE_DIRECTORY = 0x0010; use constant FILE_ATTRIBUTE_ARCHIVE = 0x0020; use constant FILE_ATTRIBUTE_NORMAL = 0x0080; use constant FILE_ATTRIBUTE_TEMPORARY = 0x0100; use constant FILE_ATTRIBUTE_COMPRESSED = 0x0800; use constant MAX_PATH = 260; Win32::API::Struct-typedef('WIN32_FIND_DATA', qw( DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[260]; TCHAR cAlternateFileName[14]; )); # 4+8+8+8+4+4+4+4+260+14=318 bytes Win32::API-Import('kernel32', 'HANDLE FindFirstFile (LPCTSTR lpFileName, ' . 'LPWIN32_FIND_DATA lpFindFileData)') or die Import FindFirstFile: $!($^E); # added the old non-import call my $FindFirstFile = new Win32::API('kernel32', 'FindFirstFile', 'PS', 'N') or die Find FindFirstFile: $^E; my $FileName = 'C:\\WINNT'; # my $FileName = D:\\Windows; # for my test on XP my $FileInfo = Win32::API::Struct-new('WIN32_FIND_DATA'); print Data::Dumper-Dump([$FileName, $FileInfo], [qw($FileName $FileInfo)]); # changed to -Call format # my $handle = FindFirstFile ($FileName, $FileInfo); my $handle = $FindFirstFile-Call($FileName, $FileInfo); print Handle returned is $handle\n; if ($handle 0) { printf Error is %d - %s\n, Win32::GetLastError (), Win32::FormatMessage (Win32::GetLastError ()); } else { print Data::Dumper-Dump([$FileInfo], [qw($FileInfo)]); } __END__ -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) * Gloucester Research Limited believes the information provided herein is reliable. While every care has been taken to ensure accuracy, the information is furnished to the recipients with no warranty as to the completeness and accuracy of its contents and on condition that any errors or omissions shall not be made the basis for any claim, demand or cause for action. * ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: More Win32::API Help....
Paul Sobey wrote: You're a genius - thankyou. I wonder why the prototype method doesn't work? Seems a bit frustrating! That whole set of modules is a bit flakey for my taste. I made lots of quick changes to keep warnings from popping up and had lots of trouble with structs and such. You have to try alternate methods for everything until you find something that works. :) -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Win32::API help
Thanks Bill, It works ! Thanks a lot again ! With Best Regards, V.S. Jangale ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs