C-DynaLib reviews

cpanratings
 

RSS | Module Info | Add a review of C-DynaLib

C-DynaLib (0.55) *****

I got this module to work under Win32 (XP) with msvc 7.0 , Perl5.8 .
I had to tweek Makefile.pl for Win32 specifics. Added a Peek()
routine to Dynalib.xs and got all the tests to run successfully ,even
the Win32 GUI test in the distribution !!!!
I might contact the author, about the changes , after I get it running to my satisfaction - there are things to iron out.
I will add one more test script - calling an inline assembly
language routine - this on simply returns a value to the caller.

###### asmcalltest.pl ##########
###### tested on Win32 x86 machine
use C::DynaLib ();

sub DeclareSub { &C::DynaLib::DeclareSub }
sub PTR_TYPE { &C::DynaLib::PTR_TYPE }

$asm = "\x90\xb8\x05\x00\x00\x00\xc3\x90\x90";
# 90 nop - replace with cc for debugger
# b805000000 mov eax, 5 # RETURN VALUE of 5
# c3 ret cdecl call return - caller adjust stack
# 90 90 (2)nop 2 nops for room(stdcall stack adjsut)

$asmptr = unpack(PTR_TYPE, pack("P", $asm)); # get pointer to routine
$AsmFunc = DeclareSub($asmptr , "i"); # define sub(returns int)
$ret = &$AsmFunc(); # call asm routine
print '&$AsmFunc() returned: ',$ret,"\n";
##### END OF CODE ######

And it prints 5 as expected.

I am having fun with tweeking this anyway....

Here are some things I did to get it to work:

Find and Edit the 2 lines in DynaLib.pm to read :
# inline-able constants?
sub DYNALIB_DEFAULT_CONV(){hack30};
sub PTR_TYPE(){i};

Then run:
c:\temp> perl Makefile.pl DECL=hack30
c:\temp> nmake test

My other noted changes:

Minor edits in test.pl

DynaLib.pm: added Microsoft's legacy dll search order (allows

msvcrt.dll to be loaded in test.pl)

DynaLib.xs: added Peek() routine - now have both Poke and Peek,

two very useful memory routines for use in Perl.

Makefile.pl: added $^O test for Win32 for redirection (> NUL:)

along with UNIX (>/dev/null)

asmcalltest.pl - call simple assembly language routine.

IDEAS: Try and make it fully compile with MSVC++ compiler with cdecl

calling convention instaed of hack30.

Add the stdcall or pascal calling convention. Since this

already calls assembly routines the

"nakedcall" could be considered - you write your own

prologue/epilog code.

Richard Shomin - 2007-01-16T14:14:19 (permalink)

2 out of 5 found this review helpful. Was this review helpful to you?  Yes No

C-DynaLib (0.55) ***

This isn't a review, so much as a cross reference for C::DynaLib::Struct.

Win32::API::Struct seems to be under more active development, but is of course platform specific.
Convert::Binary::C (actively developed as of 2004) and C::Include allow structs to be defined using C source.

mitchellncharity - 2004-02-01T23:01:28 (permalink)

Was this review helpful to you?  Yes No