|
I have a CString array called abc[10000]. This array is initialized in a OnOK() with value "none". However, when I begin a thread, and this thread called another function "testing()".......the array becomes empty.....so i got error message when I access this array in testing().
I've tried to declared this array in stdAfx.h and .cpp, and also its own .h file....but doesn't work too.........
Please help.....
p.s.: I got the similar problem when i use vector array (that's why i choose to declare abc array to abc[10000].)
|
|
|
|
|
I figure out myself....just a stupid mistake. I should declare the array in StdAfx.h/cpp.
|
|
|
|
|
Hi,
I have an application which I open a dialog box. The dialog box has a button IDC_ANALYSIS with the message handler onOpenanalysis which when pressed opens another dialog box using:
void CEpgActive::OnOpenanalysis()
{
CEpgAnalysis dlgEpgAnalysis(this);
int nRetCode = dlgEpgAnalysis.DoModal();
}
How can I modify this code (if this is the code i should modify!) can I get it so that the 1st dialog is cleared from the screen and only the second dialog is displayed?
Thanks a lot in advance,
Joe
|
|
|
|
|
void CEpgActive::OnOpenanalysis()
{
ShowWindow(SW_HIDE);
CEpgAnalysis dlgEpgAnalysis(this);
int nRetCode = dlgEpgAnalysis.DoModal();
ShowWindow(SW_SHOW);
}
Nish
Oh, I don't know why she's
leaving, or where she's gonna go
I guess she's got her reasons but I just don't wanna know
'Cos for 24 years I've been living next door to Alice
24 years just waitin' for a chance
To tell her how I feel and maybe get a second glance
Now I gotta get used to not living next door to Alice
|
|
|
|
|
Please help me . . .
I have a very simple Question. I want to use MSFlexGrid from Windows API, C++. I can not use VC++ and also VC editor.
From where I am find sample on that.
Thanx in advance.
|
|
|
|
|
I have a time-consuming thread about mathmatics processing.
I do not want to just wait for its ending.
I created a user-interface thread.
CWinThread *pProcThread = AfxBeginThread(RUNTIME_CLASS(CProcThread));
After I started the thread, I found the thread almost took all CPU's time.
I can't do anything, except closing it.
Can anyone guide me a right way?
Thanks.
Windows2000 SP2, VC++ 6.0 SP5
|
|
|
|
|
It sounds like you've got a tight loop in the theaad somewhere, such as:
while(TRUE)
{
// Nothing happens here to give up the cpu
// spins back to top of loop
}
Take a look at any looping you're doing in the thread, and throw in a Sleep() call before you come back aournd to the top of the loop to give up the cup to the next thread.
Sleep(0) will allow the next thread to get some action without a detrimental effect on your performance in the loop. That will probably suffice if this is your problem. If you sleep for an actual amount of milliseconds, keep in mind that in 9x, your minimum granularity (quanta) is 55 milliseconds (I may be off by a couple of milliseconds on the 9x number, been a while) and under NT it's 10 milliseconds, so even if you call Sleep(1), what you'll get will be these minimum slices depending on the platform.
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|
|
The mathmaics process program is from a dll call.
I can't put any sleep() call into it.
It costs about 2-3 seconds per call(depending on the performance of the
computer). My program has to call 100-400 times.
What shall I do?
Windows98 SE, VC++ 6.0 SP5
|
|
|
|
|
If you want to gain some more responsiveness from your UI thread, at the cost of increasing the time taken by the worker thread, lower the priority of the latter by using SetThreadPriority . For best results, create the thread in suspended mode, set its priority and then resume it.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Well, it's a little unclear from your previous post exactly what/where the problem is, so more details would be helpful. If what you're saying is that the cpu shoots to 100% utilization for 2-3 seconds each time you make a call to your math library dll (assuming it's not your code but a third party add on), then you're screwed - call their tech support and see if maybe there's something incorrect in how you're calling it. Yeah, I know, not the answer any of us ever want to hear, but if that's the case then you have to talk to the people who wrote that code.
If the dll you're calling is your own code, then of course you can look for tight looping in the dll function that you're calling.
If the problem is not 100% cpu utilization for 2-3 seconds every time you make that dll call, could you please be more specific about what you're experiencing?
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|
|
Thank you.
I have some simple questions:
1. How to change a tight loop into a loose one?
My codes:
for (int i = 0; i < nTimes; i++)
{
Mathmatics call(); // 100% CPU utilization for 2-3 seconds per call. It's from a third party.
}
2. What I want to do is just lowering this thread's CPU utilization or making it run background. What shall I do?
3. Can suspended mode thread work?
4. If all of above failed, any further suggestion for me or the 3rd party?
|
|
|
|
|
RichardWdy wrote:
1. How to change a tight loop into a loose one?
My codes:
for (int i = 0; i < nTimes; i++)
{
Mathmatics call(); // 100% CPU utilization for 2-3 seconds per call. It's from a third party.
}
Try this:
for (int i = 0; i < nTimes; i++)
{
// you're screwed for 2-3 seconds, but...
Mathmatics call();
// this will give the other threads a fighting chance
Sleep(0);
// if you're using overlapped i/o and want your
// thread to be alertable, you'd use SleepEx(0, TRUE);
}
RichardWdy wrote:
2. What I want to do is just lowering this thread's CPU utilization or making it run background. What shall I do?
Use AfxBeginThread instead of beginthread to kick off your thread - one of the parameters is the priority, which defaults to THREAD_PRIORITY_NORMAL.
RichardWdy wrote:
3. Can suspended mode thread work?
I'm not really sure what you mean by this, but you can start the thread in the paused state by using the CREATE_SUSPENDED flag, and then call ResumeThread() when you're ready to let it go. Use the thread handle in the CWinThread* that you get back in the call to ResumeThread() or any other thread API, e.g. ResumeThread(pThread->m_hThread).
RichardWdy wrote:
4. If all of above failed, any further suggestion for me or the 3rd party?
From the looks of that for loop, there's at least the possiblity that the problem is not in the math call. A loop like that is going to redline the cpu all on its own. Try putting that sleep in there first and see if that solves the problem. If the math call truly is causing 100% cpu utilization for 2-3 seconds, it's a tech support issue. However, if it's a small enough company that you can talk to the developers, you might suggest that they too implement some Sleep(0) calls to give up the cpu periodicially. By the way, Sleep(0) seems like it wouldn't pause at all, and it doesn't. What it does, however, is tells Windows that you're thread is ready to give up the rest of its time slice to the next waiting thread, kinda like Yield() in the old 16 bit Windows days.
Hope this helps!
Chistopher Duncan
Author - The Career Programmer: Guerilla Tactics for an Imperfect World (Apress)
|
|
|
|
|
Like Chris said, just set the threads priority low. IMHO, there is little point in playing games with Sleep. Just set the priority of the thread low and let the OS do it's job. If nothing else requires CPU, the math thread will get 100% of CPU which is exactly what you want. There is no point sleeping the thread when nothing else needs the CPU. However, since the thread has a lower priority, if pratically any other thread requires the CPU, they will get it.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
I remember I have seen some really indepth articles on DLLs, all the types and also when to auto load and when to load it explicitly. However, I searched Codeproject and did not find too much. I want to make my FIRST attempt. I want to include a class and ALL its resources in a DLL. Can anyone point me to ALL the articles?
I also read that when you change or add to a DLL then you have to recompile everything and relink. Is this also true if you are only changing an internal functions but not its calling method. I mean f(x,y,z)... This stays the same. Only now it is x-y+z instead of maybe x+y+z. Will this tpye of situation require the not only redistributing the DLL but also a new exe?
Thanks in advance.
|
|
|
|
|
As for the first question, do a search here at CP, there are some articles that will help you get started.
With respect to your second question: What you call "its calling method" is usually referred to as the signature of the function. You can see the set of signatures exported by a DLL as a contract between the DLL and the programs using it. Everything will be OK as long as the contract is respected by both parts. The following situiations can arise:- You preserve the signature of the exported functions but change its internal implementation: programs won't broke if the observed behavior of the exported functions stays more or less the same. For instance, if you rewrite a function to improve its efficiency. In this case, you'll need to redistribute the DLL only.
- The signature of the exported functions change: For instance, you change a
f(int) to be a f(double) . In this case you have to rebuild the programs using the DLL and resdistribute bouth the DLL and the EXEs affected.
- You maintain the signatures of the functions exported and add new functions to the DLL: old programs will work OK regardless of whether they're using the old or the new DLL. Programs taking advance of the new functions will need the new DLL, of course.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
The Subject tells you what I'm asking for.
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
What's your IP? I'll try pinging it from here.
Some ISPs block ping at the gateway though...
Nish
Oh, I don't know why she's
leaving, or where she's gonna go
I guess she's got her reasons but I just don't wanna know
'Cos for 24 years I've been living next door to Alice
24 years just waitin' for a chance
To tell her how I feel and maybe get a second glance
Now I gotta get used to not living next door to Alice
|
|
|
|
|
Check out Shields Up. It provides a quick test to see if any servers on your computer respond and it will also tell you which ports are open.
Josh Knox
that-guy.net
"Before you criticize someone, walk a mile in their shoes. That way, when you criticize them, you're a mile away, and you have their shoes." - author unknown
|
|
|
|
|
If you want to do it from a program, it's not possible. There's no way to know if there's a firewall or router filtering away access to your IP.
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
hi,
What exactly are call back functions?
Mila
|
|
|
|
|
They are handler functions for an event.
The call backs will have a pre defined prototype.
We write a function using this prototype and pass it to some other function. Now whenever some particular event occurs or some message is sent or something like that, the call back function is called for each such event.
Nish
Oh, I don't know why she's
leaving, or where she's gonna go
I guess she's got her reasons but I just don't wanna know
'Cos for 24 years I've been living next door to Alice
24 years just waitin' for a chance
To tell her how I feel and maybe get a second glance
Now I gotta get used to not living next door to Alice
|
|
|
|
|
hi
when i use the right to left layout property in a dialog, the following error appeare:
undefined keyword or key name: WS_EX_LAYOUT_RTL
can any body help me.
Best Regards
|
|
|
|
|
I think that is a bug in VC6. The correct style to use would be WS_EX_LAYOUTRTL . Edit that by hand in the .rc file...
/moliate
|
|
|
|
|
hi
I edit this in the.rc but the error is still ocure.
Best Regards
|
|
|
|
|
Then the resource editor probably overwrites it again. Remove the style from the editor, and then edit the .rc file. Perhaps a better alternative would be to add the window style in OnInitDialog with ModifyStyleEx.
/moliate
|
|
|
|