VB to Perl

L

Larry

Hi all,

Sorry for gettin back on this question but I wasn't able to go about it!

Below is a chunk of VB code:

[vb]
Private Type WaveInCaps
ManufacturerID As Integer
ProductID As Integer
DriverVersion As Long
ProductName(1 To 32) As Byte
Formats As Long
Channels As Integer
Reserved As Integer
End Type

Dim Caps As WaveInCaps
Call waveInGetDevCaps(0, VarPtr(Caps), Len(Caps))
[/vb]


and I need to that in Perl!!

sorry again!

(I ain't gonna post this anymore)
 
S

Sherm Pendley

Larry said:
and I need to that in Perl!!

What have you tried so far? What were the results, and how were they
different from what you expected?

Looks to me like the VB declares a complex data type, declares an instance
of that type, then passes the address and size of that instance to some
function.

To learn about working with complex data types in Perl, have a look at:

perldoc perlreftut
perldoc perldsc

sherm--
 
C

Chris Mattern

Robert said:
What? You haven't said what it does. Shall we learn VB to help you?
I'm not gonna learn VB. I can't afford the IQ loss.

--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
 
W

Wes Groleau

Larry said:
Hi all,

Sorry for gettin back on this question but I wasn't able to go about it!

Below is a chunk of VB code:

[vb]
Private Type WaveInCaps
ManufacturerID As Integer
ProductID As Integer
DriverVersion As Long
ProductName(1 To 32) As Byte
Formats As Long
Channels As Integer
Reserved As Integer
End Type

defines what Ada/Pascal calls a record, C or C++ a struct
Dim Caps As WaveInCaps

Creates one of those and names it Caps
Call waveInGetDevCaps(0, VarPtr(Caps), Len(Caps))

Calls a function and passes it some information
about Caps.
 
A

A. Sinan Unur

Sorry for gettin back on this question but I wasn't able to go
about it!

Below is a chunk of VB code:

This is a Windows 32 API call. Surprisingly enough, there is a Perl module
called Win32::API on CPAN.

....
and I need to that in Perl!!

Then you should consider trying to do it yourself first and posting
questions about the _specific_ problems you encounter.

On the other hand, I am getting tired of pointing out this obvious maxim
to people who are obviously never going to learn. Here's some untested
code. Enjoy!
sorry again!

Don't apologize. Just do what the posting guidelines suggest and there
won't be any need for apologies. Useless apologies create just as much
noise as asinine queries.

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

Win32::API->Import(winmm => q{
LRESULT waveInGetDevCaps(
UINT_PTR DeviceID,
LPWAVEINCAPS pwic,
UINT cbwic
)}
);

my $caps = Win32::API::Struct->new('WAVEINCAPS');

# You probably need a way of finding out a valid device id
# 0 seems suspect

my $result = waveInGetDevCaps(
0,
$caps,
Win32::API::Struct->sizeof('WAVEINCAPS')
);

print Dumper $caps;

__END__
 
W

Wes Groleau

J����������������������������������� said:
Maybe
waveInGetDevCaps(0, $Caps{VarPrt}, $Caps{Len});

Yes, but I think the OP wants us to tell him/her
how to write waveInGetDevCaps in perl. :)

--
Wes Groleau
-----------

"Thinking I'm dumb gives people something to
feel smug about. Why should I disillusion them?"
-- Charles Wallace
(in _A_Wrinkle_In_Time_)
 
L

Larry

A. Sinan Unur said:
Here's some untested code. Enjoy!

I can not thank you enough!! That made my life a lot easier!

I just need you to spell out the chunk of code below:

Win32::API->Import(winmm => q{
LRESULT waveInGetDevCaps(
UINT_PTR DeviceID,
LPWAVEINCAPS pwic,
UINT cbwic
)}
);

I feel to know the "import" function but it'd be great if you could tell
me what "LRESULT","UINT_PTR","UINT_PTR" and "UINT" are meant to be!

thanks again!!!
 
A

A. Sinan Unur

I can not thank you enough!! That made my life a lot easier!

I just need you to spell out the chunk of code below:

Win32::API->Import(winmm => q{
LRESULT waveInGetDevCaps(
UINT_PTR DeviceID,
LPWAVEINCAPS pwic,
UINT cbwic
)}
);

I feel to know the "import" function

We are talking about the "Import" method of the Win32::API module here.
Case matters.
but it'd be great if you could tell me what
"LRESULT","UINT_PTR","UINT_PTR" and "UINT" are meant to
be!

We are talking about the Windows API here. So, you need to head on over
to Microsoft's web site and read about it there:
<http://tinyurl.com/3wogu>.

These are mnemonics for C typedefs. Roughly, you can read them as

LRESULT = "Long Result"
UINT = "Unsigned Integer"
UINT_PTR = "Pointer to Unsigned Integer"

I used LRESULT rather than MMRESULT because I did not have time to check
the typedef for MMRESULT. It seemed to work on XP32 but looking at the
header file, I see that MMRESULT is typedef'ed to UINT on 32 bit
platforms. There is no guarantee that MMRESULT will not be typedef'ed in
to something else on. say, XP64.

This is drifting off-topic for this group. If you have questions about
the Windows API's there are other fora dedicated to various parts of it.

If you are going to be using the Windows API, you should probably
download and install the Platform SDK available from Microsoft at least
to have the header files available so you can check this sort of stuff.

Sinan
 
T

Tad McClellan

Wes Groleau said:
:

Yes, but I think the OP wants us to tell him/her
how to write waveInGetDevCaps in perl. :)


That's easy!

You write it like this:

wave_in_get_dev_caps()
 
L

Larry

A. Sinan Unur said:
#! /usr/bin/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;
)
);

Win32::API->Import(winmm => q{
LRESULT waveInGetDevCaps(
UINT_PTR DeviceID,
LPWAVEINCAPS pwic,
UINT cbwic
)}
);

my $caps = Win32::API::Struct->new('WAVEINCAPS');

# You probably need a way of finding out a valid device id
# 0 seems suspect

my $result = waveInGetDevCaps(
0,
$caps,
Win32::API::Struct->sizeof('WAVEINCAPS')
);

print Dumper $caps;

__END__

I tryed this code but I got all null values in $caps

Why?
 

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
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top