Click here to Skip to main content
15,899,314 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: VC++ abt buttons Pin
Ravi Bhavnani3-Feb-05 7:46
professionalRavi Bhavnani3-Feb-05 7:46 
GeneralRe: VC++ abt buttons Pin
Tripura.K3-Feb-05 22:26
Tripura.K3-Feb-05 22:26 
GeneralDriver architecture advice needed Pin
@Work3-Feb-05 1:48
@Work3-Feb-05 1:48 
GeneralRe: Driver architecture advice needed Pin
Antti Keskinen3-Feb-05 3:44
Antti Keskinen3-Feb-05 3:44 
GeneralRe: Driver architecture advice needed Pin
Geert van Horrik3-Feb-05 20:41
Geert van Horrik3-Feb-05 20:41 
GeneralRe: Driver architecture advice needed Pin
Antti Keskinen3-Feb-05 23:14
Antti Keskinen3-Feb-05 23:14 
GeneralRe: Driver architecture advice needed Pin
Geert van Horrik3-Feb-05 23:23
Geert van Horrik3-Feb-05 23:23 
GeneralRe: Driver architecture advice needed Pin
Antti Keskinen3-Feb-05 23:48
Antti Keskinen3-Feb-05 23:48 
Hi !

COM offers language indepence, thus it is the most reasonable choice if you want your object to be usable from all languages which support COM. These include, but are not limited to, Visual C++/Basic/C#/.NET. Even PHP supports COM these days...

However, back into the issue. The object-oriented approach is correct on this problem, but it seems you've started with wrong presumptions. First of, you don't need multiple COM objects. A single COM object which has multiple interfaces is enough. One interface for enumerating the available PLC devices and offering an index of the device, a second interface for connecting and disconnecting from the PLC and possibly a third interface which allows reading/writing from the device. And 1...n classes which implement these interfaces. 3 in the biggest case, 1 in the simplest case.

The keyword here is multiple inheritance. Consider this example:
class IEnumPLCDevices
{
public:
    virtual DWORD GetPLCList(int* nArray, int& nAmountOfDevices) = 0;
};<DIV>

class IConnectPLCDevice
{
public:
    virtual DWORD ConnectToDevice(int nIndex, IPLCDevice** plcDeviceInterface) = 0;
};<DIV>

class IPLCDevice
{
public:
    virtual DWORD Read(int nByteCount, void** pDestination) = 0;
    virtual DWORD Write(int nByteCount, void* pSource) = 0;
};<DIV>

class PrivatePLCCollection : public IEnumPLCDevices, public IConnectPLCDevice, public IPLCDevice
{
public:
   .
   // Implementation of the virtual methods to enumerate, connect and interact with the devices
   // A routine which will return the required interface pointer
   .
};
Here is the simplest model I can use to fathom an object-oriented DLL. It is not a COM example, but it follows the 'interface' idealism I showed earlier.

You don't need to seperate the communication and connections to different COM objects. They can co-exist peacefully inside a single object. You must remember here that a COM object is not the same thing as a C++ class. A COM object can have multiple C++ classes inside it. For an example, consider DirectX. It has multiple interfaces, and even more classes. Some classes implement more than one interface. However, each DirectX component is a single, independent COM object, such as Direct3D. You don't need the DirectSound object to use the Direct3D object's services, but the Direct3D object offers all the services to create, populate and manipulate 3D scenes. Lots of services (classes/interfaces), but a single COM object.

I believe there are some examples in CodeProject on writing COM objects. See under General -> COM/DCOM/COM+. You should read the articles marked with 'beginner' through to gain understanding on how COM works. Then you can start implementing your own object, either by following the examples, or simply by exploring.

-Antti Keskinen

----------------------------------------------
"If we wrote a report stating we saw a jet fighter with a howitzer, who's going to believe us ?"

-- R.A.F. pilot quote on seeing a Me 262 armed with a 50mm Mauser cannon.
GeneralRe: Driver architecture advice needed Pin
Geert van Horrik4-Feb-05 0:01
Geert van Horrik4-Feb-05 0:01 
GeneralRe: Driver architecture advice needed Pin
Antti Keskinen4-Feb-05 1:05
Antti Keskinen4-Feb-05 1:05 
GeneralRe: Driver architecture advice needed Pin
Geert van Horrik4-Feb-05 1:15
Geert van Horrik4-Feb-05 1:15 
GeneralCharting Pin
_Tom_3-Feb-05 1:24
_Tom_3-Feb-05 1:24 
GeneralRe: Charting Pin
David Crow3-Feb-05 3:47
David Crow3-Feb-05 3:47 
GeneralRe: Charting Pin
krmed3-Feb-05 6:51
krmed3-Feb-05 6:51 
GeneralGet system properies at runtime Pin
Member 16603853-Feb-05 1:13
Member 16603853-Feb-05 1:13 
GeneralRe: Get system properies at runtime Pin
David Crow3-Feb-05 2:54
David Crow3-Feb-05 2:54 
Generalabt keyboard Pin
Anonymous3-Feb-05 1:13
Anonymous3-Feb-05 1:13 
GeneralRe: abt keyboard Pin
Mike Dimmick3-Feb-05 2:43
Mike Dimmick3-Feb-05 2:43 
QuestionChanging Source IP ? Pin
Adnan5623-Feb-05 0:56
Adnan5623-Feb-05 0:56 
AnswerRe: Changing Source IP ? Pin
Antony M Kancidrowski3-Feb-05 1:13
Antony M Kancidrowski3-Feb-05 1:13 
GeneralApply different themes to single application Pin
ledallam2-Feb-05 23:39
ledallam2-Feb-05 23:39 
GeneralRe: Apply different themes to single application Pin
Antti Keskinen3-Feb-05 4:04
Antti Keskinen3-Feb-05 4:04 
GeneralNon blocking MFC Dll Pin
lmfernandez2-Feb-05 23:38
lmfernandez2-Feb-05 23:38 
GeneralRe: Non blocking MFC Dll Pin
Antony M Kancidrowski3-Feb-05 1:07
Antony M Kancidrowski3-Feb-05 1:07 
GeneralRe: Non blocking MFC Dll Pin
lmfernandez3-Feb-05 2:55
lmfernandez3-Feb-05 2:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.