Solved

ATL ActiveX Entry point!!!

Posted on 2002-07-10
17
656 Views
Last Modified: 2007-11-27
Hi,

I am developing an ATL Activex control. I want to invoke an event at startup ( run-time only ), depending upon the value of a property. The scenario is like,
the proprty name is "InvokeAtStartup", if this property is set to TRUE at design time, then the OCX is supposed to fire an event at startup during run-time. Can anyone tell me where i should write the code to test for the value of this property( there I should also be able to know, whether the control is being used as run / design time component ), and invoke the event depending upon the value of the "InvokeAtStartup" property.

Thanks in advance
Jagadeesh
0
Comment
Question by:coxswainindia
17 Comments
 
LVL 22

Expert Comment

by:ambience
ID: 7145383
If your control has always has a window then you can think about doing that inside handler for WM_CREATE.

You can force to always have a window by setting m_bWindowedOnly bit.

0
 

Author Comment

by:coxswainindia
ID: 7145528
how can i know whether the control is created at design time or at run-time. The event needs to be fired only at run-time. Furthermore, How can I get the property value of the control in WM_CREATE?
0
 
LVL 22

Expert Comment

by:ambience
ID: 7145550
HRESULT CComControl::GetAmbientUserMode(BOOL& mode)

this tells if the control is in design time (FALSE) or runtime mode (TRUE).

HRESULT CComControl::GetAmbientProperty( DISPID dispid, VARIANT& var )

use this method to fetch value of any property including predefined ones and your own properties as well.

hope this helps.



0
 
LVL 22

Expert Comment

by:ambience
ID: 7145556
if you are asking about how to add handler for WM_CREATE then you need to add a MSG map to your control like

BEGIN_MSG_MAP(CMyCtrl)
     MESSAGE_HANDLER(WM_CREATE, OnCreate)
END_MSG_MAP()

LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
0
 

Author Comment

by:coxswainindia
ID: 7148643
WM_CREATE will not work in my case, just because my control doesn't have any window associated with it. For that reason I think, I may not be able to check for the property value in OnCreate(). Can u pls tell me whether, I can use CComControl::FinalConstruct( ) for this ??

Will all the property values be loaded at this time ??
0
 

Author Comment

by:coxswainindia
ID: 7166393
hehe!!!

nobody there to help me OUT!!!
GetAmbientUserMode i snot working, its always returning TRUE, Furthermore even microsoft has recommended not to use this method. Is there any other work-around ??
0
 
LVL 22

Expert Comment

by:ambience
ID: 7169000
!! You can force to always have a window by setting m_bWindowedOnly bit.

>> CComControl::FinalConstruct( ) for this ??

I am not so sure about that and i think it wont,

>> Will all the property values be loaded at this time ??

precisely this appears to be an issues with FinalConstruct, plus i dint think any client can connect to the control to catch its events before FinalConstruct return, If finalContruct fails the object is not created at all, that is why i recommended you to do it in WM_CREATE handler. You can force the control to always have a window by setting a flag in the contructor m_bWindowOnly, as far as i remember that is inside a union. A more exact way to set this flag is given in MSDN. Its been a long time so i may be forgetting something.

>> GetAmbientUserMode i snot working, its always returning TRUE

where are you calling it from ? OnCreate ? or FinalConstruct ? can you post a link to the information forbidding its use ?

and yes sorry for late reply ...
0
 

Author Comment

by:coxswainindia
ID: 7169112
Thanks for your interest...

I tried calling GetAmbientUserMode from FinalConstruct(). I cannot use OnCreate for this, just b'coz, if the container application is VB, and if the developer uses declaration something like this

Dim withevents object as ActiveX

Then I will certainly landup in trouble. b'coz I think such declarations will never create a window and the program control will not even reach OnCreate. Is there any other point where I can check for the mode by calling GetAmbientUserMode and the property value and then fire the respective event if neccessary.

Thanks in advance
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 22

Expert Comment

by:ambience
ID: 7170922
>> I think such declarations will never create a window and the program control will not even reach OnCreate

almost true

>> Dim withevents obj as ActiveX

This is not the usual way of instantiating ActiveX controls from VB, why would you like to do it that way ? you can add it directly on the Form from the Toolbox and no need to declare a var and create it.

0
 
LVL 22

Expert Comment

by:ambience
ID: 7170927
Any other place , oh well you can fire it from OnDraw() if the usermode is TRUE, and perhaps keep a flag to make it fire once only.

I cant think of any other place at the moment. However i do recommend that you do it from OnCreate.

Even if you provide a method say FireIt , that fires the event , are you sure you can make the following work

Dim withevents obj as ActiveX

correct me if am wrong
0
 

Author Comment

by:coxswainindia
ID: 7171027
I am not writing this OCX for my use. If it was for my requirement, then I can very much avoid using "withevents". But my client wants provisions for window-less activation.

Will the poroperty values be available at OnCreate. As far as I know, the property values are loaded by a call to LoadObject of IPropertyBag. Moreover Is it possible to get the USERMODE from OnCreate() ?

Above all, I feel, OnCreate will not be called for "withevents"!!!

Pls correct me if I am wrong.
0
 
LVL 22

Expert Comment

by:ambience
ID: 7171069
Yes property values are accessible from OnCreate, i remember another question like that and the questioneer solved it by using Windowed only style. His exact problem was also determining the usermode as soon as possible.

>> OnCreate will not be called for "withevents"!!!

Nothing will be called or callable , because you need to do

set obj = new MyObject

to instantiate the control and it is after that that you recieve events or can call method, also the control will get a WM_CREATE at that point
0
 

Author Comment

by:coxswainindia
ID: 7171085
I have one more doubt...

If I use "withevents" and "Set" in VB, then the resulting ActiveX object will not be having any window associated with it!!!
Then How come OnCreate be invoked ??

OnCreate is invoked to create the window, But in this case, there is no window associated with the object, then how can I handle it in OnCreate()
0
 
LVL 22

Expert Comment

by:ambience
ID: 7171116
>> my client wants provisions for window-less activation

umm yes, because of the above facts the problem still remains otherwise it could have been tackled by setting an Invisible property and creating a window that is invisible, this way WM_CREATE is ensured.

But i think you cannot force WindowOnly mode because of the above fact.

Looks like i have to dig in deeper this time ...
0
 

Author Comment

by:coxswainindia
ID: 7173445
Pls do that, I've tried a lot, and to be frank, I'm getting a bit wierd, with not getting the results.

Anyway thanks for your interest...
0
 
LVL 11

Expert Comment

by:griessh
ID: 7439530
Dear coxswainindia

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to

     "refund the points and PAQ at zero points"

since nobody had a satisfying answer for you.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Accepted Solution

by:
Mindphaser earned 0 total points
ID: 7479692
Points refunded and moved to PAQ

** Mindphaser - Community Support Moderator **
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

762 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

19 Experts available now in Live!

Get 1:1 Help Now