Win32::api doesn't work?

L

Larry

How come the chunk of code below doesn't work?

#!/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__;

It should return the product name of the devices (like soundblaster)
I can only get the number of the devices

Can anyone tell me what I am getting wrong?

Thanks ever so much!
 
L

Larry

A. Sinan Unur said:

can you please run this code ?

#!/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);
 
A

A. Sinan Unur

can you please run this code ?

Here's what I get:

C:\Home\asu1\UseNet\clpmisc> perl -c wave2.pl
Global symbol "$Wave" requires explicit package name at wave2.pl line
72.
Global symbol "$Wave" requires explicit package name at wave2.pl line
73.
Global symbol "$Wave" requires explicit package name at wave2.pl line
74.
Global symbol "$Wave" requires explicit package name at wave2.pl line
75.
Global symbol "$Wave" requires explicit package name at wave2.pl line
78.
Global symbol "$Wave" requires explicit package name at wave2.pl line
80.
Global symbol "$Wave" requires explicit package name at wave2.pl line
86.
wave2.pl had compilation errors.

When I fix that, I get:

C:\Home\asu1\UseNet\clpmisc> wave2.pl
Win32::API::parse_prototype: WARNING unknown parameter type
'LPWAVEINCAPS' at C:
/opt/Perl/site/lib/Win32/API.pm line 248, <DATA> line 164.
Win32::API::parse_prototype: WARNING unknown parameter type 'HWAVEIN' at
C:/opt/
Perl/site/lib/Win32/API.pm line 248, <DATA> line 164.


and more ...

Please post code others can easily run by cutting and pasting.

Anyway, as I said, I don't know much about the Windows API and I don't
have much motivation to investigate.

Sinan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,166
Messages
2,570,907
Members
47,446
Latest member
Pycoder

Latest Threads

Top