|
hi everybody!
I want to use a _int46 integer as the key of STL hash_map. it seems ok when i declare the map object. But when i insert some values in the map,i get the following error
"
Error C2064: term does not evaluate to a function
c:\program files\microsoft visual studio\vc98\include\stl_hashtable.h(537) : while compiling class-template member function 'unsigned int __thiscall std::hashtable<struct std::pair<__int64 const ,int>,__int64,struct std::hash<__int64>,struct
std::_Select1st<struct std::pair<__int64 const ,int> >,struct std::equal_to<__int64>,class std::__default_alloc_template<0,0> >::_M_bkt_num_key(const __int64 &,unsigned int) const'
Error executing cl.exe.
"
Blew is the code that generate this error.
#include "stdafx.h"
#include <hash_map>
#include <stdio>
using namespace std;
int main(int argc, char* argv[])
{
_int64 int64a=88888;
hash_map<_int64,int> amap;
hash_map<_int64,int>::iterator iter;
pair<const>apair;
amap.insert(apair(int64a,33));
return 0;
}
please suggest what is the cause of error and how to avoid it.
|
|
|
|
|
It's pretty difficult to tell what your code is, because the angle brackets (< and >) have been interpreted as HTML tag delimiters.
Anyway - this works and is equivalent to your code. I'm using VS2008, where hash_map has been moved from std to stdext , but that's a cosmetic difference really:
#include <hash_map>
typedef stdext::hash_map<__int64, int> Map;
int main(int, char**)
{
Map map;
map.insert(std::make_pair(88888LL, 33));
}
Interpreting your code, I think the problem is apair(int64a, 33) . apair is an object, but you're using it as a function - that matches the error message ("Term does not evaluate to a function "). If you want to set apair 's value, do it in the constructor.
|
|
|
|
|
|
I have developed COM add-in for microsoft word.I am handling events of microsoft word like DocumentOpen, DocumentBeforeSave. In Open / save events, I am getting the content of an active document. But I am getting only text or only image or only tables at a time.
How to retrieve byte array pointer to the word document entire content irrespective of data type (image, string, and table).
Vijit P
|
|
|
|
|
Hello~~
In my code, I sink it. but, I get a "First-chance exception at 0x77f87eeb in MyIE.exe: 0xC0000005: Access violation reading location 0x00000024."
I don't know, how do to solve it...I need some help...Thanks~~
I post my code...
<br />
<br />
<br />
#include <windows.h><br />
#include <atlbase.h><br />
#include <atlwin.h><br />
#include <ExDispID.h><br />
<br />
const UINT ID_WEBBROWSER = 100;<br />
<br />
class CMainWindow : public CWindowImpl<CMainWindow>,<br />
public IDispEventImpl< ID_WEBBROWSER, CMainWindow ><br />
{<br />
public:<br />
CMainWindow()<br />
{<br />
CWndClassInfo &wci = GetWndClassInfo();<br />
<br />
if( !wci.m_atom )<br />
{<br />
wci.m_bSystemCursor = TRUE;<br />
}<br />
<br />
m_AxWindow = NULL;<br />
m_pWebBrowser2 = NULL;<br />
}<br />
<br />
virtual ~CMainWindow(){}<br />
<br />
<br />
BEGIN_MSG_MAP(CMainWindow)<br />
MESSAGE_HANDLER( WM_DESTROY, OnDestroy )<br />
MESSAGE_HANDLER(WM_CREATE, OnCreate)<br />
END_MSG_MAP()<br />
<br />
BEGIN_SINK_MAP(CMainWindow)<br />
SINK_ENTRY( ID_WEBBROWSER, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete )<br />
END_SINK_MAP()<br />
<br />
void __stdcall OnDocumentComplete( IDispatch *, VARIANT* )<br />
{<br />
<br />
}<br />
<br />
private:<br />
LRESULT OnCreate(UINT , WPARAM , LPARAM , BOOL& )<br />
{<br />
RECT rect;<br />
GetClientRect(&rect);<br />
HWND hWndContainer = m_AxWindow.Create( m_hWnd, rect, NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL, 0, ID_WEBBROWSER );<br />
<br />
if( !hWndContainer )<br />
return -1;<br />
<br />
HRESULT hr;<br />
hr = m_AxWindow.CreateControl( L"http://www.microsoft.com" );<br />
<br />
if( FAILED( hr ) )<br />
return -1;<br />
<br />
hr = m_AxWindow.QueryControl( IID_IWebBrowser2, (void**)&m_pWebBrowser2 );<br />
<br />
if( SUCCEEDED(hr) )<br />
{<br />
hr = AtlGetObjectSourceInterface( m_pWebBrowser2, &m_libid, <br />
&m_iid, &m_wMajorVerNum, &m_wMinorVerNum );<br />
<br />
if( FAILED(hr) )<br />
return -1;<br />
<br />
hr = DispEventAdvise(m_pWebBrowser2, &m_iid);<br />
<br />
<br />
if( FAILED(hr) )<br />
return -1;<br />
<br />
CComBSTR url = L"http://www.microsoft.com";<br />
<br />
hr = m_pWebBrowser2->Navigate( url,0,0,0,0 );<br />
<br />
if( FAILED(hr) )<br />
return -1;<br />
}<br />
<br />
return 0;<br />
}<br />
<br />
LRESULT OnDestroy(UINT , WPARAM , LPARAM , BOOL& )<br />
{<br />
if( m_dwEventCookie != 0xFEFEFEFE )<br />
DispEventUnadvise(m_pWebBrowser2, &m_iid);<br />
<br />
m_pWebBrowser2.Release();<br />
<br />
PostQuitMessage(0);<br />
return 0;<br />
}<br />
<br />
private:<br />
CAxWindow m_AxWindow;<br />
CComPtr<IWebBrowser2> m_pWebBrowser2;
};<br />
<br />
int APIENTRY _tWinMain(HINSTANCE hInstance,<br />
HINSTANCE hPrevInstance,<br />
LPTSTR lpCmdLine,<br />
int nCmdShow)<br />
{<br />
UNREFERENCED_PARAMETER(hPrevInstance);<br />
UNREFERENCED_PARAMETER(lpCmdLine);<br />
<br />
CMainWindow wnd;<br />
<br />
wnd.Create( NULL, NULL, NULL, WS_OVERLAPPEDWINDOW );<br />
<br />
if( !wnd )<br />
return FALSE;<br />
<br />
wnd.CenterWindow();<br />
wnd.ShowWindow( nCmdShow );<br />
wnd.UpdateWindow();<br />
<br />
MSG msg;<br />
<br />
while (GetMessage(&msg, NULL, 0, 0))<br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
<br />
return (int) msg.wParam;<br />
}<br />
compile code need to SET "Dynamic Link to ATL".
|
|
|
|
|
1) When does the exception occur.
2) Where does the exception occur (in the debugger, bereak on exceptions, get a call stack).
Difficult to advise without that information.
|
|
|
|
|
sorry...
when html download complete, exception occur.
code is set DOCUMENTCOMPLETE event, if set DISPID_BEFORENAVIGATE2, exception occur before open a url.
break in atlcore.h
HRESULT Lock() throw()
{
EnterCriticalSection(&m_sec); // here
return S_OK;
}
First-chance exception at 0x77f87eeb in 111.exe: 0xC0000005: Access violation reading location 0x00000024.
Unhandled exception at 0x77f87eeb in 111.exe: 0xC0000005: Access violation reading location 0x00000024.
Call Stack:
NTDLL.DLL!77f87eeb()
[Frames below may be incorrect and/or missing, no symbols loaded for NTDLL.DLL]
> 111.exe!ATL::CComCriticalSection::Lock() Line 87 + 0xc bytes C++
111.exe!ATL::CComCritSecLock<ATL::CComCriticalSection>::Lock() Line 336 + 0xa bytes C++
111.exe!ATL::CComTypeInfoHolder::GetTI(unsigned long lcid=0) Line 3757 + 0x8 bytes C++
111.exe!ATL::CComTypeInfoHolder::GetTI(unsigned long lcid=0, ITypeInfo * * ppInfo=0x0012f2cc) Line 3624 + 0xc bytes C++
111.exe!ATL::IDispEventImpl<100,CMainWindow,&GUID_NULL,&GUID_NULL,0,0,ATL::CComTypeInfoHolder>::GetFuncInfoFromId(const _GUID & iid={...}, long dispidMember=259, unsigned long lcid=0, ATL::_ATL_FUNC_INFO & info={...}) Line 4455 + 0x17 bytes C++
111.exe!ATL::IDispEventSimpleImpl<100,CMainWindow,&GUID_NULL>::Invoke(long dispidMember=259, const _GUID & __formal={...}, unsigned long lcid=0, const _GUID & __formal={...}, tagDISPPARAMS * pdispparams=0x0012f5c4, tagVARIANT * pvarResult=Empty, const _GUID & __formal={...}, const _GUID & __formal={...}) Line 4160 + 0x20 bytes C++
SHLWAPI.DLL!70ab88ba()
SHLWAPI.DLL!70ab883c()
SHLWAPI.DLL!70ab8935()
SHLWAPI.DLL!70ab89a7()
SHDOCVW.DLL!71752356()
SHDOCVW.DLL!7177deec()
SHLWAPI.DLL!70ab9669()
SHDOCVW.DLL!7177f819()
SHDOCVW.DLL!717a9f58()
SHDOCVW.DLL!7178b877()
OLE32.DLL!7cf15552()
SHDOCVW.DLL!71752ebe()
SHDOCVW.DLL!71722a2a()
SHDOCVW.DLL!71722bbb()
MSHTML.DLL!636a19cb()
MSHTML.DLL!63630901()
MSHTML.DLL!6367b7f1()
MSHTML.DLL!6362af7a()
MSHTML.DLL!63630e77()
MSHTML.DLL!6366fe64()
MSHTML.DLL!636f7c10()
MSHTML.DLL!636f7c10()
MSHTML.DLL!636f72a0()
MSHTML.DLL!636f85c3()
MSHTML.DLL!636f61ed()
MSHTML.DLL!636f7c10()
MSHTML.DLL!636aa379()
MSHTML.DLL!636f79b0()
MSHTML.DLL!63700394()
MSHTML.DLL!6370613c()
MSHTML.DLL!63706186()
MSHTML.DLL!637068c2()
MSHTML.DLL!637050db()
MSHTML.DLL!636fe9b0()
MSHTML.DLL!636f7c10()
MSHTML.DLL!636f64a8()
MSHTML.DLL!636f85c3()
MSHTML.DLL!636ff440()
MSHTML.DLL!636fe742()
MSHTML.DLL!63700fda()
MSHTML.DLL!63700fe2()
MSHTML.DLL!6361b66d()
MSHTML.DLL!6361b75b()
MSHTML.DLL!635f1b4c()
MSHTML.DLL!635f0b47()
MSHTML.DLL!6362af7a()
MSHTML.DLL!635f10cf()
MSHTML.DLL!635ee01b()
MSHTML.DLL!635f1df3()
MSHTML.DLL!6366f373()
MSHTML.DLL!636adff6()
MSHTML.DLL!636ae211()
MSHTML.DLL!636a8bf0()
MSHTML.DLL!636a8bf0()
MSHTML.DLL!636a8bf0()
MSHTML.DLL!636a8bcc()
MSHTML.DLL!636a8bd6()
MSHTML.DLL!636a8bcc()
MSHTML.DLL!636a8bd6()
MSHTML.DLL!63781cfa()
MSHTML.DLL!63780ae0()
MSHTML.DLL!6378109c()
MSHTML.DLL!637834be()
MSHTML.DLL!63783586()
MSHTML.DLL!63783588()
USER32.DLL!77e1a454()
USER32.DLL!77df4605()
USER32.DLL!77dfea4e()
USER32.DLL!77dfea5e()
NTDLL.DLL!77f91baf()
USER32.DLL!77dfa7f2()
111.exe!wWinMain(HINSTANCE__ * hInstance=0x00400000, HINSTANCE__ * hPrevInstance=0x00000000, wchar_t * lpCmdLine=0x000208aa, int nCmdShow=1) Line 149 + 0xf bytes C++
111.exe!__tmainCRTStartup() Line 578 + 0x35 bytes C
111.exe!wWinMainCRTStartup() Line 403 C
KERNEL32.DLL!77e889d5()
NTDLL.DLL!77f85c09()
|
|
|
|
|
Are you running in debug mode or release mode - 'cause that looks like a null pointer that would be checked by an assertion in debug mode. The Access violation reading location 0x00000024 indicates attempting to reference a structure member through a null pointer.
Anyway - have you set a LIBID in your ATL _Module (or _AtlModule or whatever it's called). I think you might get an access violation at the point where you're getting one if you haven't. You'll have a NULL type holder pointer, I think.
|
|
|
|
|
in debug mode...
I have know a null pointer in breakpoint, but that is ATL inline code...I cann't control call a null pointer...
I think I sink event is in wrong way, but what is right?
thanks~~
|
|
|
|
|
King_jinjing wrote: I think I sink event is in wrong way, but what is right?
Your sink code looks OK to me - I built a small trial application yesterday, using your code, and it loaded the web page OK and called the event handler as expected.
I used Visual Studio 2003 - which are you using?
I'll have another look at it on Monday - I don't have access to a Windows machine except at work, and I certainly won't be there over the weekend.
|
|
|
|
|
OK....
I use VS2005...WIN2000...I have to upload my Solution file?
I think, I have try other way again.. Today, I compile a WTL webbrowser example with web event, that work is OK.
Thanks.
|
|
|
|
|
I think your problem is that you haven't defined an ATL 'module' object. ATL tries to reference the module object in the CComTypeHolder::GetTI method (when it's locking the critical section), so if you haven't defined one, it'll crash there.
Here's what I have in place of your WinMain :
class CHostActiveXModule : public CAtlExeModuleT<CHostActiveXModule>
{
public :
CMainWindow m_wndMain;
HRESULT PreMessageLoop(int nCmdShow)
{
m_libid = LIBID_ATLLib;
HRESULT hr = CAtlExeModuleT<CHostActiveXModule>::PreMessageLoop(nCmdShow);
if (SUCCEEDED(hr))
{
AtlAxWinInit();
hr = S_OK;
RECT rc;
rc.top = rc.left = 100;
rc.bottom = rc.right = 500;
m_wndMain.Create(NULL, rc, _T("Host Calendar") );
m_wndMain.ShowWindow(nCmdShow);
}
return hr;
}
HRESULT PostMessageLoop()
{
AtlAxWinTerm();
return CAtlExeModuleT<CHostActiveXModule>::PostMessageLoop();
}
};
CHostActiveXModule _AtlModule;
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int nShowCmd)
{
return _AtlModule.WinMain(nShowCmd);
}
|
|
|
|
|
Oh~~~OK~~I got~~~~
It's very very very very powerful~~
Right,I haven't defined an ATL 'module' object...
Thanks,very very very much..
You solve my problem.
|
|
|
|
|
Hi,
I would like to learn about services and searched for the articles. But none of them were useful to me. Some of the articles are in fact nice, but not for a beginner like me . I would like to know about 1) what services are 2) where they can be used 3) how to use ATL Com AppWizard to create the service using Service(Exe) server type 4) A simple example (almost all the ones I have gone through today are looking like small projects, making the things more complicated for me to understand)
Could anyone post some nice article regarding this?
Thanks in advance.
Taruni
|
|
|
|
|
Taruni wrote: (almost all the ones I have gone through today are looking like small projects, making the things more complicated for me to understand)
That is because complex problems are solved by simplifying them into their constituent parts and solving the smaller problems. You are not likely to find a single example that walks through from your start to your end. That need is specific to you.
Taruni wrote: I would like to know about 1) what services are
This would be a good place for you to start[^]
led mike
|
|
|
|
|
std::vector<myclass> vec;
MyClass & get_selected()
{
std::list<myclass>::iterator it=vec.begin();
for (;it!=vec.end();++it) {
if (it->is_selected())
return &*it;
}
return NULL;
}
|
|
|
|
|
followait wrote: Is it the address of the element in the vector,
and is it safe?
Yes, &*it is the address of the vector element that the iterator refers to.
Whether it's "safe" or not depends on what you mean by "safe".
It is safe regarding if the address returned really is the address of the contained element.
But considering that you are handing out a non-const pointer or reference to the object, the caller may change it at will. This could of course be considered as "not safe" in some way.
However, your code snippet doesn't seem to compile correctly.
In your function declaration you say that the return type is a reference to a myclass object, but you actually return a pointer to it unless you've omitted something important. The return statement should read 'return *it; '.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Design suggestion: you're probably better off following what the STL algorithms do in this case, and return an iterator:
std::vector<myclass> vec;
std::vector<myclass>::iterator get_selected()
{
for (std::vector<myclass>::iterator it=vec.begin();it!=vec.end();++it)
{
if (it->is_selected())
return it;
}
return vec.end();
}
or even use the algorithms provided in the STL...
std::vector<myclass> vec;
std::vector<myclass>::iterator get_selected()
{
return std::find_if(vec.begin(), vec.end(), std::mem_fun_ref(&myclass::is_selected));
}
|
|
|
|
|
|
I think you can't save this address, for example as a class member.
If you add new elements to the vector it may need additional memory,
which means he must allocate new memory for the whole vector and copy
all his data. So every address to the old memory will be invalid
afterwards.
|
|
|
|
|
Even if you change to returning an iterator, be careful about doing any operations that invalidate the iterator.
|
|
|
|
|
I tried to follow the naming convention of STL, but encounter a problem.
For example:
class round_rect
{
...
}
Sometimes, in the context, I need no special object name,
I tried to name it as round_rect, so it became:
round_rect round_rect;
I want to know how STL name this?
BTW: google suggests RoundRect , but if I want to keep the naming convention consistent,
the member function also need capital letters. However I prefer the STL way.
|
|
|
|
|
the_round_rect ?
See, that's why I like Camel-Casing things. I'd have this:
class RoundRect
{
...
};
RoundRect roundRect;
All hail the case-sensitivity of C++!
|
|
|
|
|
Hi I have an ATL plugin which needs to receive the "WM_DISPLAYCHANGE" message, when windows resolution changes.
I've added a handler as follows
class ATL_NO_VTABLE CWebPluginControl :
public CComObjectRootEx<ccomsinglethreadmodel>,
public IDispatchImpl,
public IPersistStreamInitImpl<cwebplugincontrol>,
public IOleControlImpl<cwebplugincontrol>,
public IOleObjectImpl<cwebplugincontrol>,
public IOleInPlaceActiveObjectImpl<cwebplugincontrol>,
public IViewObjectExImpl<cwebplugincontrol>,
public IOleInPlaceObjectWindowlessImpl<cwebplugincontrol>,
public ISupportErrorInfo,
public IPersistStorageImpl<cwebplugincontrol>,
public ISpecifyPropertyPagesImpl<cwebplugincontrol>,
public IQuickActivateImpl<cwebplugincontrol>,
public IDataObjectImpl<cwebplugincontrol>,
public IProvideClassInfo2Impl<&CLSID_WebPluginControl, &DIID__IWebPluginControlEvents, &LIBID_WebPluginLib>,
public IObjectSafetyImpl<cwebplugincontrol,>,
public IConnectionPointContainerImpl<cwebplugincontrol>,
public IConnectionPointImpl<cwebplugincontrol,&diid__iwebplugincontrolevents>,
public IPropertyNotifySinkCP<cwebplugincontrol>,
public IPersistPropertyBagImpl<cwebplugincontrol>,
public CComCoClass<cwebplugincontrol,>,
public CComControl <cwebplugincontrol>,
public CProxy_IWebPluginControlEvents<cwebplugincontrol>
...
CWebPluginControl();
~CWebPluginControl();
BEGIN_MSG_MAP(CWebPluginControl)
...
MESSAGE_HANDLER(WM_DISPLAYCHANGE, OnDisplayChange)
...</cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></cwebplugincontrol></ccomsinglethreadmodel>
But my OnDisplayFunction never gets hit when i change resolutions. So my question is, does IE(using IE 7) forward this message? If so why am I not able to pick it up?
Thanks for your time,
Chris
|
|
|
|
|
The evidence certainly points to 'no', doesn't it?
The easiest way to check is to stick a conditional breakpoint on the BEGIN_MSG_MAP(CWebPluginControl) line, set to trigger when WM_DISPLAYCHANGE is received (looking at the definition of the BEGIN_MSG_MAP macro in atlwin.h , the message ID is sent in the parameter uMsg ). If this doesn't trigger, then you could use Spy++[^] or Winspector[^] to confirm that IE is receiving WM_DISPLAYCHANGE.
One possible work-around - check the screen resolution in each message handler and react appropriately when you detect a change. I would have thought that you'd get a WM_PAINT pretty soon after the resolution change, which you could use as a trigger.
|
|
|
|
|