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.
Feature list
Code: Select all
General
- 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
Object implementation
- 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, ...)
Debugging
- 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
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:
Code: Select all
COMClass(StatusObject)
COMInterface(StatusObject, IBindStatusCallback)
COMConstructor(StatusObject)
COMConstructorReturn IBindStatusCallback
EndCOMConstructor
EndCOMClass(StatusObject, IBindStatusCallback)
Procedure StatusObject_IBindStatusCallback_OnProgress(*THIS.StatusObject, Progress.l, ProgressMax.l, StatusCode.l, szStatusText.l) COMMethodOf(StatusObject)
Protected percent.f
If ProgressMax = 0
percent.f = 0
Else
percent.f = (Progress*100)/ProgressMax
EndIf
Debug Str(Progress)+"/"+Str(ProgressMax)+" ("+StrF(percent, 1)+"%)"
ProcedureReturn #S_OK
EndProcedure
BuildCOMVTable_IBindStatusCallback(StatusObject)
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."
Else
Debug "Download failed."
EndIf
BindStatus\Release()
End
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)
http://freak.purearea.net/tools/ComFramework.zip
I'll be glad to hear any comments or bugreports.