in reply to Win32::API giving a program error

My guess would be a buffer overflow or similar issue, you are passing a string to your DLL that it is suposed to modify, but you are not telling it how long the string is.
Is there any documentation stateing how long the of a string it expects?
Having played around with some Windows system API calls in perl I've found that some will crash if the string passed to them is either too long or too small, you need to find what range you can pass in that is safe. Given that your passing a 1K buffer I'd guess your on the large size. How long is the expected result string? I'd guess that size times about 2 or 3 should be good, but if there is any documentation to lead you in the right direction that that over my wild guess work.

disclaimer: I doubt my advice will cause any problems, but were talking about calles into C, especaly calls modifing stings, any thing can happen, don't hold me responsible if any advice causes your computer to spontaniously explode or other catestrophic results.

Replies are listed 'Best First'.
Re^2: Win32::API giving a program error
by Anonymous Monk on Jun 03, 2004 at 16:19 UTC
    Hi again,
    again, thanks to you both for your suggestions, I tried a good few variations on the buffer size, but without success. The same error message appeared... I also tried using windows style file paths, and included the change of my ($final) = $string =~/(.*?)\x00/;. But this also had no effect. The code now appears like this:
    #!usr/bin/perl use Win32::API; my $filename="C:\\Program Files\\America Online 9.0g\\aol.exe"; my $apiobject = new Win32::API("C:\\Documents and Settings\\Mdaviesie\ +\Desktop\\dver_1.3\\fileversion.dll", "GetFileVersionTxt", 'PP','I') +or die "Failed to acquire API: $^E"; #Set some memory aside for the returned value my $string="\x00" x 1024; #Call the function in the dll $apiobject->Call($filename,$string)| die "died at line 16"; #Remove the unused padding in the string my ($final) = $string =~/(.*?)\x00/; print "\$final - $final";
    I'm still no closer to figuring this one out, so if anybody out there could help me it would be greatly appreciated.
    Thanks in advance,
    Jonathan
      I know this a not really an awnser to your question, but depending on what you are doing it may offer a solution.
      Are you totally commited to using the Win32::API?
      You can get the information you require using OLE as well, and it is much simpler.
      use Win32::OLE; $file = "M:\\poledit.exe"; $fso = Win32::OLE->new('Scripting.FileSystemObject') or die "Cannot op +en File System Object"; $companyname = $fso->GetFileName ($file); $version = $fso->GetFileVersion ($file); print $companyname, "\t", $version;
      Of course if you are looking to do more with the Win32:API then this doesn't really help you. :-)

      At this point I would start trying different versions of the software involved to see if it is some obscure bug that was recently introduced or fixed. For example, I might:

      1. Make sure I have the latest Win32::API. If not, use PPM to install the latest version. You can also check search.cpan.org to see if there is an bug report, or a note in the change log describing your problem. There may also be something in the Win32::API documentation (Note: I am not implying the Win32::API is the cause of the problem, but it can hurt to look).
      2. Are there other versions of your DLL you can try?
      3. Try a different version of ActivateState perl. I have had good success installing different versions of ActivateState Perl side by side on Win2K Systems. Just keep an eye on your PATH.

      It may seem extream to try different versions of your software, especially Perl. But, it seems like there is little information pointing to the exact cause of the error. By trying some of these points above, you might find a combination that works. I know, I don't like poking at a problem with a stick, but there isn't much to go on here. :-)

      Your error message said that a log file was generated. Any info in there?

      Ted

      Disclamer: I am quite braindead at times and so cannot be held responsible for damage caused by following my advice. That, I am a lowsy speler.

      You have your output parameter set as an Integer. That can't be good...

      Should probably be N or P, no?
        The previously stated function signature take 2 pointers to strings and retunrs and integer, so that should be correct.
        INT GetFileVersionTxt(STRING sFile, out STRING sVersion)