PDA

View Full Version : calling activex dll



zak
06-12-2008, 11:53
hi
due to the limitation of vbscript described in:
http://www.regular-expressions.info/vbscript.html
i want to call perl regular expressions from within thinbasic
i have a vb6 small program to call a perl script so to provide the matches positions(match start, match end) of a pattern globally through a string. the perl script is converted to an activex dll by the activestate perl development kit PDK
please how i can call this activex dll from thinbasic?
i enclosed the vb6 program together with patternposition.dll and the small perl script "template.pl"
the vb6 code is:

Private Sub Command1_Click()
sentence$ = Text1.Text
ptrn$ = Text2.Text
Dim objpattern
Dim chk
Set objpattern = CreateObject("patternposition.Library")
Rem calling the procedure ptrnois within the patternposition.dll
chk = objpattern.ptrnpos(sentence$, ptrn$)

Text3.Text = Text3.Text & chk & vbCrLf

Set objpattern = Nothing
End Sub

i wish vbscript may be replaced in the future by may be the pcre library which are compatible with perl
here is a compiled dll for pcre but i can't manage to use it.
http://gnuwin32.sourceforge.net/packages/pcre.htm
also the activestate dev kit is a commercial one, while the pcre is free.
the returned position from the patternposition.dll in the example is 3,4,20,24,27,28 ie the positions of the first match is 3,4 the second is 20,24...
for a string "to be or not aboze sbxxyer be"
and a pattern: (?<!a)b.*?e
thanks
the vb6 source and the activex dll together with perl source
note that we need to register the DLL by regsvr32
http://ifile.it/glh0ira/vb_perl_regex.rar

Petr Schreiber
06-12-2008, 12:28
Hi Zak,

and welcome!
Regarding ActiveX - I don't want to give you false hope, but I think this could be manageable via COM module.


Petr

P.S. Could you attach that file to this post? It seems the link you provided need some sort of registration. Once I have the file I can check whether COM module is the way to go for this task.

zak
06-12-2008, 13:50
sorry, i have not noticed the advanced options
i have attached the file

zak
06-12-2008, 14:45
yes it may be manageable by a com module
here is my unsuccessfull code , because i don't know where should i insert the pattern string,

COM_Execute(theclass, "ptrnpos", %TB_DISPATCH_METHOD, 2, vParam,pattern, vResult)
is this legitimate?
i must supply two strings to the dll, if it is not possible i can supply the two strings as a one string then i must modify the dll to extract the two strings from the one string.


uses "COM"

dim theclass as dword
dim RetVal as long
dim vParam as variant
dim vResult as variant
dim pattern as variant
theclass = COM_CreateObject("patternposition.Library",RetVal)

vParam = "to be or not aboze sbxxyer be"
pattern = "(?<!a)b.*?e"
IF COM_Succeeded(RetVal) THEN

COM_Execute(theclass, "ptrnpos", %TB_DISPATCH_METHOD, 2, vParam,pattern, vResult)
msgbox 0, vResult
end if


COM_Release(theclass)

Petr Schreiber
06-12-2008, 15:57
Hi Zak,

here is my progress. I used COM_CallMethod to call ptrnpos and got back comma delimited serie of numbers. Is that what it should do?

Here is the code:


uses "com", "console"

dim objpattern as dword
dim RetVal as long
dim vResult as variant

' -- Create instance of class
objpattern = COM_CreateObject("patternposition.Library", RetVal)
printl "objpattern", objpattern

printl repeat$(79, "-")

' -- Put parameters for method to array of variants
%MAX_NUMBER_OF_PARAMETERS = 2
dim datain(%MAX_NUMBER_OF_PARAMETERS) as variant
datain(1) = "to be or not aboze sbxxyer be"
datain(2) = "(?<!a)b.*?e"
printl "Pattern:", datain(1)
printl "Sentence:", datain(2)

IF COM_Succeeded(RetVal) THEN
printl "Object creation succeeded"

print "Calling method..."
printl IIF$(COM_Succeeded(COM_CallMethod(objpattern, "ptrnpos", %MAX_NUMBER_OF_PARAMETERS, datain(1), vResult )), "Success", "Failure")
printl repeat$(79, "-")
printl "Pattern:", datain(1)
printl "Sentence:", datain(2)
printl "Result:", vResult

else
printl "Com failed, oh no... did you registered the DLL?"

end if

printl repeat$(79, "-")
COM_Release(objpattern)
waitkey


It returns the same as under PowerBASIC, I could not run your VisualBasic code as it fails to create object.
Let me know.

Petr

zak
06-12-2008, 16:28
yes, it is succeeded wonderfully, and gives the same results as
vb6 code
thank you very much
regards

ErosOlmi
06-12-2008, 16:52
@Petr
thanks for your support. You always come out with a solution. You are my angel ;D

@zak
welcome to thinBasic.
COM module can do some nice good job with ActiveX components.
Anyhow consider this area (COM interfaces) is an area we will work a lot in new year development so expect for the future great things on COM interfaces. I'm confidend while I say this because the compiler we use to develop thinBasic (PowerBasic) as done a great jump in this direction in its latest version so I'm sure we will be able to take advance of it.

Ciao
Eros

Petr Schreiber
06-12-2008, 16:56
I am happy it worked :)