Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DLL Call Follies

Reply
Thread Tools

DLL Call Follies

 
 
Kythe
Guest
Posts: n/a
 
      09-10-2006
Hello,
My apologies if this is a rather basic question, but I've been beating
my head against the wall trying to get Win32::API interfacing to a dll
working, and I've never done this before.

The dll in question is proprietary; however, it's 32 bit, it requires a
32,000-byte memory space, and returns values via parameters, not just
via return values.

Here's the documentation in question:

"The calling program must provide a workspace for mydll.dll. mydll will
do most of its processing & storing of data in this workspace.
Currently, the work space must be at least 32k bytes (bigger won't
help). Visual Basic programs must provide this via the Windows memory
allocation API. 'C' or Pascal programs may provide a pointer to a
memory area. Mydll creates pointers within the work space, so if the
memory is relocated, the work space must be re-initialized. This can
happen with any call, and is signaled by an error return on the call.
Error codes are listed in the "Return Error Codes" section of this
document."

Here's the provided calling procedure for Delphi/Pascal:

Procedure InitializeDataBaseDbSrvr( DatabasePath_Ptr, Password_Pchar:
Pchar; WorkSpace_Ptr: Pointer; WorkSpaceSize_Wrd: Word; Var
SizeUsed_Wrd: Word; Var ErrorReturn: SmallInt );

And here's the PERL code as it stands now:

#!c:\perl\bin\perl.exe
$password = 'xxxxxxxx';
$cwd = 'C:\\Program Files\\MyDllWorkingDirectory\\';
$err_return = 0;
$buffersize = 32000;

use Win32::API;
Win32::API::Struct->typedef('BUFFER', qw(BYTE Buffer[32000])) or die
"$!\n";
my $buff = Win32::API::Struct->new('BUFFER');

$initialize = new
Win32::API("mydll.dll","InitializeDataBaseDbSrvr", "CCSNP","V");
$initialize->Call($cwd,$password,$buff,$buffersize,$err_return );

print "$err_return\n";

Right now, Perl is throwing an error dialog "Perl Command Line
Interpreter has encountered a problem and needs to close. We are sorry
for the inconvenience."

I'm kind of tapped out on this right now. Like I said, I haven't used
PERL to import dll functions before, and I'm at wall when it comes to
the documentation and sample scripts.

Any help would be most appreciated!

 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      09-10-2006
"Kythe" <(E-Mail Removed)> wrote:

> 32,000-byte memory space, and returns values via parameters, not just
> via return values.
>
> Here's the documentation in question:
>
> "The calling program must provide a workspace for mydll.dll. mydll will
> do most of its processing & storing of data in this workspace.
> Currently, the work space must be at least 32k bytes (bigger won't


32K is probably 32,768 bytes (2^15), not 32,000

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
 
 
 
Kythe
Guest
Posts: n/a
 
      09-11-2006

John Bokma wrote:
> "Kythe" <(E-Mail Removed)> wrote:
>
> > 32,000-byte memory space, and returns values via parameters, not just
> > via return values.
> >
> > Here's the documentation in question:
> >
> > "The calling program must provide a workspace for mydll.dll. mydll will
> > do most of its processing & storing of data in this workspace.
> > Currently, the work space must be at least 32k bytes (bigger won't

>
> 32K is probably 32,768 bytes (2^15), not 32,000
>
> --
> John Experienced Perl programmer: http://castleamber.com/
>
> Perl help, tutorials, and examples: http://johnbokma.com/perl/


Very true. In the sample code they provide for allocating memory using
the kernel32 function GlobalAlloc, however, they use the nice, round
32,000 bytes. I figured it was probably close enough

Even so, using 32,768 doesn't change the outcome.

 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      09-11-2006
"Kythe" <(E-Mail Removed)> wrote:

>
> John Bokma wrote:
>> "Kythe" <(E-Mail Removed)> wrote:
>>
>> > 32,000-byte memory space, and returns values via parameters, not
>> > just via return values.
>> >
>> > Here's the documentation in question:
>> >
>> > "The calling program must provide a workspace for mydll.dll. mydll
>> > will do most of its processing & storing of data in this workspace.
>> > Currently, the work space must be at least 32k bytes (bigger won't

>>
>> 32K is probably 32,768 bytes (2^15), not 32,000
>>
>> --
>> John Experienced Perl programmer:
>> http://castleamber.com/
>>
>> Perl help, tutorials, and examples:
>> http://johnbokma.com/perl/

>
> Very true. In the sample code they provide for allocating memory
> using the kernel32 function GlobalAlloc, however, they use the nice,
> round 32,000 bytes. I figured it was probably close enough
>
> Even so, using 32,768 doesn't change the outcome.


Ok, I was guessing that not enough memory caused the behavior you saw but
was not sure

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
Kythe
Guest
Posts: n/a
 
      09-11-2006
Any ideas? Even sources references to further information would be
helpful!

 
Reply With Quote
 
Sisyphus
Guest
Posts: n/a
 
      09-11-2006

"Kythe" <(E-Mail Removed)> wrote in message
..
..
>
> And here's the PERL code as it stands now:
>
> #!c:\perl\bin\perl.exe
> $password = 'xxxxxxxx';
> $cwd = 'C:\\Program Files\\MyDllWorkingDirectory\\';
> $err_return = 0;
> $buffersize = 32000;
>
> use Win32::API;
> Win32::API::Struct->typedef('BUFFER', qw(BYTE Buffer[32000])) or die
> "$!\n";
> my $buff = Win32::API::Struct->new('BUFFER');
>
> $initialize = new
> Win32::API("mydll.dll","InitializeDataBaseDbSrvr", "CCSNP","V");
> $initialize->Call($cwd,$password,$buff,$buffersize,$err_return );
>
> print "$err_return\n";
>


You should determine just which line of code is producing the error you
reported. Is it the initial assignment to $buff, the initial assignment to
$initialize, or the '$initialize->Call()' that's causing the error.

I could be miles off ... but what happens if you rewrite that as:

#!c:\perl\bin\perl.exe
$password = 'xxxxxxxx';
$cwd = 'C:\\Program Files\\MyDllWorkingDirectory\\';
$err_return = 0;
$buffersize = 32768;
use Win32::API;

my $buff = " " x $buffersize;

$initialize = new
Win32::API("mydll.dll","InitializeDataBaseDbSrvr", "PPPNN","V"); # or maybe
"PPPNP" as 3rd arg
if (not defined $initialize)
{die "Failed to import InitializeDataBaseDbSrvr"}
$initialize->Call($cwd,$password,$buff,$buffersize,$err_return );

print "$err_return\n";

Are you sure that InitializeDataBaseDbSrvr() does not return a value ?

There are some people here who are quite good with Win32::API (though I'm
not one of them). Be patient and you'll probably get a solution.

Cheers,
Rob


 
Reply With Quote
 
Kythe
Guest
Posts: n/a
 
      09-11-2006
Thanks, Rob.

I think I may have found the trouble -- I may have stupidly omitted an
input argument to the function At the very least, it looks like
one's missing, and that can't be good.

Figures.

It also sucks that I can't post more details about the dll, but it's a
proprietary, third-party library.

Part of my problem is I've never used Win32::API before, and am not
certain that I'm not making basic, foolish mistakes. But as you said,
I need to spend more time with trial and error on this.

Sisyphus wrote:
> "Kythe" <(E-Mail Removed)> wrote in message
> .
> .
> >
> > And here's the PERL code as it stands now:
> >
> > #!c:\perl\bin\perl.exe
> > $password = 'xxxxxxxx';
> > $cwd = 'C:\\Program Files\\MyDllWorkingDirectory\\';
> > $err_return = 0;
> > $buffersize = 32000;
> >
> > use Win32::API;
> > Win32::API::Struct->typedef('BUFFER', qw(BYTE Buffer[32000])) or die
> > "$!\n";
> > my $buff = Win32::API::Struct->new('BUFFER');
> >
> > $initialize = new
> > Win32::API("mydll.dll","InitializeDataBaseDbSrvr", "CCSNP","V");
> > $initialize->Call($cwd,$password,$buff,$buffersize,$err_return );
> >
> > print "$err_return\n";
> >

>
> You should determine just which line of code is producing the error you
> reported. Is it the initial assignment to $buff, the initial assignment to
> $initialize, or the '$initialize->Call()' that's causing the error.
>
> I could be miles off ... but what happens if you rewrite that as:
>
> #!c:\perl\bin\perl.exe
> $password = 'xxxxxxxx';
> $cwd = 'C:\\Program Files\\MyDllWorkingDirectory\\';
> $err_return = 0;
> $buffersize = 32768;
> use Win32::API;
>
> my $buff = " " x $buffersize;
>
> $initialize = new
> Win32::API("mydll.dll","InitializeDataBaseDbSrvr", "PPPNN","V"); # or maybe
> "PPPNP" as 3rd arg
> if (not defined $initialize)
> {die "Failed to import InitializeDataBaseDbSrvr"}
> $initialize->Call($cwd,$password,$buff,$buffersize,$err_return );
>
> print "$err_return\n";
>
> Are you sure that InitializeDataBaseDbSrvr() does not return a value ?
>
> There are some people here who are quite good with Win32::API (though I'm
> not one of them). Be patient and you'll probably get a solution.
>
> Cheers,
> Rob


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: NYC train & bus follies PluckThePig=^||^ Computer Support 0 06-24-2010 04:05 AM
DOS Follies (Was: Docstrings...) D'Arcy J.M. Cain Python 1 03-04-2010 02:50 AM
Closed-source software follies Lawrence D'Oliveiro NZ Computing 10 01-30-2007 11:53 AM
DVD Verdict reviews: ALL I WANT FOR CHRISTMAS, CARTOON NETWORK CHRISTMAS: YULETIDE FOLLIES, and more! DVD Verdict DVD Video 0 12-10-2004 10:10 AM
"titicut follies" Vlvetmorning98 DVD Video 6 02-29-2004 09:13 PM



Advertisments