It does not work me. I can compile the dll correctly but Win32::API
just failed to load it. I've decided to try SWIG as my solution. Many
thanks for the help. IMO, there should be room for the implementation
of this dll loading stuff because I can use other script language such
as Ruby to load my dll without any problem. Just wondering if there's
any difficulty for Perl to support such capability (loading cdecl
declared function)?
I hope you tried to run the script as 'perl msdll.pl' not 'perl msdll.dll'
(as I wrote
I don't know why you're having trouble with the formulation I provided - it
should work fine.
Is the dll in the the path ? (I think it needs to be - unless you provide
the fully qualified name.)
Did you build the dll using VC 6 ? (Safest to use the compiler that was used
to build perl - which is VC 6 , if you're using ActiveState perl.) I find
that I get failures, too, if I try to mix compilers (VC 6 and VC 7 in my
case).
Do you get any warnings or error messages with any of the failures ?
Perl has absolutely no difficulty with loading dll's (irrespective of the
calling convention used) - it's only the CPAN version of Win32::API that has
trouble with cdecl.
As an alternative to accessing the demo dll (that I provided with my last
post) using Win32::API, it's quite trivial to access that dll function
using Inline::C:
--inline.pl--
use warnings;
use Inline C => Config =>
BUILD_NOISY => 1,
LIBS => '-LC:/path/to/import_lib -lmsdll'; # link to the import lib
(msdll.lib)
use Inline C => <<'EOC';
int wrap_dll(int x) {
return dll_int_square(c);
}
EOC
my $num = 12;
print wrap_dll($num);
-- end Inline.pl --
That will work just as well, even if the dll was not built using stdcall.
(Again, you may strike trouble if you mix compilers.)
Or you can achieve the same using XS directly.
Or you can use swig
Cheers,
Rob