|
Another option is to use ATL's CComBSTR[^] class.
|
|
|
|
|
Nemanja Trifunovic wrote: Another option is to use ATL's CComBSTR[^] class.
yeap you are right but, i will prefer _bstr_t
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
"If it were machines, the pair_programming seem to work, but for humans it is pair_crackdown that seems to work! " - Nisamudheen
Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
If I use WTL::CHyperLink of HLINK_UNDERLINEHOVER style and handle the WM_CTLCOLORSTATIC message at the parent dialog, underlined text font is not reset to not underlined when the cursor is removed from the control. Does anyone know how this can be fixed?
|
|
|
|
|
Dear friend,
I am new in ATL world. I want to implement IEnumString in ATL 3.0. I searched in google, but did not get appropriate example. Can anybody help me and give some example.
|
|
|
|
|
|
|
Welcome, buddy!
God bless,
Ernest Laurentin
|
|
|
|
|
Hi,
I am trying to use find_if STL method for learning purpose. I have an array of structure as
struct NewPriceLookup
{
NewPriceLookup() : m_oldprice(0.0), m_newprice(0.0)
{}
NewPriceLookup(const double& oldp, const double& newp):
m_oldprice(oldp), m_newprice(newp)
{}
double m_oldprice;
double m_newprice;
};
NewPriceLookup npLookup [5] = {NewPriceLookup(10.0, 12.0),
NewPriceLookup(12.0, 14.5),
NewPriceLookup(15.0, 17.0),
NewPriceLookup(22.0, 26.0),
NewPriceLookup(30.0, 35.0) };
vector<NewPriceLookup> OldNewPriceTable(&npLookup[0], &npLookup(5));
template<typename T1, typename T2, typename T3>
struct NewPriceGrabber : public binary_function<T1, T2, T3>
{
result_type operator()(first_argument_type arg1, second_argument_type arg2)
{
return (arg1.m_oldprice == arg2);
}
};
and somewhere in the method GetNewPrices() I am trying to do the following
.....
.....
double oldprice = 15.0;
double newprice = find_if( OldNewPriceTable.begin(), OldNewPriceTable.end(),
bind2nd(NewPriceGrabber<NewPriceLookup, double, bool>(), oldprice));
When I compile this code, I am getting all sorts of errors like pointer_to_binary_function expects 2 argument 1 provided, cannot deduce template argument etc...
Can someone please help me in getting this piece of code right?
Thanks in advance.
<div class="ForumMod">modified on Sunday, February 24, 2008 12:42 PM</div>
|
|
|
|
|
First thing - what compiler are you using? If it's VC++ 6, then....upgrade if at all possible! I've just compiled your code with VC++2005 and it seems fine, aside from a) needing const qualification on NewPriceGrabber 's operator() , b) this line
double newprice = find_if( OldNewPriceTable.begin(), OldNewPriceTable.end(),
bind2nd(NewPriceGrabber<NewPriceLookup, double, bool>(), oldprice)); which returns a vector iterator, not a double:
std::vector<NewPriceLookup>::const_iterator it = std::find_if( OldNewPriceTable.begin(), OldNewPriceTable.end(),
bind2nd(NewPriceGrabber<NewPriceLookup, double, bool>(), oldprice)); and c) I presume the '&npLookup(5) ' is a typo, 'should be '&npLookup[5] '.
My other advice would be to use Boost.Bind[^] or Boost.Lambda[^] for function binders - I find them a lot less confusing. Your example would translate to:
bool NewPriceGrabber(NewPriceLookup const& arg1, double price)
{
return (arg1.m_oldprice == price);
}
void x()
{
double oldprice = 15.0;
std::vector<NewPriceLookup>::const_iterator it = std::find_if( OldNewPriceTable.begin(), OldNewPriceTable.end(),
boost::bind(NewPriceGrabber, _1, oldprice));
} Two advantages - 1) no function object needed, 2) the bind function takes a function reference/pointer (NewPriceGrabber here) as well as 1 value for each parameter of the function. You use placeholder arguments (that's the _1 ) where you don't want to bind a parameter to a value.
|
|
|
|
|
A couple of other suggestions re: STL
- For a simple lookup table, a
map would be the preferred container, rather than use a vector of structures:
#include <map>
typedef std::map<double, double> NewPriceLookup;
void x()
{
double oldprice = 15.0;
NewPriceLookup npLookup;
npLookup.insert(std::make_pair(10.0, 12.0));
npLookup.insert(std::make_pair(12.0, 14.5));
npLookup.insert(std::make_pair(15.0, 17.0));
npLookup.insert(std::make_pair(22.0, 26.0));
npLookup.insert(std::make_pair(30.0, 35.0));
NewPriceLookup::const_iterator it = npLookup.find(oldprice);
} If you want to initialise a map , you can use Boost.Assign[^].
operator() in function objects should generally be defined to take arguments (especially structs/classes) by const reference rather than by value - it minimizes copying. Also, operator() should in general be const -qualified - it's all part of const -correctness.
|
|
|
|
|
Hi Stuart,
Thanks for your suggestions. Using STL map was so simple, I didn't realized it earlier but anyways I did wanted to learn the usage of find_if method.
I will also look into Boost libraries once I have a bit more confidence in STL itself.
Regards.
|
|
|
|
|
psychedelic_fur wrote: but anyways I did wanted to learn the usage of find_if method.
Good plan! I did wonder whether "learning to use STL" was the reason you were using vector & find_if rather than map.
psychedelic_fur wrote: I will also look into Boost libraries once I have a bit more confidence in STL itself.
I'll just reiterate that (IMO) Boost binders are a lot easier to get to grips with than STL binders - I have always had trouble working out exactly what bind2nd and bind1st will produce.
|
|
|
|
|
Yes I did used vector for that purpose, may be my example was not good.
I would really like to understand STL first before using Boost. Even though boost make the life simple it does hide you from lots of internal details and I do not want to miss on those details.
Thanks & Regards.
|
|
|
|
|
Just a tip for coming exercises: Never compare floating point types for equality. Only use integral types for equality comparisons. Floating point types should be compared by checking if their difference is smaller than some defined tolerance.
--
Time you enjoy wasting is not wasted time - Bertrand Russel
|
|
|
|
|
Hi all,
I wanted to write a browser plugin. In Firefox, I could simply write some javascript with XUL to get things to work. In Internet Explorer, from my online searching, it seems that I have to write ATL code if I want a toolbar with buttons (Explorer Band)?
Now writing Javascript for one and ATL for other seems like a lot of repeatation. I would like to use Javascript for both. Is it possible to simply write a toolbar in ATL and call some javascript code for the toolbar buttons to manipulate window elements? If so, how can I call the Javascript from ATL?
Please guide.
Viv.
|
|
|
|
|
whizdom wrote: I wanted to write a browser plugin. In Firefox, I could simply write some javascript with XUL to get things to work. In Internet Explorer, from my online searching, it seems that I have to write ATL code if I want a toolbar with buttons (Explorer Band)?
Now writing Javascript for one and ATL for other seems like a lot of repeatation. I would like to use Javascript for both. Is it possible to simply write a toolbar in ATL and call some javascript code for the toolbar buttons to manipulate window elements? If so, how can I call the Javascript from ATL?
There is a set of Windows Scripting Engine objects and interfaces. I think the appropriate COM object has a progid of "JScript" and implements IActiveScript. You will need to implement an object with IActiveScriptSite. The stuff is fairly complicated, so it'll take some time to learn.
I'm impressed that you can get XUL to work. I tried to make a program to run on Seamonkey, and I've given up on it.
Nathan
|
|
|
|
|
Thanks Natan. Sorry for the late reply -- i got swamped with other things for a few days.
I'll look into learning the stuff. I had trouble with XUL as well, however, thanks to a couple of resources online, I could get basic stuff to work. If you like I'll get you some useful links -- since this is an ATL forum, I'll avoid posting them here.
ATL does seem a little involved... I guess it'll take me a bit of getting used to the syntax and conventions.
|
|
|
|
|
I use STL at work, but "lazy" way, i.e. it works, and who cares about performance, right ? So I know only basics about STL. Now I'm currently writing heavily multithreaded program for my own good. For the sake of fast development at this stage I opted to use STL. And then I noticed during debugging, that STL iterators call Critical Section locking, which causes a lot of slow down. I then delved (very briefly) into STL code and saw that they are really using CS for the iterators. I immediately dropped STL from the project, thanks to the fact that I use only arrays, not lists or maps, and there are plenty straight-forward-no-hidden-things implementations of templated arrays out there. But now I'm curious: when exactly STL iterators use CS locking? Is it for non-const iterators only? Is it for in-between-threads access? Or always? I'm too lazy and too busy to dive deep into STL code to check this, and it's not relevant to the project anymore, but out of curiosity it is very interesting, and might be useful for others who strive for performance and use STL.
Thank you in advance!
P.S. Forgot to mention: I use MS implementation of STL (VC++ 2005).
SY-
Kosta.
|
|
|
|
|
As far as I know STL does not do any critical section locking as that is left up to the application developer. We use STL (STLPort) extensively for high-performance server-side applications and find its performance outstanding.
As far as thread safety goes I would look at the Adapative Communication Framework (ACE). This library has reader/writer locks so readers don't block each other accessing a cache but a write blocks all readers. If you have a cache that is primarily read-only then this is quite and efficient mechanism.
Pax Domini sit semper vobiscum
|
|
|
|
|
I think I (almost) found answer to my own question.
Here is code:
#if _HAS_ITERATOR_DEBUGGING
void _Orphan_range(pointer _First, pointer _Last) const
{ // orphan iterators within specified (inclusive) range
_Lockit _Lock(_LOCK_DEBUG);
const_iterator **_Pnext = (const_iterator **)&this->_Myfirstiter;
while (*_Pnext != 0)
if ((*_Pnext)->_Myptr < _First || _Last < (*_Pnext)->_Myptr)
_Pnext = (const_iterator **)&(*_Pnext)->_Mynextiter;
else
{ // orphan the iterator
(*_Pnext)->_Mycont = 0;
*_Pnext = (const_iterator *)(*_Pnext)->_Mynextiter;
}
}
#endif /* _HAS_ITERATOR_DEBUGGING */
It's all over STL code, but it looks like locking happens only during 1) Debug Mode and 2) MultiTreaded application.
|
|
|
|
|
hi!
i want to use an activex control in my ATL project, i don't use MFC in this project(ATL Project). how do i do this?
must the activex be a Windowless?
Is there any sample to use an activex in ATL Project?
Zo.Naderi-Iran
|
|
|
|
|
If you're putting it in a dialog, use CAxDialogImpl to implement the dialog instead of CDialogImpl . Here's an example - it encapsulates a dialog that instantiates the Web browser ActiveX control as 'IDC_ABOUT':
#include <exdispid.h>
class CAboutDlg: public CAxDialogImpl<CAboutDlg>,
public IDispEventImpl<IDC_ABOUT, CAboutDlg, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>,
{
public:
CAboutDlg();
virtual ~CAboutDlg()
{
if (pWbAbout_)
{
BrowserDispEventImpl::DispEventUnadvise( pWbAbout_ );
}
}
typedef IDispEventImpl<IDC_ABOUT, CAboutDlg, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1> BrowserDispEventImpl;
enum {IDD = IDD_ABOUTBOX};
BEGIN_MSG_MAP(CAboutDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
END_MSG_MAP()
BEGIN_SINK_MAP(CAboutDlg)
SINK_ENTRY_EX(IDC_ABOUT, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)
END_SINK_MAP()
private:
LRESULT OnInitDialog(UINT , WPARAM , LPARAM , BOOL& )
{
CenterWindow();
aboutMessage_ = GetDlgItem(IDC_ABOUT);
CComPtr<IAxWinAmbientDispatch> spHost;
HRESULT hr = aboutMessage_.QueryHost(IID_IAxWinAmbientDispatch, (LPVOID*) &spHost);
if(SUCCEEDED(hr))
{
spHost->put_AllowContextMenu(VARIANT_FALSE);
spHost->put_DocHostFlags(DOCHOSTUIFLAG_DIALOG | DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_DISABLE_HELP_MENU);
}
if (SUCCEEDED(aboutMessage_.QueryControl(&pWbAbout_)) && pWbAbout_)
{
if (FAILED(BrowserDispEventImpl::DispEventAdvise ( pWbAbout_ )))
{
pWbAbout_ = 0;
}
else
{
pWbAbout_->put_RegisterAsBrowser(VARIANT_FALSE);
pWbAbout_->put_RegisterAsDropTarget(VARIANT_FALSE);
pWbAbout_->put_AddressBar(VARIANT_FALSE);
pWbAbout_->put_Offline(VARIANT_TRUE);
pWbAbout_->put_Resizable(VARIANT_FALSE);
pWbAbout_->put_Silent(VARIANT_TRUE);
pWbAbout_->put_MenuBar(VARIANT_FALSE);
pWbAbout_->put_StatusBar(VARIANT_FALSE);
pWbAbout_->put_ToolBar(VARIANT_FALSE);
CComVariant v;
pWbAbout_->Navigate(<default 'about' URL>, &v, &v, &v, &v);
}
}
return 0;
}
void __stdcall OnDocumentComplete(IDispatch* pDisp, VARIANT * URL)
{
}
CAxWindow aboutMessage_;
CComPtr<IWebBrowser2> pWbAbout_;
}; If you want your Active X control to be a window in a view, you just need to use CAxWindow, like so:
class CBrowserView : public CWindowImpl<CBrowserView, CAxWindow>
{
public:
CBrowserView() {}
virtual ~CBrowserView() {}
DECLARE_WND_SUPERCLASS(NULL, CAxWindow::GetWndClassName())
BEGIN_MSG_MAP_EX(CBrowserView)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
END_MSG_MAP()
private:
LRESULT OnCreate(UINT , WPARAM , LPARAM , BOOL& )
{
DefWindowProc();
CComPtr<IAxWinAmbientDispatch> spHost;
if(FAILED(QueryHost(IID_IAxWinAmbientDispatch, (LPVOID*) &spHost)) || !spHost)
{
OutputDebugString("CBrowserView::OnCreate - QueryHost failed\n");
return -1;
}
if (FAILED(QueryControl(&pWB2_)) || !pWB2_)
{
OutputDebugString("CBrowserView::OnCreate - QueryControl failed\n");
return -1;
}
return 0;
}
CComPtr<IWebBrowser2> pWB2_;
};
The type of Active X control created is specified when you call the Create method for the window - the window name is the ProgID or CLSID - see this page[^].
HTH!
|
|
|
|
|
hi,
edit: there is a short background explanation; but the problem is not outlook-specific
for an outlook-addin i need to get disp-events of outlook-items (IDispatch-based interface Outlook::ItemEvents)... which is fine as long as i just need the events of a fixed number of items (see below for a shortened code-example how i do it at the moment).
but now i need to connect to n items... and am as of yet clueless if there is a nice clean atl-way to do just that?
browsing the msdn-documentation for atl and googling didn't give me useful results so far
any hints and clues are appreciated.
class ATL_NO_VTABLE xyz :
...
public IDispEventSimpleImpl<1, xyz, &__uuidof(Outlook::ItemEvents)>,
...
{
...
typedef IDispEventSimpleImpl<1, xyz, &__uuidof(Outlook::ItemEvents)> MyItemEvents;
...
BEGIN_SINK_MAP(xyz)
SINK_ENTRY_INFO(
2,
__uuidof(Outlook::ItemEvents),
0xF006,
OnItemCustomAction,
&AtlCallDispatchDispatchBool
)
...
END_SINK_MAP()
...
}
modified on Friday, February 8, 2008 12:06 PM
|
|
|
|
|
Ummm - how about a simple object that encapsulates and inherits from a single 'IDispEventSimpleImpl<1, class-name, &__uuidof(Outlook::ItemEvents)> ', then have a collection of those, one for each object whose events you want to handle?
Can't think of a better way off the top of my head.
|
|
|
|
|
ah, sure... thanks. i guess i was just blind
|
|
|
|
|