|
Hi, all:
There are some good oppotunity in Freeborders, we are search some Sr.C++ Engineer to join us, if you are interested in this position, please move your mouse to send me your CV to pandapam@126.com, maybe i can help you to get a good job!
Thank you for your attention, wish you a good luck.
|
|
|
|
|
Support!
|
|
|
|
|
This is not the right forum.
|
|
|
|
|
Hello,
I am new to the C++ language. How can I make a variable hold its value when enters the function the next time, I don't want to declare it as static, I was wondering how its handled in MFC. Here is the concept of what I want to do:
How can I hold the value of variable m_Val when it exits the function, doesn't reset to zero when it comes back in? (note, can't use static)
Thanks
Class A{
void DoFunction(....)
double m_Val;
...etc
};
void A::DoFunction(....)
{
....
m_Val = x^2/1000 ;
if(flag)
m_Val -= K;
....
}
int main()
{
....
For Loop timer every 15 msecs{
DoFunction(...)
}
}
sft
|
|
|
|
|
Not quite sure if I understand you sft.
Would you like the value of m_Val to be the same after a call to A::DoFunction(....) as it was before?
Or do you simply want m_Val to hold whatever is put into it until it is explicitly changed again?
If the answer is (a) the first one, use some code like this:
void A::DoFunction(....)
{
double m_Temp_Val = m_Val;
....
m_Val = x^2/1000 ;
if(flag)
m_Val -= K;
....
m_Val = m_Temp_Val;
}
If however, the answer is (b), you already have posted code that will allow the value of m_Val to persist, or remain until the next time you choose to change it. Since m_Val is a class member, it's value will remain until either (a) you re-assign a value to it by using the A::DoFunction member(assuming no other member functions modify the value held by m_Val), or (b) the class object is destroyed, either by going out of scope, or explicitly via a call to the delete function.
S.
|
|
|
|
|
Thanks for your explanation, my question was (b), and you are right, I had it working as posted.
I do have a seperate question, I would like to use a flag in MFC that will tell me if the computer/(OS) is using a 10 ms or 15 ms time slices... Is there a way I can find out what time slice does a computer have, or any other method to obtain this? I can use GetTickCount() to calculate the thread updates and find the time slice may be, but it doesn't sound too smart.
Thanks
sft
|
|
|
|
|
From the articles I'm reading, it seems that this should be reasonably easy to determine.
Quoting from Description of Performance Options in Windows[^],
The term "quantum" is a unitless measure of time for each time slice that a thread will run until a "context switch" occurs and another thread (either within the same program or from within another program) is selected to run. This prevents a CPU-bound process from monopolizing the processor. Currently in Windows, 3 quantums are equal to either 10 milliseconds (single processor) or 15 milliseconds (multiple-processor Pentium). This depends on the hardware abstraction layer (HAL) selected for your computer. Original Equipment Manufacturer (OEM) HALs may have a different value. Time slices that are fixed at 36 quantums are currently used when background services are selected (as you might choose in a typical server installation).
The situation become more complex when you enable the Foreground Applications option. This introduces the "variable quantum" concept. In this case, background tasks receive a different quantum than the quantums received by the foreground tasks. Also, both sets of quantums are shorter than a thread would receive on a computer set for background services. Currently, a background process receives a quantum of 3 and a foreground process receives a quantum of 9. Therefore, you can calculate the length of time the thread will run before its timer expires.
Soooo, it seems that all you have to do is determine if the running system contains a single processor, or multiple processors.
If you open up regedit, and take a look at
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WindowsNT\CurrentVersion , there is a key called CurrentType
On my Celeron D 2.66 Ghz, this has the value "Uniprocessor Free".
On my Pentium D 3.4 Ghz, this same key has the value "Multiprocessor Free"
Perhaps it really is as simple as that??! (hope so )
Simon.
|
|
|
|
|
Thanks again, but if I read that particular key from the registry, it will only work if all the strings are consistent on all computers, otherwise reading the 2 particular strings won't be good enough, correct?
sft
|
|
|
|
|
That's okay. Yup, got it in one. If these strings vary, then this method I propose would suck the big-one.
The only thing I can think of is to try it on a number of different machines, or see if anyone else around the net has anything to say about this (yeah, I know - sorry it's a disingenuous suggestion, but I can't think of any other ways to attack the problem right now)
Here's a page that mentions the key -
http://www.volny.cz/rootshell/hackistry.htm[^]
Hope it helps get you there.
S.
|
|
|
|
|
enhzflep wrote: On my Pentium D 3.4 Ghz, this same key has the value "Multiprocessor Free"
I have an Intel Core Duo that reports the same.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
I checked about 6 computers at work between single and dual, it looks to be consistent with your findings. Its good enough for me, I will read the values, if not consistent, I will default to either one of the two.
Thanks again
sft
|
|
|
|
|
Hi;
I have just started to use Dev C++. But I guess I just could not figure out how to use it because I have tried a very simple program, but it did not work. I have just one class
#include <iostream>
using std::cout;
using std::endl;
int main(){
cout<<"endl"<<endl;
return 0;
}
</iostream>
When I try to compile it; it gives the error:
[Linker error] undefined reference to `__cpu_features_init'
ld returned 1 exit status
I know this is gonna sound stupid. But I need some help here. Thank you.
|
|
|
|
|
Hmm, I seem to remember having this error once or twice before. I did solve it, though found the whole suite to be a little dated.
An alternative that I've since switched to that you may enjoy is Code::Blocks.
You can find it here: Code::Blocks download page[^]
(you'll probably want the one with MinGW included, as this simplifies setup)
|
|
|
|
|
im using this example to add a new resource to a PE file
http://www.codeproject.com/KB/cpp/UpdateResource.aspx[^]
well when i use this code or a pre defined file path on the compile the code works perfectly
hFile = CreateFile(L"C:\\Winnt\\System32\\calc.exe", GENERIC_READ, 0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
but if i use a cstring that holds the path of a file (it reads the path from a listview item) the program crashes
CString strFile = m_List.GetItemText(0,3)
hFile = CreateFile(strFile, GENERIC_READ, 0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
how can i fix this?
|
|
|
|
|
Evil_Inside01 wrote: the program crashes
Evil_Inside01 wrote: how can i fix this?
By writing code that handles exceptional conditions and reacts gracefully rather than crashing. You know how to do that correct?
led mike
|
|
|
|
|
no im still a beginner in cpp...
so this isnt a CString error that i have to convert CString to another variable?
modified on Monday, November 24, 2008 3:57 PM
|
|
|
|
|
Evil_Inside01 wrote: no im still a beginner in cpp...
What? And you are trying to add a resource to a PE file? Warning Will Robinson! Does not compute!
Do yourself a favor and stick to beginner stuff until you have a very strong grasp on the basics. Using internet forums to debug your beginner level coding of advanced applications is far Far FAR from productive.
led mike
|
|
|
|
|
Evil_Inside01 wrote: (it reads the path from a listview item)...
Have you verified that it is correct?
Evil_Inside01 wrote: ...the program crashes
Which means what?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
ive fixed the error
thanks for helping
|
|
|
|
|
i is an integer holding an 8 bit value of a joysticks position. How do i get an emulator on my pocket pc to see it as an input/button press?
|
|
|
|
|
Try the Mobile Development forum [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello,
I'm writing an MFC application that has headings of anti-aliased text in dialogs that are CStatic pictures (bitmaps). They appear against another flat coloured CStatic that has it's color set to "Gray" - the actual shade of gray varies, based on the windows style - a unique shade for windows classic style, windows XP style, or windows Vista style. I could just make the background of the overlaid, anti-aliased text the same as the colour of the flat "gray", but, as I've said, the exact color varies.
What can I do to achieve the desired effect of having an image of anti-aliased text overlaid over the variable "gray", looking correct in all possible scenarios? GDI+ looks interesting, but I can't find a codeproject project that does what I've described.
Thanks in advance,
Sternocera
|
|
|
|
|
Are the bitmaps composed programatically or with an image editor?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
They are simple bitmap files, composed with an image editor,
Regards,
Sternocera
|
|
|
|
|
If you create the bitmaps with a transparent background and save them
in a format that preserves alpha channel info (e.g. PNG) then you can use
GDI+ to easily render the images on any background.
ULONG dwToken;
Gdiplus::GdiplusStartupInput input;
Gdiplus::GdiplusStartupOutput output;
Gdiplus::Status status = Gdiplus::GdiplusStartup(&dwToken, &input, &output);
if(status == Gdiplus::Ok)
{
Gdiplus::Bitmap *srcBitmap = new Gdiplus::Bitmap(L"c:\\some.png", FALSE);
Gdiplus::Graphics g(hwnd, 0);
g.DrawImage(srcBitmap, 0, 0);
delete srcBitmap;
Gdiplus::GdiplusShutdown(dwToken);
}
You could also use GDI+ to compose a bitmap programatically.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|