Link to home
Start Free TrialLog in
Avatar of Member_2_99151
Member_2_99151

asked on

Initialise ActiveX within a Class...

Hi,

I have an interesting issue that I am having problems with ...

I have created a Class called DBConnect - which is used as a communications Class.  Within this class I wish to create a reference to a Database ActiveX control.  The 'DBConnect' Class provides a simple interface to the ActiveX control..

Now, I have created a private variable 'm_DB' which is an instance of the Database ActiveX, which is held within the DBConnect Class.

Public Functions if DBConnect will then be used to access the ActiveX.

Sounds fairly straight forward - he says - however it appears that I somehow need to 'Initialise' the ActiveX - as currently, I will get Assertions due to the Control not being ready...

How do I do this?  In previous cases I use the 'Create' function, but there is no hWnd to tie it to - or have a missed something...

Any help would be very much appreciated...

James
Avatar of AlexFM
AlexFM

You need to use window handler supplied by client - add function like:
Create(HWND, RECT)
to DBConnect class and create an ActiveX control in it.

If your class should be wrapper to existing ActiveX control added by user to dialog/form using designer, add function
Attach(<ActiveX control pointer>).

You may use both functions allowing to user both ways.
Avatar of Member_2_99151

ASKER

The first option sounds like what I am after...

Can you please supply a snippit of example code?

Thanks again,

James
Avatar of DanRollins
Why do you need a window?  It sounds like your class purely functional behind-th-scenes... not U/I related at all.

-- Dan
You're right, the Class is purely functional, however I understood that the 'Create' function needed a handle - I am obviously mis-understanding something.

If it is possible to simply initialise the ActiveX within the Class as a member variable (as in VB - Set myObj = New TheObject) then this is exactly what I am after.  I looked for info on doing this some time back, but as I found no information at all, I assumed that it couldn't be done that way...
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you please give an example - I've been a C/C++ programmer for many years, but my knowledge of MFC is still getting there....
Hi,

The original requirement for this (dbConnect) is no longer an issue - I have extended the CDatabase class to cater for my requirements, howeverI still have this issue for another control - can anybody help?

It is associated with MSComm, which is created at runtime.  The handle to the control is held in m_pMainWnd, and created during the InitInstance function.  Obviously, by doing this, it works Ok, but generates a number of First Chance Exceptions.

To remove them, I need to Create the instance, but not attempt to display it in any way...  The current call is as folows:
   myCOM.Create("COMx", WS_VISIBLE, CRect(10,10,15,15), m_pMainWnd, IDC_COMX);

I believe that this is possible, but I am using the wrong parameters (WS_VISIBLE for one!)

Please can anybody help...

Best regards,

James
Don't worry - if I change the call to ...

   myCOM.Create(NULL, WS_VISIBLE, CRect(0,0,0,0), m_pMainWnd, IDC_COMX);

I get no Exception warnings..

James
Tidy up time on open questions...