mciSendCommand is actually pretty simple. The tricky part is preparing the structure for its fourth argument, since the structure varies based on the second argument.

I imagine it would look like the following:

package MCI; use strict; use warnings; use Encode qw( decode ); use Win32::API qw( ); use constant { # Messages MCI_INFO => 0x80A MCI_RECORD => 0x80F, ... # Flags MCI_NOTIFY => 0x01, MCI_WAIT => 0x02, ... }; my $send_command = Win32::API->new( 'Winmm.dll', 'mciSendCommandW', 'NNNP', 'N', ); sub send_command { my ($device, $msg, $flags, $packed_parms) = @_; my $rv = $send_command->Call($device, $msg, $flags, $packed_parms); return 1 if $rv == 0; die(MCI::Error->new($rv)); } sub info { my ($device, $flags, $win_handle, $max_chars) = @_; $max_chars ||= 256; my $size = $max_chars * 2; my $str_buf = "\0" x $size; # MCI_INFO_PARMS my $packed_params = pack("IPI", $win_handle, $str_buf, $size, ); return undef if !send_command( $device, MCI_INFO, $flags, $packed_params, ); my ($new_size) = unpack("x4x4I", $packed_params); return decode('UCS-2le', substr($str_buf, 0, $new_size)); # Or $ne +w_size-2? } sub record { my ($device, $flags, $win_handle, $from, $to) = @_; # MCI_RECORD_PARMS my $packed_params = pack('III', $win_handle, $from, $to, ); return send_command( $device, MCI_RECORD, $flags, $packed_params, ); } ... 1;
package MCI::Error; use strict; use warnings; sub new { my ($class, $error) = @_; my $msg = ...mciGetErrorString...; return bless({ code => $error & 0xFFFF, driver_id => $error >> 16, msg => $msg, }, $class); } ... 1;

In reply to Re: Win32::API syntax for mciSendCommand? by ikegami
in thread Win32::API syntax for mciSendCommand? by slloyd

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.