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

Discussion in 'Perl Misc' started by jc, Apr 18, 2009.

  1. jc

    jc Guest

    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(
    '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....
    jc, Apr 18, 2009
    1. Advertisements

  2. sisyphus

    sisyphus Guest

    On Apr 18, 2:48 pm, Ben Morrow <> wrote:
    > Quoth jc <>:

    > > 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.

    sisyphus, Apr 18, 2009
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. pcarr01
    Gordon Beaton
    Feb 17, 2005
  2. H. Simpson
    H. Simpson
    Aug 3, 2004
  3. Replies:
    Oct 25, 2007
  4. Thomas Thomassen
    Thomas Thomassen
    Dec 29, 2010
  5. cyl

    Win32::API cannot load any DLL?

    cyl, Apr 11, 2007, in forum: Perl Misc
    Apr 14, 2007

Share This Page