Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

VB6 Regfree Handling of AX-Plugin-Dlls per DirectCOM

$
0
0
One necessity, to make the handling of VB6-produced ActiveX-Dlls more easy,
is the regfree loading of the Classes which are contained in the Plugin-Dlls.

Once that is out of the way (we use DirectCOM.dll for that task), another
problem comes to mind, which needs to be addressed:
How to "force" the potentially "foreign" contributors to the plugin-system,
to conform to a certain set of "rules" (with regards to the functions and
their signatures - type- and parameter-wise).

One way to do that would be "by convention which is documented somewhere".
Another (more strict - and more selfexplaining) way is, to define an interface
(or a set of interfaces, as used in this Demo) in a TypeLib, and force plugin-
authors to adhere to the "contract" which is given over those COM-Interfaces.

In VB6 this is quite easy - since we can just use:
Implements ISomeInterface
... then drop down the appropriate Methods we have to implement from the
VB6-IDEs ComboBoxes (Interface-methods are reachable quite similar to Event-
handler-Methods because they are available over the very same IDE-ComboBoxes,
but in case of an Interface we cannot choose to leave such a Method out -
we have to bring them all as code into the appropriate Module - and then
"fill them out" with our own implementations).

That said, the creation of such an interface might be considered "boring stuff"
(maybe because it really is ;)) - but it's a task which (when finished and well-done) -
kind of repays for the initial trouble... (implementing existing interfaces is a bit more fun,
because this can be done pretty fast usually, since "the structure is already a given" -
and the "fill-out" quite easy in most cases.

Maybe a nice TypeLib-Editor might help in this regard - I'm using the one from
Matt-Curland for my stuff (as e.g. for the 'PluginInterfaces.tlb', which is contained in the Demo).

The Demo comes with a Main-Application, which shows the Management of the Plugin-Dlls -
and is codewise quite lean - here's the complete Form-Code:
Code:

Option Explicit

Private Declare Function LoadLibraryW Lib "kernel32" (ByVal pFileName As Long) As Long  'to preload DirectCOM.dll
Private Declare Function GetInstanceEx Lib "DirectCOM" (spFName As Long, spClassName As Long, Optional ByVal UseAlteredSearchPath As Boolean = True) As stdole.IUnknown

Private CurPlugin As PluginInterfaces.IPluginInfo

Private Sub Form_Load()
  LoadLibraryW StrPtr(App.Path & "\Bin\DirectCom.dll")
  Set picSrc.Picture = LoadPicture(App.Path & "\Res\SrcImg.jpg")
  lstPlugins.Path = App.Path & "\Plugins"
End Sub

Private Sub lstPlugins_Click()
  If lstPlugins.ListIndex < 0 Then Exit Sub
  Set CurPlugin = LoadPlugin(lstPlugins.Path & "\" & lstPlugins.FileName)
 
  txtInfo(0) = CurPlugin.GetVersion
  txtInfo(1) = CurPlugin.GetName
  txtInfo(2) = CurPlugin.GetDescription
 
  lstActionClasses.Clear
  Dim AC
  For Each AC In Split(CurPlugin.GetActionClassNames, ",")
    lstActionClasses.AddItem Trim$(AC)
  Next
End Sub

Private Function LoadPlugin(FileNameDll As String) As PluginInterfaces.IPluginInfo
  Set LoadPlugin = GetInstanceEx(StrPtr(FileNameDll), StrPtr("Info")) 'instantiate the Info-Class regfree
End Function

Private Sub lstActionClasses_Click()
  If lstActionClasses.ListIndex < 0 Then Exit Sub
  DoAction lstActionClasses.Text
End Sub

Private Sub DoAction(ClassName As String)
  Dim ActionObj As PluginInterfaces.IPluginAction, Pxl() As Long
  Set ActionObj = CurPlugin.CreateActionInstance(ClassName)
 
  GetArrFromHdl Pxl, picSrc.Picture.Handle 'copy the Pixels from the Source-Picture into the Pxl-Array
    ActionObj.ProcessImgData UBound(Pxl, 1) + 1, UBound(Pxl, 2) + 1, VarPtr(Pxl(0, 0))
  DrawArr Pxl, picDst.hDC 'now that the action is finished, draw the resulting Pixels to the Destination-PicBox
  If picDst.AutoRedraw Then picDst.Refresh
End Sub

Here's a ScreenShot, what the Plugins do (I've decided to cover a "PhotoShop-like scenario"
(Plugins which cover different ImageProcessing-Algorithms).



Don't know - besides the already mentioned "hurdles":
- Regfree-Loading
- TypeLib-Creation
- getting familiar with VBs Implements-Keyword

There's not much more to say - if there's questions left - just ask...

The code for the Demo is here:
RegfreePluginHandlingVB6.zip

Have fun...

Olaf
Attached Files

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>