|
Thanks Eric. Wasn't what I was look 4 but appreicated the help.
|
|
|
|
|
Hello w_logan,
What you want to develop is an "Event Sink". If you are using ATL, create a class that inherits from IDispEventImpl. You will also need to include the BEGIN_SINK_MAP(), SINK_ENTRY_EX() and END_SINK_MAP() macros. Of course, your class will have to implement the event function itself. The great thing about the sink map macros is that you choose only those events that you want to supply handlers for. You do not need to implement handlers for all the events.
An alternative to using the above-mentioned ATL constructs is to use my TEventHandler class. Please read my article :
"Understanding COM Event Handling" (http://www.codeproject.com/com/TEventHandler.asp[^])
- Bio.
|
|
|
|
|
Thanks Bio. I had already read the article when I was doing my research. It was a great article.
I had initially intended to use "Event Sink" to solve my problem but I work around it by another mean.
Actually, I had a COM DLL with multiple objects within it. But I had only expose the main object class. My problem arise when one of my internal object needs to fire a event to the app using my DLL. As only the main interface is expose, the internal object can't fire the event direct to the app.
I was trying use the main object to sink the event and fire it again. But I never really got the way for doing the sink coding properly. Nonetheless, I worked around it by send the point to the main object inwards to the internal object and use this pointer to fire the event. It may not be the proper way to solve the problem but it solve my problem for now.
Nonetheless, thanks for the help again. (If you remember, you had help this fellow Singaporean on several other occasion.)
Cheers
-- modified at 22:09 Tuesday 22nd November, 2005
|
|
|
|
|
Hello w_logan,
Yes, I remember you. We had corresponded som months ago I believe. How are you ? I hope you're doing well. Just a few comments :
>> Actually, I had a COM DLL with multiple objects within it. But I had only expose the main object class. My problem arise when one of my internal object needs to fire a event to the app using my DLL. As only the main interface is expose, the internal object can't fire the event direct to the app.
Comment : you may want to re-think about the design of your interfaces. Since the internal object needs to fire an event to your app, this may signal a need for the internal object's interface to be exposed to the app directly.
On the other hand, if the internal object is meant to be internal afterall, then its events should rightfully be handled internally as well. The main object should be the handler for the event and it is a completely separate matter whether or not this main object ought to further "relay the message" to the app.
>> I was trying use the main object to sink the event and fire it again. But I never really got the way for doing the sink coding properly.
Comment : there are many ways to connect sinks with sources I guess. Just be careul about inter-thread event firing which will require marshaling. However, if everything happens on one thread, marshaling may not be so important.
>> Nonetheless, I worked around it by send the point to the main object inwards to the internal object and use this pointer to fire the event. It may not be the proper way to solve the problem but it solve my problem for now.
Comment : again, be careful about directly passing interface pointers here and there espacially across threads. Marshaling may be required.
- Bio.
|
|
|
|
|
Lim Bio Liong wrote: - Bio.
Hai Sir,
I am waiting for an article on IDispEventImpl from your side ...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hello Alok !
How are you dear friend ? Enthusiastic as usual. It's very contagious
Yes, it'd be great if there's an in-depth dissertation on ATL's IDispEventImpl. Especially one that can show how to use it in MFC apps. I'll see if I can get some time on this.
But how about yourself, Alok ? Would very much like to see you contribute another winner !
Best Regards,
Bio.
|
|
|
|
|
Lim Bio Liong wrote: How are you dear friend ? Enthusiastic as usual. It's very contagious
Ohh I am Alright Sir!.. As Usual ..
Lim Bio Liong wrote: Yes, it'd be great if there's an in-depth dissertation on ATL's IDispEventImpl. Especially one that can show how to use it in MFC apps. I'll see if I can get some time on this.
Thats would be Great ... if you find some time for that!
Lim Bio Liong wrote: But how about yourself, Alok ? Would very much like to see you contribute another winner !
Thats so nice of you, Sir!...But I am still in learning phase ... but as always its requires your help to get started ...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Could someone tell me what I may be doing wrong with my rebar usage here. I have a multi-threaded SDI app with the auto-generated rebar in the frame window. I want to add a band with a generic window or dialog as its child window. So I have something like this in my frame window's OnCreate:
CMyRebarWindow rbw;
rbw.Create(m_hWnd);
AddSimpleReBarBand(rbw, _T("Title"));
rbw.Detach();
For the CMyRebarWindow class I've tried just basically empty derived classes from CWindowImpl<> and CDialogImpl<>. I get an access violation somewhere deep into the Win32 ::ShowWindow function call for the frame window, possibly related to the WM_SYNCPAINT message (I say this because every so often the debugger stops in a different place, somewhere in the handling of this message. If I replace the CMyRebarWindow with, for example, a CComboBox, everything is fine.
Are there some restrictions on the type of windows you can use within a rebar band? Any ideas what is causing this? I realise it may be something stupid since I've just started using WTL.
On a side note, can someone explain what happens with command and notification messages from controls in rebar bands - I noticed that with a CCombo box in there, the command messages that came through to the frame window, like CBN_SELENDOK for example, came not with the correct ID of the combo box, but with an ID of 1 for some reason.
Any help on any of this would be much appreciated. Thanks.
|
|
|
|
|
i am trying to access mehod of ocx but its showing runtime error
HRESULT hret;
try
{
CoInitialize(NULL); // init of Com
hret = testPtr.CreateInstance(__uuidof(TestOCX));
testPtr->Check(); //Crash here
}
catch( _com_error &e )
{
// Get info from _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
TRACE( "\tCode = %08lx\n", e.Error());
TRACE( "\tCode meaning = %s\n", e.ErrorMessage());
TRACE( "\tSource = %s\n", (LPCTSTR) bstrSource);
TRACE( "\tDescription = %s\n", (LPCTSTR) bstrDescription);
}
catch(...)
{
TRACE( "*** Unhandled Exception ***" );
}
can anybody help me for the same
thanx
regards
Rajesh
|
|
|
|
|
|
Sounds like a bug in the OCX, it might be expecting you to call some initialization function first. 0x8000ffff is E_CATASTROPHIC, which is pretty much a catch-all for "something bad happened". Is this your own ocx? If it is, you should be able to step through it in the debugger. If not, I'd still run it in the debugger and look for first-chance exceptions, that would be a good indication of something wrong in the 'Check' method.
|
|
|
|
|
Hi,
we have created ATL dll in which we added one composite control on which
we have place an MFC user define control. we want to access the function of
that user define control.
we tried by getting reffrence pointer of that control but it gives memory
problem.
we are calling following stmt in OnInitDialog of composite control
CSOCX *cWnd = (CSOCX*)GetDlgItem(IDC_SOCXCTRL1);
if(cWnd)
{
cWnd->ShowWindow(SW_HIDE ); // it gives error here
cWnd->Assign(..);
...
}
please help me...
Regards
Rajesh
|
|
|
|
|
Dear friends,
Few days ago i developed an ActiveX control using MFC. The control was intened to be used by MFC dialog based clients. It is a windowless control. I preferred ActiveX control over simple COM dll, because it is easy to deal with the control events in MFC dialog based application. Just drop the control on the dialog, add a member variable, right click on it and handle events. So easy.
Now i want to use the functionality of this control in an application with no User Interface (i.e windows service). Is it possible to use the functionality exposed by ActiveX control in an application which provides no GUI container. If yes, then how ???
Ahsan
|
|
|
|
|
Is there any way to indicate the duplicate key insertion in STL map.
Here the key should be a class object.
|
|
|
|
|
#include < iostream >
#include < map >
using namespace std;
int main()
{
map < int, int > themap;
pair < map < int, int > ::iterator, bool > res = themap.insert(pair < int,int > (1,2));
if (res.second)
cout << "a value was inserted" << endl;
else
cout << "a value was updated" << endl;
res = themap.insert(pair < int,int > (1,3));
if (res.second)
cout << "a value was inserted" << endl;
else
cout << "a value was updated" << endl;
return 0;
}
If you have to be sure before inserting elements, you'll need to use find before inserting.
---
"Man will never be free until the last king is strangled with the entrails of the last priest". -- Denis Diderot
|
|
|
|
|
hi ,
I have an code, in that code i want know when i will get a duplicate value since values are generated at runtime.
could you know the duplicate value by overloading < and == operators.
#include<iostream.h>
#include <algorithm>
class A
{
unsigned long la;
unsigned long lb;
unsigned long lc;
public:
A()
{
la=lb=lc=0;
}
A(unsigned long ln,unsigned long lm,unsigned long lo)
{
la=ln;
lb=lm;
lc=lo;
}
A(const A& objref)
{
la=objref.la ;
lb=objref.lb;
lc=objref.lc;
}
A& operator =(const A& objref)
{
if(this!=&objref)
{
la=objref.la;
lb=objref.lb;
lc=objref.lc;
}
return *this;
}
bool operator==(const A& objref) const
{
bool b=(((la==objref.la)&&(lb==objref.lb)&&(lc==objref.lc))?1 );
return b;
}
/*
bool operator<(const A& objref) const
{
if((((la==objref.la)&&(lb==objref.lb)&&(lc==objref.lc))?1 ))
{
cout<<"Attempting insert a duplicate value -"<<"("<<la<<","<<lb<<","<<lc<<")"<<" -="" "<<endl;
="" }
="" return="" la<objref.la=""
="" ||(!(objref.la<la)="" &&="" lb<objref.lb)
="" ||(!(objref.la<la)&&="" (!(objref.lb<lb))&&="" lc<objref.lc);
="" *="" bool="" operator="" !="(const" a&="" objref)="" const
="" {
="" if(((la="=objref.la)&&(lb==objref.lb)&&(lc==objref.lc))?1 )
" 0;
="" 1;
="" unsigned="" long="" sum();
="" void="" displayvalues()="" cout<<"("<<la<<","<<lb<<","<<lc<<")"<<"="" ";
="" friend="" class="" asortcriterion;
};
unsigned="" a::sum="" ()
{
="" (la+lb+lc);
}
="" for="" function="" predicate
*="" operator()="" returns="" whether="" a="" person="" is="" less="" than="" another="" person
*=""
class="" asortcriterion=""
{
public:
="" (const="" p1,="" const="" p2)="" if((((p1.la="=p2.la)&&(p1.lb==p2.lb)&&(p1.lc" =="p2.lc))?1 ))
" cout<<"attempting="" insert="" duplicate="" value="" -"<<"("<<p1.la<<","<<p1.lb<<","<<p1.lc<<")"<<"="" p1.la<p2.la="" ||(!(p2.la<p1.la)="" p1.lb<p2.lb)
="" ||(!(p2.la<p1.la)&&="" (!(p2.lb<p1.lb))&&="" p1.lc<p2.lc);
=""
};
="" maptest.cpp="" :="" defines="" the="" entry="" point="" console="" application.
=""
#include="" "stdafx.h"
#include="" "maptest.h"
#include<map="">
using namespace std;
typedef std::map Aptrmap;
int main(int argc, char* argv[])
{
A objOne(0,1,2);
A objTwo(0,1,2);
A objThree(0,1,1);
A objFour(3,4,0),objFive(4,4,5);
float *pfa,*pfb,*pfc,*pfd,*pfe;
pfa= new float(1.10);
pfb= new float(2.20);
pfc= new float(3.30);
pfd =new float(4.40);
pfe =new float(5.50);
Aptrmap objmap;
objmap.insert(std::make_pair(objFive,pfe));
// objmap[objFive]=pfe;
objmap.insert(std::make_pair(objOne,pfa));
objmap.insert(std::make_pair(objTwo,pfb));
objmap.insert(std::make_pair(objThree,pfc));
objmap.insert(std::make_pair(objFour,pfd));
float pf=9;
objmap[objThree]=&pf;
// print all element values
Aptrmap::iterator pos;
for (pos = objmap.begin(); pos != objmap.end(); ++pos)
{
(pos->first).DisplayValues();
cout <<*( pos->second )<<endl;
}
="" cout="" <<="" endl;
=""
="" aptrmap::const_iterator="" postwo="objmap.find(objThree);
" cout<<*(postwo-="">second)<<endl;
="" aptrmap::const_iterator="" postwo1="objmap.find(objFive);
" cout<<*(postwo1-="">second)<
|
|
|
|
|
Some of your post was eaten and it's still not clear to me if you want to know if an item was a dublicate before or after you insert it into the map.
Here's your code (rewritten some so I could get it to compile)
[Edited:] Doh! I was under the impression that map<>::insert updates an elemet already in the map. That is not correct, sorry for the confusion!
#include <iostream>
#include <map>
#include <boost\shared_ptr.hpp>
using namespace std;
class A
{
unsigned long la;
unsigned long lb;
unsigned long lc;
public:
A() : la(0), lb(0), lc(0) {}
A(unsigned long ln,unsigned long lm,unsigned long lo): la(ln), lb(lm), lc(lo) {}
A(const A& o) : la(o.la), lb(o.lb), lc(o.lc) {}
bool operator==(const A& o) const
{
return la == o.la && lb == o.lb && lc == o.lc;
}
bool operator !=(const A& o) const
{
return !(*this == o);
}
unsigned long sum()
{
return (la+lb+lc);
}
bool operator < (const A& o) const
{
if (la == o.la)
if (lb == o.lb)
return lc < o.lc;
else
return lb < o.lb;
else
return la < o.la;
}
friend ostream& operator<<(ostream& out, const A& o);
};
ostream& operator<<(ostream& out, const A& o)
{
out<<"("<<o.la<<","<<o.lb<<","<<o.lc<<")";
return out;
}
namespace std { // needed for std::copy to work
ostream& operator<<(ostream& out, const pair<A, boost::shared_ptr<float> >& o)
{
out << "[" << o.first << "," << *(o.second) << "]";
return out;
}
}
typedef std::map<A, boost::shared_ptr<float> > Aptrmap;
bool is_duplicate(const Aptrmap& themap, const A& o)
{
return themap.find(o) != themap.end();
}
int main(int argc, char* argv[])
{
A objOne(0,1,2);
A objTwo(0,1,2);
A objThree(0,1,1);
A objFour(0,1,2);
A objFive(4,4,5);
boost::shared_ptr<float> pfa(new float(1.10)),
pfb(new float(2.20)),
pfc(new float(3.30)),
pfd(new float(4.40)),
pfe(new float(5.50));
Aptrmap objmap;
pair <Aptrmap::iterator, bool> it;
it =objmap.insert(std::make_pair(objFive,pfe));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;
// objmap[objFive]=pfe;
it =objmap.insert(std::make_pair(objOne,pfa));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;
it =objmap.insert(std::make_pair(objTwo,pfb));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;
it =objmap.insert(std::make_pair(objThree,pfc));
// check if we inserted a new value or updated an old item
if (it.second)
cout << *(it.first) << " was inserted" << endl;
else
cout << *(it.first) << " was a duplicate" << endl;
// check if this value is a duplicate before inserting
if (!is_duplicate(objmap, objFour))
{
it =objmap.insert(std::make_pair(objFour,pfd));
if (it.second)
cout << *(it.first) << " was inserted" << endl;
}
else
cout << objFour << " was a duplicate, will not insert it" << endl;
boost::shared_ptr<float> pf(new float(9));
objmap[objThree]=pf;
// print all element values
copy(objmap.begin(), objmap.end(), ostream_iterator<pair<A, boost::shared_ptr<float> > >(cout, "\n"));
Aptrmap::const_iterator posTwo=objmap.find(objThree);
if (posTwo != objmap.end())
cout<<*(posTwo->second)<<endl;
Aptrmap::const_iterator posTwo1=objmap.find(objFive);
if (posTwo1 != objmap.end())
cout<<*(posTwo1->second)<<endl;
return 0;
}
HTH
---
"Man will never be free until the last king is strangled with the entrails of the last priest". -- Denis Diderot
-- modified at 8:49 Monday 14th November, 2005>>
|
|
|
|
|
Or alternatively, use count, as that returns an integer that can be tested in a boolean fashion (makes for more concise code)
|
|
|
|
|
Could you please elaborate further? I'm really not sure what you mean by "use count".
--
Pictures[^] from my Japan trip.
|
|
|
|
|
I meant "use the count method" - assume we've got a map call a_map and that we're trying to put something keyed by the number 16 into it:
if (!a_map.count(16)) a_map.insert(std::make_pair(16, something_else));
rather than
if (a_map.end() == a_map.find(16))
a_map.insert((std::make_pair(16, something_else)));
It just always seems sort of wrong that there's no "test for the presence of a value in a map
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Aha! I didn't know about the count() method for ordinary maps. I thought it was a pure multimap method.
> It just always seems sort of wrong that there's no "test for the presence of a value in a map
Indeed! Where's the ismember() method?
--
|
|
|
|
|
Especially when you look atstd::binary_search , expecting to find something that returns an iterator and find it returns a bool instead...
I use the STL a lot, and do think it's pretty damn good....but some bits of it just seem a bit bizarro...
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
Except that using count does much more than you need. Much like using strlen/size to test to see if a string is empty. Thus it is a performance problem. Even with a map, count with get the lower bound and then the upper bound for that key. Then it computes the delta of the two iterators. (V7 implementation)
If you want to create some form of a test, create a template function to do the find and then test for end. Then again, you can just use the insert and avoid the needless double search.
Tim Smith
I'm going to patent thought. I have yet to see any prior art.
|
|
|
|
|
Is there a way to use commands like cout in a command line in a WTL program? This could be very useful for debugging to monitor how and when events are being called (for example).
|
|
|
|
|
A GUI app can call AllocConsole() to create a console window. See the MSDN topic "Reading and Writing Blocks of Characters and Attributes" for some sample code.
You can also write the debug stuff with ATLTRACE (or the API itself, OutputDebugString() ) and then run an app that shows the debug output.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | 1ClickPicGrabber | NEW~! CP SearchBar v3.0 | C++ Forum FAQ
Pinky, are you pondering what I'm pondering?
I think so Brain, but if we shaved our heads, we'd look like weasels!
|
|
|
|
|