|
Have you had a look to PostThreadMessage[^] ?
HTH,
K.
I hurt so bad inside
I wish you could see the world through my eyes
It stays the same
I just wanna laugh again
|
|
|
|
|
Hello to all.
I've checked this following article (http://www.cuj.com/experts/1906/hyslop.htm?topic=experts) at CUJ web site and decided to use it in my own application.
So here we go. I have managed to implement the factory inside a windows DLL. But i'm having weird problems with it. Mainly the genericFactory::create method.
This is how i've implemented it (with the modification that I use a pointer to a function with three std::string parameters) :
template <class manufacturedobj,="" typename="" classidkey="">
std::auto_ptr<manufacturedobj>
genericFactory<manufacturedobj, classidkey="">::create(const classIDKey &className,
const std::string& p1,
const std::string& p2,
const std::string& p3) const
{
std::auto_ptr<manufacturedobj> ret(0);
FN_REGISTRY::const_iterator regEntry=registry.find(className);
if (regEntry != registry.end())
{
ret = regEntry->second(p1, p2, p3);
}
return ret;
}
And in my client code this is how I call it :
std::auto_ptr<mysqltable> tbl(0);
tbl = genericFactory<mysqltable>::instance().create("HistoricalDataTbl", host, user, pwd);
-----------------------------------------------------------------------------------------------
When I trace inside the create method, the "ret" variable is fine and points to a valid MySQLTable object. BUT, when the function returns to the client code... I get an unhandled exception error. This error is generated inside the auto_ptr<>::reset() method. To be more precise, the "tbl" auto_ptr in the client code is supposed to be initialized with a NULL pointer but when getting back from genericFactory::create method the "tbl" pointer points to an invalid MySQLTable object.
The quilty code inside auto_ptr :
void reset(_Tp* __px=0) {
_Tp* __pt = this->get();
if (__px != __pt)
delete __pt; //offending line...
this->__set(__px);
}
So i'm currently puzzled has to why the "tbl" variable points to a bad MySQLTable object!?!?!?!
Any help would be greatly appreciated
Luc.
|
|
|
|
|
Well, your sample code doesn't look good since the template parameters were lost by the HTML translation. Try putting the code inside pre tags next time.
However, I did take a quick peek it and it seems like the problem is with your regEntry variable. It's a local variable which, I assume, is returning to you a pointer to a MySQLTable object via the second function which it created internally. My guess is that when the create function returns, regEntry goes away and so does the MySQLTable pointer that it was holding -- which is also in your ret variable. So ret is left holding on to a pointer which is no longer valid.
That's one guess, based on my complete lack of knowledge on FN_REGISTRY.
Another guess is that it has to do with how ret variable is being copied and freed when it gets returned. But it shouldn't be that since ret would be "released" before being copied to tbl , and then it would be freed with a NULL pointer -- should be no problem.
BTW, I noticed you're not using Microsoft's auto_ptr implementation, which doesn't even have a reset (at least not the one in VC6.0)
Regards,
Alvaro
Well done is better than well said. -- Benjamin Franklin
(I actually prefer medium-well.)
|
|
|
|
|
Here is how FN_REGISTRY is defined...
typedef std::auto_ptr<manufacturedObj> (*BASE_CREATE_FN)(const std::string&,
const std::string&,
const std::string&);
typedef std::map<classIDKey, BASE_CREATE_FN> FN_REGISTRY;
FN_REGISTRY registry;
And I use STLPort !!!
P.S. How come, after using the pre tags, that my "<" and ">" gets deleted !?!?!?
|
|
|
|
|
Hey there.. ive never created CEdits without the dialog editor.. now i am trying to create a bunch and have DoDataExchange() when they lose focus.. it doesn't look like DoDataExchange ever gets called in my view tho.. here is how i am creating my fields:
CEdit* pEdit = new CEdit;
pEdit->Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_AUTOHSCROLL,
CRect(10, 10, 110, 30), this, 1);
how can i make a field like this call DoDataExchange() when it gains focus? or better yet, how can i make it call a function when it loses focus? i only know how to use the BEGIN_MESSAGE_MAP and END_MESSAGE_MAP .. is there a way to make this message map dynamically?
thanks for the help
still a newb.. cut me some slack :P
-dz
|
|
|
|
|
I think you need to handle this using the OnCommand message if you have created a dynamic control.
Sara
|
|
|
|
|
|
I'm using MFC's and MDI`s,I can change the window style after the creation of the window?
|
|
|
|
|
Yes, some of the styles can be changed ( dependent on the Cwnd ( derived Cnwd ).
look at CWnd::ModifyStyle and CWnd::ModifyStyleEx
Max.
|
|
|
|
|
Thanks
|
|
|
|
|
Good morning,
I'm trying to have a small window to hover over my view (opengl ), following the mouse; a bit like a toolip, but needs to stay, not hide after a small delay.
so, I created a CWnd derived class with the text and all the trimmings, added _TrackMouseEvent to the view to be able to receive the WM_MOUSELEAVE and WM_MOUSEHOVER so that the window is shown only if the mouse is over the view's client.
It's working, but the display is bad, I have bad refresh.
I move the windows on the MouseMove of the view, it works ok, but it will, I think, trigger a redraw, so I get too much flicking ( even with double buffer ).
The question, is there way to make the hover window behave more like it was a overlay thing ?
Oh Bugger!, I'm just answering the question when writing this ... the parent window of the my Cwnd was bad ... much better ...
move on... just crazy programmer ... nothing to see ... move on ...
Max.
|
|
|
|
|
help me please, I am stucked here.
It's a very simple SDI application. I got it from MFC appWizard.
In the view class, I started a worker thread, which will be running until a flag is cleared. I made sure that the worker thread is ended before the program terminate, because I put a TRACE line before its return statement, and the line is outputed. But still, I got such info:
Detected memory leaks!
Dumping objects ->
thrdcore.cpp(166) : {97} client block at 0x00305BB0, subtype 0, 112 bytes long.
a CWinThread object at $00305BB0, 112 bytes long
Object dump complete.
To make it more annoying, this doesn't happen all the time. What can go wrong?
Any clue is appreciated!
|
|
|
|
|
As its a CWinThread object thats been leaked, you can either store the pointer when you create the thread or set the m_bAutoDelete member var to true so it deletes itself when the thread ends.
Roger Allen
Sonork 100.10016
In case you're worried about what's going to become of the younger generation, it's going to grow up and start worrying about the younger generation. - Roger Allen, but not me!
|
|
|
|
|
Thank you for your quick help.
I set it, but it didn't solve the problem. anything else?
|
|
|
|
|
I noticed that after I rebuild the project then run it for the first time, this memory leak will occur for sure. The subsequent running doesn't have this problem. Why this inconsistence?
|
|
|
|
|
It seemed that after I add #include "StdAfx.h" to my generic cpp file, this problem is solved.
But in my generic cpp file, all I did is some mathematical computation. No input or output involved, except for the argument passing to the function.
What does StdAfx.h do here? Why I have to include it? It makes no sense to me.
|
|
|
|
|
Hi.
I read an interesting thread at a MSDN newgroup on MFC and thread safety. Its author asks about why a thread causes the process to hang when you pass to the thread points to MFC control objects (CListrCtrl, CEdit, CTreeCtrl, etc).
I remember something similar to what the author of thread asks from a application I just finished. I found that you can make changes to MFC controls from threads via pointers to the controls. Everything works well until you call WaitForSingleObject(), or WaitForMultipleObject(), etc. In other words, the process hangs if you call WaitForSingleObject() when the thread is updating an MFC control.
Ivan Lalis posted an interesting solution involving MFC controls handles. He writes that one solution is to pass in the worker threads handles to MFC controls instead of pointers.
-----
UINT theWorkerThread(LPVOID pParam)
{
CListCtrl theList;
theList.attach(handleToRealListbox);
...
theList.detach();
return 0;
}
-----
I would like to know what is the safest solution to this problem? Secondly, in terms of Lalis' solution, do you create and attach, for example, one CListCtrland for the entire life-time of the thread?
Thanks,
Kuphryn
|
|
|
|
|
Does anyone know how to print the German characters öäü to a line printer (Epson LX-300). I suppose I need to select a character set to do this, but somehow I can not manage to get it workin.
Thanks,
Richard
|
|
|
|
|
:-DI want to get the data from video card and store them as Bmp.Please tell me how to do? Thanks a lot!
thanks to every one!
|
|
|
|
|
Do you have the data from the video card?
How did you get it?
How you got the information and the format that it is currently stored in determines how you will save it.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
no, i have't the data ,i want to know how to get the data in it.which function in Visual c++ can get the data?
thanks!
|
|
|
|
|
The next question is do you want to save an image that is on the screen or in a window?
You will need to create a device context for either the desktop window or the window that you want to save.
AFter you have the DC look at this article:
http://www.codeproject.com/bitmap/dibsection.asp[^]
Good Luck
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
i want to screen capture to Bmp format.
|
|
|
|
|
Use avphone3 control:
'connect to driver
vidcap1.device = -1;
Sub Timer1_Timer()
SavePicture vidcap1.Picture, filename
End Sub
|
|
|
|
|
I get past one problem, and bump into another... Steep learning curve
I created a dialog with among other controls, a static control expanded to a size I can use to draw small plots in. I created my own plotting class derived from CStatic, and attached it to the static control in the dialog with ClassWizard. I built the functionality in my derived class to draw the plots, and now I'd like to handle some mouse move and click messages. For some reason, my CStatic derived class won't handle any of these messages. If I add a handler in the dialog, it does handle them. I've looked through the articles on subclassing controls, and I don't see where I'm missing anything. Can you give me some suggestions on where to look?
Thanks.
|
|
|
|
|