skywalker has asked for the wisdom of the Perl Monks concerning the following question:
Hi I have a C++ compiled dll that is a licenced product, as a result I can not get at the source code, can I use win32::API or win32::OLE to access the object, the dll is an 'Active X COM DLL'.
I have a supplied VB example, can I port this to perl??
#VB code example
DataToEncode = InputString.Text
Dim DMFontEncoder As DMATRIXLib.Datamatrix
Set DMFontEncoder = New Datamatrix
DMFontEncoder.FontEncode DataToEncode, 0, 0, 0, Printable_string
PrintableBarcodeString = Printable_string
I have tried the API and OLE, but can not get either to function without errors
API perl Code
use Win32::API;
my $DataToEncode = "Test1 Test2 Test3";
use Win32::API;
$function = Win32::API->new(
'IDAutomationDMATRIX6.DLL', 'FontEncode',
);
$function->Call($DataToEncode);
Dan
Re: dll calling problems
by SankoR (Prior) on Jun 18, 2008 at 13:42 UTC
|
Don't forget Win32::API needs a list of your dll's expected parameters and return type. | [reply] |
Re: dll calling problems
by syphilis (Archbishop) on Jun 18, 2008 at 14:13 UTC
|
$function = Win32::API->new(
'IDAutomationDMATRIX6.DLL', 'FontEncode', 'P', 'V'
);
You can probably use Win32::API ... but you do need to know what types of arguments the functions take, and what types of values (if any) are returned. Normally, this information would be retrieved from a header file and/or documentation. Do you have either/both ?
Cheers, Rob | [reply] [d/l] [select] |
|
Ok, the software is a 2d barcode (data matrix) encoder created by IDAutomation. http://www.idautomation.com/datamatrixfaq.html
the paramaters that the routine expects are DataToEncode, ProcessTilde, EncodingMode, PreferredFormat, Result
it should also then return an encoded string that can then be used to generate a 2d barcode font.
Thanks
Dan
| [reply] [d/l] [select] |
|
Hi Ive been in touch with the vendor, and they confirm that both the dll and the function are correct,the paramaters are
string,numeric,numeric,numeric,string
so my amended code now looks like this, however I still get the same error ('Cant call method "Call" on an undefined value at line 12'), am I doing some thing wrong, or should I just learn VB so I can use the vendor example...
use Win32::API;
my $DataToEncode = "Test1 Test2 Test3";
my $return_sring = undef;
use Win32::API;
$function = Win32::API->new(
'IDAutomationDMATRIX6', 'FontEncode',['P','N','N','N','P']
);
my $string = $function->Call('FontEncode');
Thanks
| [reply] [d/l] |
|
use Win32::API;
my $DataToEncode = "Test1 Test2 Test3";
my $return_sring = undef;
use Win32::API;
$function = Win32::API->new(
'IDAutomationDMATRIX6', 'FontEncode',['P','N','N','N','P']
);
my $string = $function->Call('FontEncode');
There are still some inconsistencies in the above code - and these inconsistencies may be preventing the thing from working (there might also be Win32::API bugs that mean it's never gunna work anyway).
I think you still need to specify the return type in new:
$function = Win32::API->new(
'IDAutomationDMATRIX6', 'FontEncode',['P','N','N','N','P'], 'P'
);
You could also try the 2 following renditions:
$function = Win32::API->new(
'IDAutomationDMATRIX6', 'FontEncode',['P','N','N','N','P'], 'P',
+ '_cdecl'
);
and
$function = Win32::API->new(
'IDAutomationDMATRIX6', 'FontEncode',['P','N','N','N','P'], 'P',
+ '__stdcall'
);
Since FontEncode takes 5 arguments, Call() also needs to be given 5 arguments - a string, an int, an int, an int, and a string (in that order):
my $string = $function->Call($str1, $n1, $n2, $n3, $str2);
Finally, $string may need to be large enough to accommodate the return string:
my $string = '' x 500; # Big enough ?
$string = $function->Call($str1, $n1, $n2, $n3, $str2);
Without access to the dll it's hard to provide good assistance. If you can't get anywhere with it using Win32::API, then VB might be your best approach.
XS/Inline::C would also be options - and they provide excellent milage. I far prefer Inline::C over Win32::API, any day. However, for that to be an option, you also need the relevant header (.h) file and import lib (.lib) - as well as a Microsoft C compiler. (Actually, MinGW usually works fine, too - and doesn't even need the import lib. But I don't think you can use MinGW where COM is involved.)
Cheers, Rob | [reply] [d/l] [select] |
Re: dll calling problems
by swampyankee (Parson) on Jun 18, 2008 at 13:42 UTC
|
Well, if you've got VB, it may be worthwhile to check to see if the sample code actually works. It's not unheard of for vendor-supplied sample code to be slightly buggy.
It would also be beneficial to tell the monks what the proprietary product is; one of the monks may have dealt with it, or be currently trying to use it. Heck, it's not impossible one of the monks wrote the dll.
Also, The Nameless One is correct, in that the error messages may contain useful information, so show them to us, too.
Generally, the more relevant information you supply, the more likely it is you'll get a useful answer.
Information about American English usage here and here. Floating point issues? Please read this before posting. — emc
| [reply] |
Re: dll calling problems
by Anonymous Monk on Jun 18, 2008 at 13:10 UTC
|
Errors are good, start with those | [reply] |
|
The error I get is Win32::API::parse_prototype: bad prototype 'FontEncode' cant call method new on undefined value
As I cant 'see' the function name I am guessing from the VB example, however I am not sure if this is even possible.
| [reply] [d/l] |
|
|