Help on Win32 API
am 20.06.2007 15:53:31 von jis
Hi,
I have a dll by name AduHid.dll.
There is a function with prototype
void * _stdcall OpenAduDeviceBySerialNumber(const char*
psSerialNUmber,unsigned long iTimeout);
I used the following perl code to call the above function
use Win32::API;
my $function = Win32::API->new(
'AduHid.dll','int OpenAduDeviceBySerialNumber(const
char* psSerialNUmber,unsigned long iTimeout)' );
my $return = $function->Call("A03744",0);
But i get an error
1. unknown parameter type const and unsigned
2. Argument A03744 isnt numeric in subroutine entry.
I tried removing const and unsigned.Then I got an error
"Modification of read only value attempted".
Where am i going wrong?
Please advise.
regards,
jis
Re: Help on Win32 API
am 20.06.2007 17:44:46 von paduille.4061.mumia.w+nospam
On 06/20/2007 08:53 AM, jis wrote:
> Hi,
>
> I have a dll by name AduHid.dll.
> There is a function with prototype
>
> void * _stdcall OpenAduDeviceBySerialNumber(const char*
> psSerialNUmber,unsigned long iTimeout);
>
> I used the following perl code to call the above function
>
> use Win32::API;
> my $function = Win32::API->new(
> 'AduHid.dll','int OpenAduDeviceBySerialNumber(const
> char* psSerialNUmber,unsigned long iTimeout)' );
>
> my $return = $function->Call("A03744",0);
>
> But i get an error
> 1. unknown parameter type const and unsigned
> 2. Argument A03744 isnt numeric in subroutine entry.
>
> I tried removing const and unsigned.Then I got an error
> "Modification of read only value attempted".
>
> Where am i going wrong?
> Please advise.
>
> regards,
> jis
>
I don't have access to a Windows computer, but I was able to download
the CPAN source for Win32::API. Read the POD for Win32::API::Types. It
says you should examine the __DATA__ section of Win32/API/Types.pm to
see a list of supported types.
You might need to specify a prototype like this:
int OpenAduDeviceBySerialNumber(PCHAR psSerialNUmber, ULONG iTimeout)
I hope this helps some.
Re: Help on Win32 API
am 21.06.2007 00:22:54 von paduille.4061.mumia.w+nospam
On 06/20/2007 11:25 AM, jis wrote:
> On Jun 20, 10:44 am, "Mumia W."
> +nos...@earthlink.net> wrote:
>> On 06/20/2007 08:53 AM, jis wrote:
>>
>>
>>
>>
>>
>>> Hi,
>>> I have a dll by name AduHid.dll.
>>> There is a function with prototype
>>> void * _stdcall OpenAduDeviceBySerialNumber(const char*
>>> psSerialNUmber,unsigned long iTimeout);
>>> I used the following perl code to call the above function
>>> use Win32::API;
>>> my $function = Win32::API->new(
>>> 'AduHid.dll','int OpenAduDeviceBySerialNumber(const
>>> char* psSerialNUmber,unsigned long iTimeout)' );
>>> my $return = $function->Call("A03744",0);
>>> But i get an error
>>> 1. unknown parameter type const and unsigned
>>> 2. Argument A03744 isnt numeric in subroutine entry.
>>> I tried removing const and unsigned.Then I got an error
>>> "Modification of read only value attempted".
>>> Where am i going wrong?
>>> Please advise.
>>> regards,
>>> jis
>> I don't have access to a Windows computer, but I was able to download
>> the CPAN source for Win32::API. Read the POD for Win32::API::Types. It
>> says you should examine the __DATA__ section of Win32/API/Types.pm to
>> see a list of supported types.
>>
>> You might need to specify a prototype like this:
>>
>> int OpenAduDeviceBySerialNumber(PCHAR psSerialNUmber, ULONG iTimeout)
>>
>> I hope this helps some.- Hide quoted text -
>>
>> - Show quoted text -
>
> Thanks for the quick reply.
> It took away errors that were there.But came up with an error
> "Modification of read only value attempted"
> Only time it gave away the error was when i tried
> int OpenAduDeviceBySerialNumber(CHAR psSerialNumber[],ULONG
> iTimeout)
> Unfortunately this time the code crashed with "the memory could not be
> read"
>
> Anyway it took me a step ahead.
>
> regards,
> jis
>
>
Try to keep the conversation in the newsgroup.
"Const char*" tells me that psSerialNUmber is a pointer to characters,
so either PCHAR or LPCHAR should be used for that parameter. Note: it's
been years since I've had to program for Windows in C, so I may not
remember everything exactly, but I think LPCHAR is what you're looking for.
Also, Win32::API probably doesn't recognize the [] because Win32::API is
not a C compiler.
int OpenAduDeviceBySerialNumber(LPCHAR psSerialNumber,ULONG
iTimeout)
---or even---
int OpenAduDeviceBySerialNumber(LPCHAR,ULONG)
Re: Help on Win32 API
am 21.06.2007 01:10:20 von jis
On Jun 20, 5:22 pm, "Mumia W."
+nos...@earthlink.net> wrote:
> On 06/20/2007 11:25 AM, jis wrote:
>
>
>
>
>
> > On Jun 20, 10:44 am, "Mumia W."
> > +nos...@earthlink.net> wrote:
> >> On 06/20/2007 08:53 AM, jis wrote:
>
> >>> Hi,
> >>> I have a dll by name AduHid.dll.
> >>> There is a function with prototype
> >>> void * _stdcall OpenAduDeviceBySerialNumber(const char*
> >>> psSerialNUmber,unsigned long iTimeout);
> >>> I used the followingperlcode to call the above function
> >>> useWin32::API;
> >>> my $function =Win32::API->new(
> >>> 'AduHid.dll','int OpenAduDeviceBySerialNumber(const
> >>> char* psSerialNUmber,unsigned long iTimeout)' );
> >>> my $return = $function->Call("A03744",0);
> >>> But i get anerror
> >>> 1. unknown parameter type const and unsigned
> >>> 2. Argument A03744 isnt numeric in subroutine entry.
> >>> I tried removing const and unsigned.Then I got anerror
> >>> "Modification of read only value attempted".
> >>> Where am i going wrong?
> >>> Please advise.
> >>> regards,
> >>> jis
> >> I don't have access to a Windows computer, but I was able to download
> >> the CPAN source forWin32::API. Read the POD forWin32::API::Types. It
> >> says you should examine the __DATA__ section ofWin32/API/Types.pm to
> >> see a list of supported types.
>
> >> You might need to specify a prototype like this:
>
> >> int OpenAduDeviceBySerialNumber(PCHAR psSerialNUmber, ULONG iTimeout)
>
> >> I hope this helps some.- Hide quoted text -
>
> >> - Show quoted text -
>
> > Thanks for the quick reply.
> > It took away errors that were there.But came up with anerror
> > "Modification of read only value attempted"
> > Only time it gave away theerrorwas when i tried
> > int OpenAduDeviceBySerialNumber(CHAR psSerialNumber[],ULONG
> > iTimeout)
> > Unfortunately this time the code crashed with "the memory could not be
> > read"
>
> > Anyway it took me a step ahead.
>
> > regards,
> > jis
>
> Try to keep the conversation in the newsgroup.
>
> "Const char*" tells me that psSerialNUmber is a pointer to characters,
> so either PCHAR or LPCHAR should be used for that parameter. Note: it's
> been years since I've had to program for Windows in C, so I may not
> remember everything exactly, but I think LPCHAR is what you're looking for.
>
> Also,Win32::APIprobably doesn't recognize the [] becauseWin32::APIis
> not a C compiler.
>
> int OpenAduDeviceBySerialNumber(LPCHAR psSerialNumber,ULONG
> iTimeout)
>
> ---or even---
>
> int OpenAduDeviceBySerialNumber(LPCHAR,ULONG)- Hide quoted text -
>
> - Show quoted text -
Thanks for the reply.
i tried like
use Win32::API;
my $function = Win32::API->new(
'AduHid.dll','OpenAduDeviceBySerialNumber',PN,N );
my $return = $function->Call("A02365",0);
print $return;
it goes without any errors.But i always get the result 1952.
I have got another function.
void * _stdcall OpenAduDevice(unsigned long iTimeout);
which i tried with the following perl function.
use strict;
use warnings;
use Win32::API;
my $function = Win32::API->new(
'AduHid.dll', 'int OpenAduDevice(ULONG iTimeout)');
$result= $function->Call(0);
print $result;
I always get the result 1952. I tried the same code in Visual
Basic ,it works fine.
Any idea what 1952 is?
Even i tried the following code
use strict;
use warnings;
use Win32::API;
my $function = Win32::API->new(
'AduHid.dll', 'OpenAduDevice',N,N);
$result= $function->Call(0);
print $result;
It still always give me 1952.
Any ideas??
regards,
jis
Re: Help on Win32 API
am 21.06.2007 02:55:52 von Sisyphus
"jis" wrote in message
news:1182381020.613445.86000@m36g2000hse.googlegroups.com...
..
..
> i tried like
>
> use Win32::API;
> my $function = Win32::API->new(
> 'AduHid.dll','OpenAduDeviceBySerialNumber',PN,N );
Going by the examples in the docs, the 'PN' and 'N' should be quoted - not
barewords as you have done.
Maybe you should also turn on warnings ?
However, in your case, I would probably be using Inline::C or XS to access
the functionality assuming you have an import lib (AduHid.lib) as well as
the dll.
Untested:
---------------------------------------------
use warnings;
use strict;
use Inline C => Config =>
BUILD_NOISY => 1,
INC =>'-IC:/path/to/AduHid_header', # if relevant
LIBS => '-LC:/path/to/import_lib -lAduHid';
use Inline C => <<'EOC';
#include // if relevant
int wrap_OpenAduDeviceBySerialNumber(char * str, unsigned long num) {
return OpenAduDeviceBySerialNumber(str, num);
}
EOC
my $ret = wrap_OpenAduDeviceBySerialNumber("A03744",0);
print $ret, "\n";
---------------------------------------------
Cheers,
Rob