Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Module Win32::API and DLL with Windows Visual C++

Thread Tools

Module Win32::API and DLL with Windows Visual C++

Posts: n/a
I am having trouble getting my own DLLs to work with the above module
(ver 0.55).
I can get the examples to work from the write up that involve the DLLs
from kernal32,
but not from my own little DLL project file.

I fear I need a simple example DLL project for MS Visual C++ 6 that
does work.
Can anyone help here?

The current fault I have is;
"Can't call method "Call" on an undefined value at
line 44."

With the following lines of PERL code:
use Win32::API;
$function = Win32::API->new(
'C:\\User_JC\\Perl\\Module_Win32\\DLL\\test\\Debug \\test.dll',
'int ANSIchar(int a, int b)'
$return = $function->Call( 1, 2 ) ; # This is line 44

I have change this around but $function is always undefined.
I am not sure if Win32::API is the appropriate tool for accessing user
DLLs. ??

Regards JC....
Reply With Quote
Posts: n/a
On Apr 18, 2:48*pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth jc <(E-Mail Removed)>:

> > I am not sure if Win32::API is the appropriate tool for accessing user
> > DLLs. ??

> Well, there are several alternatives. The most long-winded and most
> likely to work successfully is to write a proper XS module that wraps
> the DLL. If you find XS too complicated, you could use Inline::C to do
> the grunt-work for you, though IME it brings its own list of
> complications I prefer to do without.

For mine, Win32::API is *not* the ideal way to access user DLLs
1) you don't have a C compiler
2) your C compiler cannot link to DLLs directly (ie needs to link to
an import lib) and you don't have an import library for that DLL.

With Strawberry Perl, neither 1) nor 2) will be the case (as
Strawberry Perl comes with the MinGW port of the gcc compiler - which
is a C compiler that can link directly to a DLL if need be).
With ActiveState Perl neither 1) nor 2) will be the case if you first
'ppm install MinGW'.

Ben's advice is, as always, sound. But don't let his recommendations
deter you from using Inline::C which is a powerful and flexible tool
that allows you to take the XS solution without having to learn how to
write an XS file. (You may need to become familiar with the perl API,
however - 'perldoc perlapi'.)

And feel free to use Inline::C with windows system DLLs too:

use Inline C => DATA =>
MYEXTLIB => 'C:/windows/system32/user32.dll';

$text = "@ARGV" || ' works with MSWin32. Scary...';

WinBox('Inline Text Box', $text);


int WinBox(char* Caption, char* Text) {
return MessageBoxA(0, Text, Caption, 0);

That's based on an example in the Inline::C-Cookbook documentation -
it links directly to user32.dll. To use that script with a Microsoft
Compiler you'd have to replace:

MYEXTLIB => 'C:/windows/system32/user32.dll';
LIBS => '-luser32';

With MinGW, both of those 2 variations work (assuming user32.dll is in
C:/windows/system32, of course).

Once your Inline::C solution has been written you can always convert
to XS (and avoid the dependency upon Inline) using
<plug>InlineX::C2XS</plug>, again without having to go to the trouble
of writing the XS file yourself.


Reply With Quote

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
How to call Visual C dll and .Net dll at clientside? Tom ASP .Net 1 09-14-2008 01:49 PM
How to determine if a DLL is a COM DLL or .NET DLL Anushi ASP .Net 5 10-28-2004 01:59 PM
Why does Ruby use both tcl83.dll and tk83.dll (instead of just tk83.dll)? H. Simpson Ruby 4 08-03-2004 04:45 PM
mprapi.dll --> samlib.dll --> ntdll.dll issue. Some1 Computer Support 4 04-05-2004 02:02 AM
msvcrt.dll, msvcirt.dll, msvcrt20.dll and msvcrt40.dll, explanation please! Snoopy NZ Computing 16 08-25-2003 12:34 PM