|
Alexander M. wrote:
Don't try it, just do it!
Google does.
http://www.atsc.org/
Bikram Singh
|
|
|
|
|
Hello,
A quick question: Is it alright to use a CWinThread derived class to create a non User-Interface thread?
If it is, would it be okay to initialise AND execute whatever objects (classes) I need inside InitInstance ?
Thanks,
David
|
|
|
|
|
Straight answer: Yes, it is alright. Creating and executing objects in the CWinThread::InitInstance is ok as well.
Detailed:
To create a non-GUI (worker) thread, just create a function that will run on the thread (just like WinMain runs on the primary thread). Then call AfxBeginThread a pass it a pointer to the function. When you wish to end the thread execution, just return from the function.
You should use CWinThread objects only when you have a GUI thread. Although it is safe to use a CWinThread object with a worker thread, it's a waste of resources. Only use a CWinThread object if your new thread requires a message pump. If it doesn't need it, just create a function that executes on the new thread.
For more information, see AfxBeginThread in MSDN.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Straight answer: Yes, it is alright. Creating and executing objects in the CWinThread::InitInstance is ok as well.
But I heard something before....
Although it is safe to use a CWinThread object with a worker thread, it's a waste of resources.
Ahh, I see...
Only use a CWinThread object if your new thread requires a message pump.
Flawless explanation as usual, Antti. I thought there would be some sort of a considerable difference between using or not CWinThread , but I just didn't know what/how.
As usual, you've enlightened and pointed me in the rihgt direction.
Thanks a lot Antti,
David
dNimrod#X
________________________
|
|
|
|
|
This is a question, not a critism of your answer
AfxBeginThread returns a CWinThread pointer. So what is the difference if one uses a CWinThread derived class and simply returns FALSE from the OnInitInstance() function, or one calls AfxBeginThread() with a pointer to a function? Does not AfxBeginThread() end up creating a CWinThread object anyway, so how is one a bigger waste of resources than the other?
I have so far used AfxBeginThread() for small uncomplicated threads, and CWinThread derived classes for more complicated threads where I can group helper functions all within a class structure.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it!
|
|
|
|
|
There are other resources than those used by the code. Deriving, designing and implementing the CWinThread -derived class that is to operate as the GUI thread also takes time, which is a crucial resource in a software project.
As such, doing this process for a thread that wouldn't necessarily require it is a waste of time/resources, even though the impact shouldn't be considerable.
Writing a single function is easier, I think. However, this is more of a point-of-view issue than an actual problem, so let's just agree that both solutions are just as good to use
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi!
Is there a way to compile a library into a "static version" so that when you link to an application, it doesn't need an extra DLL?
For example, I would like to compile Ingo A. Kubbilun's code (http://www.codeproject.com/docking/IngoExpBar.asp) so that my application doesn't need the DLL to run properly.
Thks in advance!
Appstmd
http://www.atlence.com
|
|
|
|
|
Yes.
In Visual Studio .Net (2003), create a new Win32 project using the wizards. For Application Type, select "Static Library". Add MFC support if you need to. And off you go.
Not sure if this is possible in VC6. But in VC .Net it is.
-Antti Keskinen
----------------------------------------------
The definition of impossible is strictly dependant
on what we think is possible.
|
|
|
|
|
Hi,
Every body.
I would like to draw a control which you can find in windows 2000 Perofrmace tab. problem is that I have used a way like drawing into the bitmap and Bitblitting it.
But I don't want to use bitmap. Becuase It take so much of memory.
I tried to directly draw on to dialog box without using bitmap. But I have flickering problem.
Canany one help me out!!!
bye
Salman
Live and Let live
|
|
|
|
|
|
there is a FlexGrid in my dialog of my dll,I have exported a function for applicaiton, in the function I want to show dialog,buf failure. and I removed FlexGrid,it works well,why?
|
|
|
|
|
Im not aware what FlexGrid is, but there have been similar problems with MS Richedit control causing the dialog creation to fail. In this case, you were supposed to call AfxEnableControlContainer() , then all was well.
Maybe you should try calling AfxEnableControlContainer() or some other function, depending on what FlexGrid uses? Maybe InitCommonControlsEx() ?
Bikram Singh
|
|
|
|
|
it still does not work,what should I do
|
|
|
|
|
Search Google for a solution or post your project/core code where this problem occurs. If you do, be sure to test that the error still occurs before posting it !
Bikram Singh
|
|
|
|
|
I alse do it as follow,but it does not work
void __declspec(dllexport) __stdcall TestDialogClass(HWND hWnd,CString& name)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
AfxSetResourceHandle(theApp.m_hInstance);
AfxEnableControlContainer();
OleInitialize(0);
CTestDlg dlg;
dlg.m_strTest=name;
dlg.DoModal();
AfxSetResourceHandle(AfxGetInstanceHandle());
}
|
|
|
|
|
I have resolved it,codes as above.but I tried it in the morning ,it doesn't work well,now it starts to work, I really don't the reason
|
|
|
|
|
The code works fine for me... the problem is probably elsewhere in your dll/exe code...
Bikram Singh
|
|
|
|
|
thanks a lot,those codes work well now,but I don't know the reason that it doesn't work at the begin.
|
|
|
|
|
I want my VC program window run as the sidebar,what should I do ?
|
|
|
|
|
|
hello,
I need to parse a text file and take some tag as <cover href="url"> or , I need it to be written in C, do you think I better use an XML parser ( if yes, which one should I use?, I premitt that I've not got much experience with XML) or should I better so it sequentially by doing
<br />
if( strcmp(line,"<cover..............)???<br />
thanks in advance
Paolo
|
|
|
|
|
Easiest will be to process the input char-by-char. Use a state machine, switching states when you reach a '<' or a '>', adding the finished tags or between-tag-content to arrays as appropriate. As a matter of a fact, you should have state changes for spaces and '='s inside the tags as well.
|
|
|
|
|
You can use the static string parsing methods in this[^] article to do exactly that.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
A SAX-parser would probably be the best solution for you. They're fast and they don't require lots of memory. Parsing XML using SAX-parsers is kind of like recursive descent parsing if I'm not mistaken. When the parser finds an element <img , it'll call your callback, notifying you of that. Then when it finds href="img" , it'll call your callback notifying you of that. So, basically you need two (possibly three) callbacks. One for notifying you that you've <img has begun, one that tells you href="img" was found, and possibly one that says </img> .
Here's one such parser: libxml2[^]. It's licensed under the MIT License, so there's no problem using it in a closed source/commercial application.
--
Ich bin Joachim von Hassel, und ich bin Pilot der Bundeswehr.
Welle: Erdball - F104-G Starfighter
|
|
|
|
|
I'm trying to pass a value between property sheets in a CFormview.
From searching old comments in this forum, I read that the method is to use GetParent();
However this gets me the CMainframe window that doesn't appear useful for passing such variables.
Suggestions anyone ?
|
|
|
|