Sub classing methods in a dll (Ithink?)
Hi,
I am writing a serial communications dll. Let's call it MyDll
In the dll I have a class called CommsController which handles connection, disconnection via methods MyDll.CommsController.Connect etc.
A number of actions must be performed by the dll so, in order to keep the CommsController class at a sensible length, I want to have a method called DoAction which then calls methods from another class called Actions.
Let's say class actions has methods Sleep and Wake
I don't know how to structure things such that the methods of class Actions are exposed via MyDll.CommsController.DoAction.
I hope somebody understands what I am trying to do and can point me in the right direction.
Re: Sub classing methods in a dll (Ithink?)
VB 6 is not structured to handle sub-classing using classic the OOP technique, inheretance. This is commonly referred to as the "is-a" relationship (ie.. ClassB is-a ClassA when ClassB inherets from ClassA).
However, there is another OOP technique available to you, referred to as containment, or the "has-a" relationship (ie.. ClassA has-a ClassB).
You must use containment. It is a bit messy. ClassA is to expose all of ClassB's methods. In this case, ClassA must instantiate a Private variable of type ClassB. You must then code by hand every public member you want exposed and in that member, call the ClassB's identical member.
A possibly easier approach might be to expose the ClassB directly, like:
ClassA.ClassB.function()
Re: Sub classing methods in a dll (Ithink?)
Thanks for the reply.
I think I understand what you are saying. I will give it a try.
An example or code snippet showing how to do this would be appreciated if anybody has one.
Re: Sub classing methods in a dll (Ithink?)
Oh dear. One step forward into the next problem :cry:
I have added a class called Actions to my project.
I have exposed the methods of that class by defining.
Public DoActions As New Actions
in my CommsController class.
Fantastic! I can now reference the methods of the Actions class from the application using the dll by using MyDll.CommsController.DoActions and a list of the possible actions is available.
Unfortunately my CommsController class uses a lower level serial port control dll and is declared using
Private WithEvents LASSCD01DLL As MySerialPort
The problem now is that the Actions class needs to call a function from that dll as well. How can I do that?
Re: Sub classing methods in a dll (Ithink?)
Wel, you can define the Actions Class to have-a MySerialPort Class of its own. If you reference the ActiveX DLL to the Actions project, then just give the Actions Class its own MySerialPort Class:
VB Code:
Option Explicit
Private LASSCD01DLL As MySerialPort
Re: Sub classing methods in a dll (Ithink?)
Yes, that would work.
I was trying to make things more complicated than they need to be.
Thanks again :)