Solved

ATL ActiveX Entry point!!!

Posted on 2002-07-10
17
669 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

627 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