Solved

ATL ActiveX Entry point!!!

Posted on 2002-07-10
17
664 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ assignment question 7 236
C++ dll will not run on machine without VS installed 10 87
Embarcadero C++ Builder XE2 TDateTime 8 75
Adding items to a C# list incrementally 5 29
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

839 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