|
Crap... I'm not getting this at all... Doesn't free ing make the string NULL ? How can I return/pass a null string? The only reason I'm using malloc() is to make the char* long enough to contain the other one... And, if I allocate only a certain amount of memory for a string, and I try to add something that's larger than that, why does it add it anyways without crashing? C is confusing... I'd be using C# if this app didn't require to work on DOS. But, hfry, why parse the file myself if the extension is always 3 chars? (plus the dot) Thanks you all!
And: VuNic, that code crashed Winders.
[edit] A few minutes later...
Now I really AM confused. If I only copy 8 characters, look at what I get:
is730enucrosoft é
...crosoft? Why is Microsoft involved here?! I got no "Microsoft" string in my whole freaking program!
But if I copy 9:
is730en
I have never been so confused in my life...
[/edit]
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
-- modified at 13:49 Tuesday 13th June, 2006
|
|
|
|
|
Exactly what is wrong with the code that I have provided?
The point is you shouldn't pass the pointer out, instead the caller should pass a buffer in. The caller has an option of creating a buffer on the heap or on the stack. If the caller creates the buffer on the heap using malloc, then he would also know that he has to free it.
Extensions are not always 3 characters.
I try to add something that's larger than that, why does it add it anyways without crashing
There is no reason why writing past an allocated buffer must cause a crash. It largely depends on what you happen to be writing over. If you are writing past an allocated buffer on the heap, fun things might happen in totally unrelated portions of your application that happen to be using that memory that you overwritten.
|
|
|
|
|
hmm.. well Kixdemp, I had to leave office fast and didn't read your problem well, I gave that answer with a rough Idea of your problem. Dont worry today I'll sit down for it. You would be able to do it certainly
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
|
|
|
|
|
hfry wrote: The point is you shouldn't pass the pointer out, instead the caller should pass a buffer in. The caller has an option of creating a buffer on the heap or on the stack. If the caller creates the buffer on the heap using malloc, then he would also know that he has to free it.
Oh... Now I understand why it's always done that way... Now, is that the source of the problem or can I leave that change (all my functions do it the other way...) for when I finish the program?
hfry wrote: Extensions are not always 3 characters.
In this program they are (*.mtx and *.000 thru *.fff)
VuNic: Alright!
Thanks you both!
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
Hi,
I am using Excel automation to plot the chart.I am not able to get a handle on the X-axis (primary), I already have a handle on the Chart (Because I can change the title/plot chart), I am trying to change X-axis property to Catagory(we can set X-axis to Automatic/Catagory/Time-Scale) using the following spinets
Axes axes;
lpDisp = chart.Axes( COleVariant((short)(2)), 1);
ASSERT(lpDisp);
axes.AttachDispatch(lpDisp);
////////////////Second way-------------------------
Axis axis;
lpDisp = axes.Item(2, 1);
ASSERT(lpDisp);
axis.AttachDispatch(lpDisp);
Does anyone know what I'm doing wrong?
Mike
|
|
|
|
|
Dears Sirs;
How can I make a color to my Formview
I learn my self
|
|
|
|
|
Talking in terms of VC7.0 or VS6.0?
In vc7.0 it's very easy just open the form view. Go to properties > Appearance >Backcolor and select your choice of color.
In am answering in the context because you asked for FormView
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
-- modified at 10:02 Tuesday 13th June, 2006
|
|
|
|
|
I am using Visual c++ PLease
|
|
|
|
|
Supposing you have an MFC application, I think you have to handle the WM_ERASEBKGND notification. Add a handler for this message in your frame class. Within the handler you will have a CDC object as a parameter. Use drawing functions to fill the frame with colour you prefer.
|
|
|
|
|
I don't see this handle : WM_ERASEBKGND
|
|
|
|
|
you can use WM_PAINT and use CPaintDC dc(this);
whitesky
|
|
|
|
|
Hi,
I m using Windows Timers in my application which has 4 threads. I need a separate timer for each thread. At most how many timers can I use in an application as in future I will update my application for 32 threads? Regards
Cyber Friend
|
|
|
|
|
Cyber Friend wrote: At most how many timers can I use in an application as in future I will update my application for 32 threads?
I'm not exactly sure. In any case, they are a limited resource. Check SetTimer() 's return value.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
The Following link have more about Timers which may resolve your problem for creating timers and limit for creating them.
Timers[^]
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
Windows resources are very precious. I recall one of the old applications in which the developer used around 20 timers, each to refresh different portion of the display. The refresh rate is 10-20 Hz. Whenever that program is run, it used up all 100% CPU. Of ocourse, the 20 timers have been later combined to one centralized, high-resolution timer.
In general, 4 threads should be fine, but I have concerns about 32 threads. The number does matter. Not just the number of timers, but also the number of thredas. Each thread (and timer) takes a lot of overheads. I don't know of your situation, but you might want to think again about the design.
- It's easier to make than to correct a mistake.
|
|
|
|
|
Hi,
Thanx for the repies from all of u.
Jun Du wrote: Whenever that program is run, it used up all 100% CPU. Of ocourse, the 20 timers have been later combined to one centralized, high-resolution timer.
Jun I m using timers first time in an application and dont know much about them. Can you plz mention the link of some article/tutorial about the usage of a "High-resolution timer", instead of so many timers.
Regards.
Cyber Friend
|
|
|
|
|
Search CodeProject for "multimedia timer".
- It's easier to make than to correct a mistake.
|
|
|
|
|
Hi,
Can I use one Central High-resolution Timer for all of my threads
(32 threads in future and currently 4).
Best Regards
Cyber Friend
|
|
|
|
|
IN a Dialog I have two CButton when i clicked on first button a loop starts. The requirement is when i click on second button it should break the loop. How i can communicate this to the loop. I tried Sleep so that i can check the status of common variable. But this variable is updatted only when the loop terminates. What will be the possible solution of my Problem.
|
|
|
|
|
Read up on threads here and here.
anilksingh wrote: I tried Sleep...
Using Sleep() with threads is usually a bad idea.
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
one thing that you can do is that create a static flag=false as a global variable.
now in the loop you can check that if the flag is set to true.
(You will set the flag to true when the second button is pressed.)
if the flag is set simply put return 0; in the block of code where you want the thread function to end.
Here's some code for you that is inside the thread function :
CMyDlg *test=(CMyDlg *)pVoid;
for(int i=0;i<1000;i++)
{
Sleep(10);
if(flag==true)
{
CString s;
s.Format ("%d",i);
AfxMessageBox("Thread stoping on "+ s);
return 0;
}
else
{
CString s;
s.Format ("%d",i);
test->m_number.SetWindowText (s);
}
}
return 0;
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
-- modified at 9:34 Tuesday 13th June, 2006
|
|
|
|
|
put the shared resource in crtical section (global varaible)dont use sleep
never say die
|
|
|
|
|
It was just to show the user. Afterall this was not a live example.
It was just to give the user the time to perform the inputs while the thread is running
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
The old way (Win16) of doing this was to pump messages in the loop so that the other button will respond to user input. Today, a worker thread would be what I would suggest.
Look up how to create a background thread using the links provided in the previous answer. While you can use a shared variable to terminate the thread, I would suggest looking into how "event" objects work with threads to get a feel for them and how they should be used.
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
Create an event handle (using CreateEvent). Pass that handle to the loop when you create it (its quite common to pass such objects in the LPARAM pointer used when creating a thread). When you need to terminate the thread, call SetEvent. Internally to the loop, you will use WaitForSingleObject with an appropriate timeout value (in your case, 0 would probably work since you just want to check to make sure it has already been set). If WaitForSingleObject returns WAIT_OBJECT_0, then your event was signaled and you should stop the loop.
Alternatively, you could create a boolean flag and put a critical section around every access. This works just as well, but is error prone (one access without a critical section breaks the entire system). The Event solution doesn't have that problem.
If you use Sleep in any application, you can pretty much be assured that your design is flawed. Using it in Multithreaded applications to try to manage synchronization between threads is worse than useless. Use proper thread synchronization techniques and you won't have issues.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|