Hello, I've been trying (for a few days) to use Win32::API and Win32::API::Prototype to import a couple of functions from a DLL, but I can't get it to work properly. I already got a function with no parameters to work, but the other takes a complex struct as a parameter, and I'm obviously missing something. I wonder if you monks can help me out here.

The DLL was written in Delphi ("DiscIdCalcDLL.dll", from http://webplaza.pt.lu/public/vigatol/discidcalc/), and the documentation says:

The GetCdRomDrives scans for Cd-Rom installed on the system and retrie +ves informations over the Cd-Rom drive. function GetCdRomDrives(var CdRoms: TCdRoms): Boolean; Parameters CdRoms Return Values If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE.


The TCdRoms data type is defined as follows:

TCdRom = record HaId : Byte; Target : Byte; Lun : Byte; Vendor : ShortString; ProductId : ShortString; Revision : ShortString; VendorSpec: ShortString; end; TCdRoms = record CdRomCount: Byte; CdRom : array[0..25] of TCdRom; end;


So I did this in Perl:


#!/usr/bin/perl use Win32::API::Prototype; Win32::API::Struct->typedef( TCdRom => qw{ int HaId; int Target; int Lun; char Vendor[256]; char ProductId[256]; char Revision[256]; char VendorSpec[256]; }); Win32::API::Struct->typedef( TCdRoms => qw{ BYTE CdRomCount; TCdRom Drive[26]; }); ApiLink( 'DiscIdCalcDLL.dll', 'int GetCdRomDrives(LPTCdRoms CdRoms)' ) + || die; $cds = Win32::API::Struct->new('TCdRoms'); for (my $i = 0; $i < 26; $i++) { $drvs[$i] = Win32::API::Struct->new('TCdRom'); $cds->{Drive}[$i] = $drvs[$i]; } $x = GetCdRomDrives(\$cds); ########## (ETC) #########################


At this point, $x contains 1, and I'm not sure whether it means "true" or "false" (I would expect -1 for false, 0 for true). And $cds is empty. Using the perl debugger, I get this:

DB<4> x $cds 0 Win32::API::Struct=HASH(0x1c3dc30) 'Drive' => ARRAY(0x1c3e050) 0 Win32::API::Struct=HASH(0x1c12730) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) 0 ARRAY(0x1c12760) 0 'HaId' 1 'i' 2 'int' 1 ARRAY(0x1c127a8) 0 'Target' 1 'i' 2 'int' 2 ARRAY(0x1c127c0) 0 'Lun' 1 'i' 2 'int' 3 ARRAY(0x1c127fc) 0 'Vendor' 1 'c*256' 2 'char' 4 ARRAY(0x1c12838) 0 'ProductId' 1 'c*256' 2 'char' 5 ARRAY(0x1c12874) 0 'Revision' 1 'c*256' 2 'char' 6 ARRAY(0x1c128b0) 0 'VendorSpec' 1 'c*256' 2 'char' 1 Win32::API::Struct=HASH(0x1c3e158) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) -> REUSED_ADDRESS 2 Win32::API::Struct=HASH(0x1c3e194) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) -> REUSED_ADDRESS 3 Win32::API::Struct=HASH(0x1c3e1d0) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) -> REUSED_ADDRESS 4 Win32::API::Struct=HASH(0x1c3e20c) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) -> REUSED_ADDRESS ###### Repeat for indexes 5 through 23, and... ####### 24 Win32::API::Struct=HASH(0x1c3e6bc) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) -> REUSED_ADDRESS 25 Win32::API::Struct=HASH(0x1c3e6f8) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) -> REUSED_ADDRESS 'Drive[26]' => Win32::API::Struct=HASH(0x1c3e05c) '__typedef__' => 'TCdRom' 'typedef' => ARRAY(0x1c12550) -> REUSED_ADDRESS '__typedef__' => 'TCdRoms' 'typedef' => ARRAY(0x1c12778) 0 ARRAY(0x1c1276c) 0 'CdRomCount' 1 'C' 2 'BYTE' 1 ARRAY(0x1c12988) 0 'Drive[26]' 1 '>' 2 'TCdRom' ###################


I don't like that " 'Drive[26]' => Win32::API::Struct=HASH(0x1c3e05c)" after the drive entries, but I don't know how to get rid of it. So, my best guess is I'm passing something wrong as a parameter to GetCdRomDrives, and the function is returning an error. Or maybe it's not returning an error, but it's not returning what I need either (the TCdRoms structure with 1 or 2 entries defined, as I have a CD-ROM and a DVD-ROM drive installed).

Do you have any clues for me? I'm out of guesses.

Thanks a lot,

VMat

In reply to Win32::API arguments by VMat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.