Solved

Initialise ActiveX within a Class...

Posted on 2003-10-22
9
156 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:jatkin
  • 6
  • 2
9 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 9597800
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.
0
 
LVL 4

Author Comment

by:jatkin
ID: 9597828
The first option sounds like what I am after...

Can you please supply a snippit of example code?

Thanks again,

James
0
 
LVL 49

Expert Comment

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

-- Dan
0
 
LVL 4

Author Comment

by:jatkin
ID: 9612325
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...
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 9612387
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.
0
 
LVL 4

Author Comment

by:jatkin
ID: 9612429
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....
0
 
LVL 4

Author Comment

by:jatkin
ID: 9903307
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
0
 
LVL 4

Author Comment

by:jatkin
ID: 9903437
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
0
 
LVL 4

Author Comment

by:jatkin
ID: 11610716
Tidy up time on open questions...
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa‚Ķ
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now