|
Thanks for the reply. I think I've figured it out.
I actually wasn't using CString, but rather a user-defined
class. Nonetheless, I seem to have figured it out.
The following apprears to work:
<br />
using std::vector;<br />
using std::endl;<br />
using std::sort;<br />
using std::partition;<br />
using std::less;<br />
using std::bind2nd;<br />
using std::ostream_iterator;<br />
using std::copy;<br />
using std::back_inserter;<br />
using std::vector<CSpring>;<br />
<br />
void CSpringSolver::DumpSprings()<br />
{<br />
vector<CSpring>::iterator itr;<br />
for (itr = SpringStack.begin(); itr != SpringStack.end(); ++itr)<br />
{<br />
itr->ShowSpring();
}<br />
}<br />
I just need to overload << (if possible)
|
|
|
|
|
So I've authored the activeX control using ATL and used the wizard to implement the connection point I added. Of course the wizard generated that header file, '<NameOfProject>CP.h', and in that header was the class: 'CProxy<INameOfDispInterface>Events'.
Now here's my dilema...
I want the event handler, that is a member function of the MFC dialog containing the control, to close and destroy the dialog. Unfortunately when that happens, the COleControlSite with the ATL control in it also get's destroyed, and then when the 'Fire_<Event1>' method returns from the call to 'pDispatch->Invoke' it tries to call release on the CComPtr it held pointing to the COleControlSite (which was just destroyed).........hence a memory access exception.
I'd love for someone to point out what I'm doing wrong, or perhaps another way to do this.
Ultimately all I care about is having an MFC dialog that can destroy itself based on some kind of event from a contained ATL control.
thanks,
nebbish
"The man who trades freedom for security does not deserve, nor will he ever receive either." -- Benjamin Franklin
|
|
|
|
|
I've created a toolbar for IE using ATL, and weird problem has showed up.
Everything is fine when I open up Internet Explorer and select View->Toolbars->mytoolbar, however, when i close IE after that and open it up again, there is only the first button visible on my toolbar.
When i hide my toolbar, restart IE and make toolbar visible (View->Toolbars->mytoolbar)everything is ok again (all the buttons do appear...), so the problem might be related somehow to IE initializing toolbars at startup...
Any comments?
Hannes Pahapill
|
|
|
|
|
Hi,
I have written a dll using ATL. In which I want to fire events from a call back function. When I tried to do that my program crashes.
So that I have implemented a hidden window (which I saw in an article in this site) and posting the message to that window. From there I fire the events. It is working quite fine.
But my problem is, when I closes the application which used my COM object, it crashes at the end. I cannot trace what is the problem.
I describe here step by step what I have written in my program..
1. This is the hidden window i have created..
// mywnd.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMyWindow window
class CClsRecord;
class CMyWindow : public CWnd
{
// Construction
public:
LRESULT OnFireEventForThread(WPARAM wParam, LPARAM lParam);
CClsRecord *m_pControl;
HWND Create();
CMyWindow(CClsRecord *pCtrl);
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMyWindow)
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CMyWindow();
// Generated message map functions
protected:
//{{AFX_MSG(CMyWindow)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
HWND CMyWindow::Create()
{
//Register a window class
LPCTSTR classname = 0;
classname = AfxRegisterWndClass(0);
//Create the window and return it's handle
CWnd::CreateEx(NULL,classname,NULL,NULL,1,1,1,1,NULL,NULL);
ASSERT(m_hWnd!=NULL);
return m_hWnd;
}
LRESULT CMyWindow::OnFireEventForThread(WPARAM wParam, LPARAM lParam)
{
CComBSTR bstr;
//This is a one-message-does-everything handler. If wParam is not
//set, that means our message has been sent to fire the even.
//If wParam is set that means we're being asked to destroy ourselves
if(!wParam)
{
if (lParam!=NULL)
{
bstr = m_pControl->GetEventMessage();
m_pControl->Fire_OnEvent(lParam,bstr.Copy());
}
}
else if(wParam==1)
DestroyWindow();
return TRUE;
}
void CMyWindow::PostNcDestroy()
{
//clean up this object
delete this;
}
2. In the ClsRecord class, I have created a thread like this
CMyWindow *pWnd = new CMyWindow(this);
HWND hwndTarget = pWnd->Create();
//create a thread for handling all the events
HANDLE threadHandle = CreateThread(NULL,NULL,
(LPTHREAD_START_ROUTINE)GetNextEventLoopInThread,
(LPVOID)hwndTarget,
NULL,
&Tid);
3. Now, I am sending the message to the window like this..
PostMessage(hWnd,WM_THREADFIREEVENT,(WPARAM)NULL,(LPARAM)CLS_END_CALL_EVENT);
4. Now I call the dll in a VB application. The events are getting fired without any problem. But when I close the vb application, my program crashes. If I use 'End' statement in VB also it crashes immediately.
I have absolutely no glue that what could be the probem? Is it because of a memory leak? Then how can I detect this?
Kindly help me..
Thanks in advance
with regards
Sivakumar R
|
|
|
|
|
Did you call CoInitializeEx(...) in both threads where you are accessing your object?
Don't forget to call also CoUninitialize() before the thread exits.
ÿFor the bread of God is he who comes down from heaven and gives life to the world. - John 6:33
|
|
|
|
|
hi all,
i want to write data to a text file...i am using ATL..and i dont have any idea about this..any help or pointers are higly welcome..please help me out..
thanks in advance..
himanshu
|
|
|
|
|
xxhimanshu wrote:
hi all,
i want to write data to a text file...i am using ATL..and i dont have any idea about this..any help or pointers are higly welcome..please help me out..
thanks in advance..
Why not use the regular fstream object of C++?
-Nick Parker
|
|
|
|
|
Hello,
My code looks like this:
struct CButton
{
COLORREF color;
BOOL select;
tagDRAWITEMSTRUCT pditag;
}MyCButton;
[helpstring("method DoOwnerButton")] HRESULT DoOwnerButton([in]DRAWITEMSTRUCT pstruct,int IID_BUTTON, TCHAR * Caption,int Wmessage,MyCButton pnew);
I am getting error:
error MIDL2025 : syntax error : expecting a type specification near "tagDRAWITEMSTRUCT"
Is that mean that I can not use Windows structure in idl file?
PLease answer as soon as you can
Tahnks in advance
Nena
Nena
|
|
|
|
|
Hello,
I want to use the latest collection classes from VC .NET so I chose hash_set . The collection is storing custom objects (not just plain int s) that have operator < . Can anyone show my how do define the hash_set and its corresponding hash_compare correctly?
Thanks
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
You only have to define operator < for your class:
class MyClass
{
public:
...
bool operator<(const MyClass& x)const
{
}
};
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I wish it were that easy....
I get C2440 error (cannot convert from const MyClass to size_t ). I think I must derive from hash_compare and implement custom hash method as the compiler does not know how to get a hash code for my objects...
Best regards,
Alexandru Savescu
P.S. Interested in art? Visit this!
|
|
|
|
|
This sounds strange. Could you post the code to see how you're using hash_set ? I think it should work once you defined operator < .
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Here's the code:
#include <iostream>
#include <hash_set>
using namespace std;
class MyClass
{
public:
int x;
MyClass (int a) : x (a)
{
}
bool operator < (const MyClass& OB) const
{
return x < OB.x;
}
};
int main ()
{
hash_set <MyClass> MySet;
MySet.insert (MyClass (2));
}
Best regards,
Alexandru Savescu
<small>P.S. Interested in art? Visit <a href="http://www.geocities.com/mirunadutescu" target="_blank"> this! </a></small>
|
|
|
|
|
I write a control for script, but I can't return more then one parameters:
[out] VARIANT param1,
[out] VARIANT param2,
[out,retval] VARIANT *pret
now only one parameter will return well, is that script can't accept method that have more output parameters?
|
|
|
|
|
First I have to say, I like WTL so far and have decided to create a control instead of using MFC, my only question is this...actually i think i know the answer, but i'm not sure how...
How do I include an WTL control (mycontrol.h) in an MFC project???
What steps are required...?
Thanks...
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
My project compiles and builds and runs fine for debugging but when I try to build the release version I get the following error. Anyone ever seen this before?
error C2065: '_AtlModule' : undeclared identifier
I should mention that I was able to build the release before without a problem, then one day this showed up. I'm not sure what is going on. TIA for any assistance.
Matt (Padawan Learner)
|
|
|
|
|
Hi all,
I have an application written in C++ using win32, it creates a few windows, has a menu etc. Nothing fancy. But it's becomming a major pain to add new windows, fancy controls and whatnot so I thought about using WTL instead of the raw API's.
Is that feasible? The app works fine right now so I would like to create the new windows using WTL, the existing may be converted in the future.
.Henrik
---
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
|
|
|
|
|
Yep, it's pretty easy.- Remove your include of windows.h; instead, include atlbase.h, atlapp.h, then whatever other ATL/WTL headers you need.
- Right after the atlapp.h include, add
extern CAppModule _Module; - In one of your CPP files, declare the global
CAppModule _Module; - At the beginning of
WinMain() , call _Module.Init(NULL, hInstance); (where hInstance is the 1st param to WinMain() ).
--Mike--
Eh! Steve!
Homepage | RightClick-Encrypt | 1ClickPicGrabber
"You have Erica on the brain" - Jon Sagara to me
|
|
|
|
|
Great, I'll give it a try.
Thanks for the info.
---
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
|
|
|
|
|
Hi All,
I am working on a Windows browser sort of a thing and building it in ATL domain. The problem I am facing is that I can't "Cut" a file from a given location. I have "Copied" a file and "Pasted" it but I don't know how to "Cut" a file.
Can anybody help me????
Best regards,
Pious.
|
|
|
|
|
Cut/Paste == Copy + Delete.
Copy from old location to new, then delete from the old location.
-Sean
----
Shag a Lizard
|
|
|
|
|
Is this a MS specific library?
For instance could I use WTL in say Bloodshed C++? I'm not sure if the ming(??) compiler supports templates or not?
Anyways, if I can use WTL in VC++ and bloodshed...that would be super...
Thanks
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
I believe ATL is MS-specific - I think it uses some MS extensions, such as __uuidof , in places. Looking at the WTL code, the only thing I can see (in a small sample of the code) is the use of #pragma once .
Best thing to do is to try compiling some WTL code and see what happens!!!!
If you're not tied to GCC, you could try the Borland or Watcom C++ compilers - they're both freely downloadable....
Stuart Dootson
'Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p'
|
|
|
|
|
How can I shift all the items on a stack up by one?
Item1
Item2
Item3
Item4
After shifting up by one you would have
Item2
Item3
Item4
Item5
Do I have to create a temp stack? Or is there any way I can access each item in the stack like vector? A quick hack maybe...I just think swapping the values (except index 0 which would overwritten) would be more efficient the creating a temp stack (or popping the values off into a vector, then copying the vector values over to the new stack)
Anyways...if I made myself clear and you understand what i'm trying to do...can this be accomplished???
Thanks
"Two wrongs don't make a right, but three lefts do!" - Alex Barylski
|
|
|
|
|
One solution is to use a list or a deque container that way you can add elements from both ends.
Kuphryn
|
|
|
|