Reviews by Richard Shomin

cpanratings
 

RSS

Win32-API (0.46) ****

This works well, but there is an upgrade that handles "cdecl"
calling convention, This one only handles the "stdcall" similar
to the pascal calling convention .
Expect a crash(stack overflow exception) if you call a dll that uses

__cdecl calling convention such as the functions inside msvcrt.dll
, msvcr71.dll or msvcp71.dll.

Without using __cdecl ,
your stack pointer will not be balanced after the call. You still
have to pop (or add esp, ???) the arguments you passed off the stack.
Many of the Microsoft dll's like kernel32.dll,user32.dll use the __stdcall calling convention. The C libraries use the C calling convention.
Also the upgrade will compile under vstudio.net 2003 see:
www.xs4all.nl/~itsme/projects/perl/ by Willem Jan Hengeveld
There is an extra option after the return type parameter for your
calling convention in your prototype '__stdcall' or '_cdecl',
the default is '__stdcall' .
I might develop another optional parameter that tests the stack
pointer before and after the call to print an error message if
the stack isn't balanced.

Richard Shomin - 2007-01-18T09:56:59 (permalink)

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

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