pg has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: c style Win32::API interface
by Roger (Parson) on Oct 05, 2004 at 06:10 UTC | |
|
Re: c style Win32::API interface
by dfaure (Chaplain) on Oct 05, 2004 at 05:53 UTC |