I posted Re: opening the cd rom yesterday, but now I have a question myself. I copied the original code here, so it is easy to reference. It was a piece of code to eject CDROM:

use Win32::API; use strict; use warnings; my $f = Win32::API->new("winmm", "mciSendString", "PPNN", "N"); my $ret = ' ' x 127; my $return = $f->Call('set CDAudio door open', $ret, 127, 0);

I came from c background, so I tried to modify the API interface to c style, which makes much more sense to me:

use Win32::API; use strict; use warnings; my $f = Win32::API->new("winmm", "long mciSendString(char * a, char * +b, long c, long d)"); my $ret = ' ' x 127; my $return = $f->Call('set CDAudio door open', $ret, 127, 0);

This didn't work, and core dump. I tried couple of other variances, but none of them worked. Please help.

Update:

Changed the code to something like this:

use Win32::API; use strict; use warnings; my $f = Win32::API->new("winmm", 'long mciSendString(LPSTR a, LPSTR b, + long c, long d)'); my $ret = ' ' x 127; $f->Call('set CDAudio door open', $ret, 127, 0);

Now it gives this error:

Modification of a read-only value attempted at C:/Perl/site/lib/Win32/ +API/Type.p m line 195, <DATA> line 164.

In reply to c style Win32::API interface by pg

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.