|
-
Jan 24th, 2005, 12:11 PM
#1
Thread Starter
Hyperactive Member
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.
Last edited by Simon Caiger; Jan 25th, 2005 at 09:37 AM.
Reason: Resolved
Simon Caiger
Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.
-
Jan 24th, 2005, 01:02 PM
#2
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()
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
-
Jan 25th, 2005, 03:35 AM
#3
Thread Starter
Hyperactive Member
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.
Simon Caiger
Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.
-
Jan 25th, 2005, 05:03 AM
#4
Thread Starter
Hyperactive Member
Re: Sub classing methods in a dll (Ithink?)
Oh dear. One step forward into the next problem
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?
Simon Caiger
Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.
-
Jan 25th, 2005, 09:24 AM
#5
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
Nobody knows what software they want until after you've delivered what they originally asked for.
Don't solve problems which don't exist.
"If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)
2 idiots don't make a genius.
-
Jan 25th, 2005, 09:35 AM
#6
Thread Starter
Hyperactive Member
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
Simon Caiger
Documentation is like sex; when it's good, it's very, very good, and when it's bad, it's better than nothing.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|