Calling Activex dll's
-
- User
- Posts: 18
- Joined: Mon Nov 11, 2013 12:10 pm
Calling Activex dll's
I have a commercial program with a communications interface in the form of an ActiveX DLL. It can be called from Visual Basic 6 or Visual Basic for Applications. I am looking for a modern programming language implementation that might be able to do the same. Can PureBasic call functions from such DLLs?
Re: Calling Activex dll's
Hi jsampson45,
Yes, PureBasic can call functions in COM (ActiveX) DLLs; not directly, but with the help of srod's great COMatePlus library (http://www.purecoder.net/comate.htm).
Regards,
Eric
Yes, PureBasic can call functions in COM (ActiveX) DLLs; not directly, but with the help of srod's great COMatePlus library (http://www.purecoder.net/comate.htm).
Regards,
Eric
-
- Enthusiast
- Posts: 200
- Joined: Wed Feb 01, 2012 5:30 pm
- Location: Russian Federation
Re: Calling Activex dll's
Standard PureBasic "Interface" library, no?
Code: Select all
Interface MyObject
Move(x,y)
MoveF(x.f,y.f)
Destroy()
EndInterface
; CreateObject is the function which creates the object, from the DLL,
; whose interface has just been defined.
; Create the first object...
;
Object1.MyObject = MyCreateObject()
; And the second one.
;
Object2.MyObject = MyCreateObject()
; Then the functions which have just been defined, may
; be used, in order to act upon the desired object.
;
Object1\Move(10, 20)
Object1\Destroy()
Object2\MoveF(10.5, 20.1)
Object2\Destroy()
Former user of pirated PB.
Now registered user :].
Now registered user :].
-
- User
- Posts: 18
- Joined: Mon Nov 11, 2013 12:10 pm
Re: Calling Activex dll's
Many thanks for this. Further searches on the forum suggest that I should also ask if this is possible with the demo version of PureBasic. I cannot find a description of the limitations of the demo version vs the full version.
Re: Calling Activex dll's
Yes it can call COM dlls as I do it all the time with Visual FoxPro COM dlls. You have to correctly create the Interface by getting the information from the type library as shown below. In my case the VFP COM dll only has two methods Prepare110 and Prepare130. They both return a text string that is a response to a specific authorization request. I pass them the request string and the location of the file where the request is to be logged and they return a response string. The strange part is the hidden return value that must be specified in PB. I say hidden because the return value is not a parameter in the the VFP methods. Not being an expert in COM it must be something that happens behind the scenes that I am not aware of.
Code: Select all
Macro DEFINE_GUID(Name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Global Name.GUID
Name\Data1 = l
Name\Data2 = w1
Name\Data3 = w2
Name\Data4[0] = b1
Name\Data4[1] = b2
Name\Data4[2] = b3
Name\Data4[3] = b4
Name\Data4[4] = b5
Name\Data4[5] = b6
Name\Data4[6] = b7
Name\Data4[7] = b8
EndMacro
DEFINE_GUID(CLSID_KardAuth, $8DC6BA5D, $6861, $4F0A, $A0, $80, $7D, $ED, $CC, $97, $C1, $0F)
DEFINE_GUID(IID_KardAuth, $4C791FAF, $8649, $462D, $A9, $3A, $18, $5F, $95, $C2, $DC, $0E)
Interface KardAuth Extends IDispatch
Prepare110_115(String.p-bstr, String.p-bstr, ReturnValue.i)
Prepare130(String.p-bstr, String.p-bstr, ReturnValue.i)
EndInterface
Define *lnReturnPtr,*loVFP.KardAuth
If CoCreateInstance_(@CLSID_KardAuth, 0, #CLSCTX_INPROC_SERVER, @IID_KardAuth, @*loVFP)= #S_OK
If *loVFP\Prepare130(lcTxt, gcStartIn+#dCLogFileB, @*lnReturnPtr) = #S_OK
...do something
Endif
Endif
Last edited by swhite on Fri Nov 22, 2013 9:54 pm, edited 1 time in total.
Simon White
dCipher Computing
dCipher Computing
-
- User
- Posts: 18
- Joined: Mon Nov 11, 2013 12:10 pm
Re: Calling Activex dll's
Thanks - that pretty well shows that I could not do it - I haven't heard of any 'type library' and I am afraid I do not understand your code. From VBA in Word I can run a test program I was provided with, which I can understand.
Re: Calling Activex dll's
@jsampson45:
as ebs wrote: There is an include called COMate you can use to call ActiveX - DLL pretty similar to VBS or VBA.
Unfortunately you cannot use COMate in the PureBasic Demo Version.
Greetings ... Kiffi
as ebs wrote: There is an include called COMate you can use to call ActiveX - DLL pretty similar to VBS or VBA.
Code: Select all
ExcelObject = COMate_CreateObject("Excel.Application")
If ExcelObject
If ExcelObject\SetProperty("Visible = #True") = #S_OK
WorkBook = ExcelObject\GetObjectProperty("Workbooks\Add")
If WorkBook
ExcelObject\SetProperty("Cells(1,1) = 'Hello'")
ExcelObject\SetProperty("Cells(1,2) = 'from'")
ExcelObject\SetProperty("Cells(1,3) = 'COMate!'")
...
Greetings ... Kiffi
Hygge
-
- User
- Posts: 18
- Joined: Mon Nov 11, 2013 12:10 pm
Re: Calling Activex dll's
COMatePlus has an empty help file. I don't know who the author is and there are no contact details on the nxSoftware website. Has anyone actually used this software? I would be grateful for any lead to instructions on calling ActiveX DLL's from Purebasic that someone unfamiliar with Windows COM can understand.
Re: Calling Activex dll's
It's not true.jsampson45 wrote:COMatePlus has an empty help file.
I just downloaded the zip file from the location linked by ebs (I suppose you got it from there) and the help file is certainly not empty.
srod, as mentioned above.jsampson45 wrote: I don't know who the author is
http://www.purecoder.net/contact.phpjsampson45 wrote: and there are no contact details on the nxSoftware website.
But the site looks semi-abandoned, and probably it is. So you shouldn't count on updates of the software.
Truth is if you don't have a background in COM or the time and will to wrap your head around it and srod's code (you have the source) probably it's a risky choice.
Yes.jsampson45 wrote: Has anyone actually used this software?
http://www.purebasic.fr/english/viewtop ... 14&t=37214
http://www.purebasic.fr/english/search. ... mit=Search
"Have you tried turning it off and on again ?"
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Re: Calling Activex dll's
Sadly, I can confirm this. But nobody can kick me for hoping that will change someday. And the software he's written "pretty much just works", so if you need support on it, you can likely find it on the forums.But the site looks semi-abandoned, and probably it is. So you shouldn't count on updates of the software.
BERESHEIT
-
- User
- Posts: 18
- Joined: Mon Nov 11, 2013 12:10 pm
Re: Calling Activex dll's
My apologies - I have discovered that the COMatePlus help file was blocked, not empty. On Windows 7, help files fail silently and appear to be empty. I find that one can read them by right-clicking and selecting 'unblock' in 'properties'.
-
- User
- Posts: 18
- Joined: Mon Nov 11, 2013 12:10 pm
Re: Calling Activex dll's
Coming back to this, I am reading the example code for COMatePLus to see if I can eventually translate Visual Basic code, which I have, into PureBasic code for accessing a third-party ActiveX dll. I see "Define.COMateObject" - is COMateObject a type? The PureBasic manual seems to indicate that what follows the "."" after the term "Define" is a type. What sort of type would COMateObject be?
Re: Calling Activex dll's
From what I remember looking briefly at the source, it's an interface. In PB you can use structures (for the object's data), procedures + virtual tables (for the object's methods) and interfaces to glue them together and build an object. Object as in OOP. Not really easy stuff for beginners but highly educational
To understand how this work see the docs for interfaces in the help file -> http://www.purebasic.com/documentation/ ... faces.html, and any of the tutorials available in this forum on the subject, or the one from srod's himself on his site. Since he's the author of the lib you are using probably it's the optimal one for you to read. It's very clear and easy to follow.
http://www.purecoder.net/oop.zip

To understand how this work see the docs for interfaces in the help file -> http://www.purebasic.com/documentation/ ... faces.html, and any of the tutorials available in this forum on the subject, or the one from srod's himself on his site. Since he's the author of the lib you are using probably it's the optimal one for you to read. It's very clear and easy to follow.
http://www.purecoder.net/oop.zip
"Have you tried turning it off and on again ?"
-
- User
- Posts: 18
- Joined: Mon Nov 11, 2013 12:10 pm
Re: Calling Activex dll's
My guess that "oWScript\Invoke(x)" is equivalent to Visual Basic's "Call .x" appears to be correct in that I can get one of the commands exposed by the DLL to work. But only one command - the others do not work. So there seems to be a partial connection. I expect for non-experts it is best to stick to Visual Basic.
Re: Calling Activex dll's
You can use the PureBasic "TypeLib Explorer.exe" to create all the code necessary to access an ActiveX dll then it is just a matter of using the methods. I spent some time reading the Windows documentation about COM which helped me understand the basic ideas and then created the example I gave earlier. It all works quite well in Purebasic but it does require some research to understand what is happening under the hood. I came from a VFP background so it was all new to me when I started but I use it all the time now.
Simon
Simon
Simon White
dCipher Computing
dCipher Computing