Newsgroup: it.comp.lang.perl
Titolo: WIN32::API non funziona

Ho provato queto codice che dovrebbe riportarmi il numero di WaveIn 
Device installate sul sistema e delle informazione su di esse:
#!/perl
use strict;
use warnings;
use Win32::API;
use Win32::API::Struct;
use Data::Dumper;
Win32::API::Struct->typedef( "WAVEINCAPS", qw{
   INT ManufacturerID; 
   INT ProductID; 
   LONG DriverVersion; 
   TCHAR ProductName[32]; 
   LONG Formats; 
   INT Channels; 
   INT Reserved;
} ) or die "Typedef error $!\n"; 
#Win32::API->Import( winmm => q{LRESULT waveInGetNumDevs()} );
Win32::API->Import("winmm", "int waveInGetNumDevs()");
Win32::API->Import( winmm => q{LRESULT waveInGetDevCaps(UINT_PTR 
DeviceID, LPWAVEINCAPS pwic, UINT cbwic)} );
my $devices = waveInGetNumDevs();
my $caps = Win32::API::Struct->new("WAVEINCAPS"); # Dim Caps As 
WaveInCaps
print "Devices: $devices\n\n";
my $result;
for (0 .. ($devices - 1) ) {
   $result = waveInGetDevCaps($_, $caps, 
Win32::API::Struct->sizeof('WAVEINCAPS'));
}
print Dumper $caps;
__END__;
Funziona solo: my $devices = waveInGetNumDevs();
ma print Dumper $caps; restituisce tutte variabili null
che fare?

Tanto meno questo codice:
#!/perl
use strict;
use warnings;
use Win32::API;
my ($caps, $devices, $result);
Win32::API::Struct->typedef( 'WAVEINCAPS', qw(
   INT ManufacturerID; 
   INT ProductID; 
   LONG DriverVersion; 
   TCHAR ProductName[32]; 
   LONG Formats; 
   INT Channels; 
   INT Reserved;
)) or die "Typedef error $!\n";
my $caps = Win32::API::Struct->new('WAVEINCAPS'); # Dim Caps As 
WaveInCaps
Win32::API->Import( winmm => "int waveInGetNumDevs()");
Win32::API->Import( winmm => q{LRESULT waveInGetDevCaps(UINT_PTR 
DeviceID, LPWAVEINCAPS pwic, UINT cbwic)} );
$devices = waveInGetNumDevs();
print "Devices: $devices\n\n";
for (0 .. ($devices - 1) ) {
   $result = waveInGetDevCaps($_, $caps, 
Win32::API::Struct->sizeof('WAVEINCAPS'));
   print "Device ID: $_ ,ProductName: $caps->{ProductName}\n";
}
__END__;

Potreste provare anche questo codice?
#!/perl
use strict;
use warnings;
use Win32::API;
my ($WaveFormat,$DevHandle,$result);
my $InData = " " x 44100;
# Private Type WaveFormatEx
Win32::API::Struct->typedef( 'WaveFormatEx', qw(
   INT FormatTag; 
   INT Channels; 
   LONG SamplesPerSec; 
   LONG AvgBytesPerSec; 
   INT BlockAlign; 
   INT BitsPerSample; 
   INT ExtraDataSize;
)) or die "Typedef error $!\n";
# Private Type WaveHdr
Win32::API::Struct->typedef( 'WaveHdr', qw(
   LONG lpData; 
   LONG dwBufferLength; 
   LONG dwBytesRecorded; 
   LONG dwUser; 
   LONG dwFlags; 
   LONG dwLoops; 
   LONG lpNext;
   LONG Reserved
)) or die "Typedef error $!\n";
# Private Type WaveInCaps
Win32::API::Struct->typedef( 'WaveInCaps', qw(
   INT ManufacturerID; 
   INT ProductID; 
   LONG DriverVersion; 
   TCHAR ProductName[32]; 
   LONG Formats; 
   INT Channels; 
   INT Reserved;
)) or die "Typedef error $!\n";
# Declare Function ...
Win32::API->Import( winmm => "int waveInGetNumDevs()");
Win32::API->Import( winmm => q{LRESULT waveInGetDevCaps(UINT_PTR 
DeviceID, LPWAVEINCAPS pwic, UINT cbwic)} );
Win32::API->Import( winmm => q{LRESULT waveInAddBuffer(HWAVEIN 
hwi,LPWAVEHDR pwh,UINT cbwh)} );
Win32::API->Import( winmm => q{LRESULT waveInOpen(LPHWAVEIN 
phwi,UINT_PTR uDeviceID,LPWAVEFORMATEX pwfx,DWORD_PTR 
dwCallback,DWORD_PTR dwCallbackInstance,DWORD fdwOpen)} );
Win32::API->Import( winmm => q{LRESULT waveInPrepareHeader(HWAVEIN 
hwi,LPWAVEHDR pwh,UINT cbwh)} );
Win32::API->Import( winmm => q{LRESULT waveInUnprepareHeader(HWAVEIN 
hwi,LPWAVEHDR pwh,UINT cbwh)} );
Win32::API->Import( winmm => q{LRESULT waveInStart(HWAVEIN hwi)} );
Win32::API->Import( winmm => q{LRESULT waveInStop(HWAVEIN hwi)} );
Win32::API->Import( winmm => q{LRESULT waveInReset(HWAVEIN hwi)} );
Win32::API->Import( winmm => q{LRESULT waveInClose(HWAVEIN hwi)} );
$WaveFormat = Win32::API::Struct->new('WaveFormatEx'); # Static 
WaveFormat As WaveFormatEx
$WaveFormat->{FormatTag} = 1; # WAVE_FORMAT_PCM
$WaveFormat->{Channels} = 1;
$WaveFormat->{SamplesPerSec} = 44100;
$WaveFormat->{BitsPerSample} = 16;
$WaveFormat->{BlockAlign} = 2;
$WaveFormat->{AvgBytesPerSec} = 44100 * 2;
$WaveFormat->{ExtraDataSize} = 0;
$Wave = Win32::API::Struct->new('WaveHdr'); # Static Wave As WaveHdr
$Wave->{lpData} = $InData;
$Wave->{dwBufferLength} = 44100 * 2;
$Wave->{dwFlags} = 0;
$result = waveInOpen($DevHandle, 0, $WaveFormat, 0, 0, 0);
$result = waveInPrepareHeader($DevHandle, $Wave, 
Win32::API::Struct->sizeof('WaveHdr'));
$result = waveInAddBuffer($DevHandle, $Wave, 
Win32::API::Struct->sizeof('WaveHdr'));
$result = waveInStart($DevHandle);
sleep 1;
$result = waveInPrepareHeader($DevHandle, $Wave, 
Win32::API::Struct->sizeof('WaveHdr'));
$result = waveInClose($DevHandle);

Mi sono ufficialmente arreso 
Questo è il codice che ho tirato fuori .. ma naturalmente non funziona: 
http://www.theartofweb.netfirms.com.
..D=3&TOPIC_ID=45 
nevermind!

 wrote:
il link funzionante è questo:
http://www.theartofweb.netfirms.com/cgi-bin/bbsmart/bbsmart.cgi?DO=showto
pic&FORUM_ID=3&TOPIC_ID=45