With the introduction of interfaces in PureBasic, accessing external COM (Component Object Model) objects
has become fairly simple (in terms of needed amounts code to do so). However, creating COM objects in PB
to be used externally, or with API commands is still something that requires lots of knowledge about PB and
COM and quite some work to do. This framework tries to change that. It provides a set of macros to easily define
an object and also to automate most of the tasks common to all object implementations (like implementing the
IUnknown interface). Additionally, it provides extensive debugging functionality to track down bugs in your
implementation. There are also some macros that are useful for general COM development.
- No preprocessing needed. Evetything is pure PB code.
- Everything contained in residents and includefiles, minimizing possible problems with future PB versions
- Threadsafe and unicode ready
- Works with the EnableExplicit compiler option
- Simple macros to define the class structure
- Multiple interfaces supported in one class (up to 9)
- Implementation of IUnknown is completly done by the framework
- Constructor/Destructor support
- For not-implemented methods, a default method is automatically inserted which returns #E_NOTIMPL
- A VTable is created with a single macro call
- Macros for easy definition and handling of GUID values (IID, CLSID, ...)
- Complete tracking of all calls to the objects methods, including displaying return values
- Tracking of calls to dead (allready freed) objects
- Catching of method calls outside the VTable (to find calls to wrong interfaces)
- The amout of debug output for the tracking can be customized with 'DebugLevel'
- Conversion of GUID and HRESULT values to text for easier debugging
- With Debugger off, the debug output is printed with OutputDebugString_() for easy dll debugging
This framework is intended for those that have allready some understanding
of how COM works, but want to make their life easier when it comes
to creating objects with PB.
NOTE: The purpose of this framework is to implement interfaces that are defined in the Microsoft Component
Object Model. The intend is not to provide general OOP functionality for PureBasic. To automate most
of the work, the framework needs information on the given interfaces, this is why only predefined interfaces
can be implemented, not any custom one. (currently 855 interfaces are known to the framework)
I started this project to ease my own work with COM in PureBasic, and
also als a challange to see how far i could go with the PB4 macro capabilities.
As this shows, there is quite a lot that can be done with it. It also prooves
that you can produce totally ugly code with them.
(have a look at the main includefiles and you will see. Better don't try to understand
how all of it works
As an Example, implementing a basic IBindStatusCallback interface to be used
with UrlDownloadToFile_() can be as simple as this:
Procedure StatusObject_IBindStatusCallback_OnProgress(*THIS.StatusObject, Progress.l, ProgressMax.l, StatusCode.l, szStatusText.l) COMMethodOf(StatusObject)
If ProgressMax = 0
percent.f = 0
percent.f = (Progress*100)/ProgressMax
Debug Str(Progress)+"/"+Str(ProgressMax)+" ("+StrF(percent, 1)+"%)"
RemoteName$ = InputRequester("File Download:", "Enter remote FileName: ", "http://www.purebasic.com/")
If RemoteName$ = "": End: EndIf
LocalName$ = SaveFileRequester("Select Local Filename:", "C:\temp.html", "All Files|*.*", 1)
If LocalName$ = "": End: EndIf
BindStatus.IBindStatusCallback = New_StatusObject()
Debug "Starting download..."
If URLDownloadToFile_(0, @RemoteName$, @LocalName$, 0, BindStatus) = #S_OK
Debug "Download successful."
Debug "Download failed."
Here is the download link. Make sure you have a look in the Readme file on how it all works.
There are also some example codes included.
To install it, just extract the archive directly into the purebasic folder.
(it adds a 'ComFramework' subfolder and 2 resident files, nothing more)
I'll be glad to hear any comments or bugreports.