Initialise ActiveX within a Class...


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 AtkinSenior Principle Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
James AtkinSenior Principle Software EngineerAuthor Commented:
The first option sounds like what I am after...

Can you please supply a snippit of example code?

Thanks again,

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

-- Dan
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

James AtkinSenior Principle Software EngineerAuthor Commented:
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...
If you want ActiveX Control to be invisible and you need it for some purpose inside of the class, create invisible window and keep the control in it.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
James AtkinSenior Principle Software EngineerAuthor Commented:
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....
James AtkinSenior Principle Software EngineerAuthor Commented:

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 AtkinSenior Principle Software EngineerAuthor Commented:
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 AtkinSenior Principle Software EngineerAuthor Commented:
Tidy up time on open questions...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.