|
Thanks!
I figured ZeroMemory and memset were basically the same.
Weird that = {0} works different on VS.NET. I'm still using VC6, so that doesn't affect me now.
Joe Woodbury wrote:
stosd
wtf?
I prefer to wear gloves when using it, but that's merely a matter of personal hygiene
[Roger Wright on VB]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
[Rich Cook]
|
|
|
|
|
|
Well (as I found out the hard way) the
MY_STRUCT foo = {0};
is only usable (in terms of zeroing out the whole structure) on MS compilers. So if you want to write correct, portable code you should use memset (AFAIK).
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
What sort of error does this produce on non-Microsoft compilers?
|
|
|
|
|
MY_STRUCT foo = {0};
Jim Crafton wrote:
is only usable (in terms of zeroing out the whole structure) on MS compilers
Was the compiler(s) compliant with the C or C++ standard?
I have not read the standard for C in years but if I remember it right then the above initialization should work on all compliant compilers. If you are sure I am wrong about this then send a reply and I'll go look it up to verify what the standard has to say on the subject of initializing Aggregate Types.
Trust in the code Luke. Yea right!
|
|
|
|
|
Thanks!
So far, I've only done dev work in Windows, using DevStudio, so I haven't run into anything like that.
I prefer to wear gloves when using it, but that's merely a matter of personal hygiene
[Roger Wright on VB]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
[Rich Cook]
|
|
|
|
|
Jim Crafton wrote:
s only usable (in terms of zeroing out the whole structure) on MS compi
No, that syntax for initializing a struct is inherited from C. It sets the first member to 0, then by definition sets all remaining members to 0. So if you write = {1} that sets the first member to 1, and all remaining members to 0.
--Mike--
"So where does that leave us? Well, it leaves us right back where we started, only more confused than before." -- Matt Gullett
Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber
|
|
|
|
|
Crap!! I swear to god I ran into this, using GCC (I think it was the 2.9x series) but I just tried it (using GCC 3.2) and it works perfectly!
My apologies to all! Sorry
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
Ok, i have an annoying problem. I'm writing an MFC program that has a ton of edit controls and droplist combos. all data enteres/selected in these controls needs to be saved in a text file. I've taken care of all the edit controls and radio buttons, but i'm baffled as to how to do it with a droplist combo.
So far, (in my 2 weeks of MFC experience), the only way i've found to enter data in a droplist combo or a list combo is to enter it in the property window of the individual combo. i need to be able to enter the data somewhere in the code.
Basically, what i want to do is:
- input strings from a text file (which i can handle no problem)
- store those strings into the contents of the droplist combo (this is where i have troubyle)
- and eventually display all the necessary strings in the droplist box.
If anyone can give some insight, i'd greatly appreciate it. If its not possible to do, ie the only way to enter data is to manually enter it when creating the listbox, well, i'm just screwed.
|
|
|
|
|
(droplistbox == combobox )
CCombobox::AddString ( ... ) should do the work to add a string into the combobox
Maximilien Lincourt
For success one must aquire one's self
|
|
|
|
|
Thanks for the speedy response.
I looked on the msdn library and i didnt find much about AddString, so i'm unclear as to how to use it. do i need to create a new class derived from CCombobox? or can i just do something like
my_combobox.AddString("yabbadabbadoo");
In my dodataexchange, i put
DDX_CBIndex(pDX, IDC_LANG, combo_box);
combo_box.AddString("hi");
where combo_box is defined as an int in my dialog class. it returned the error:
error C2228: left of '.AddString' must have class/struct/union type
|
|
|
|
|
keegan wrote:
or can i just do something like
my_combobox.AddString("yabbadabbadoo");
Correct, assuming that my_combobox is of type CComboBox.
|
|
|
|
|
ok, I've created a CComboBox Class called MyCombo. In the veiw.h file, i defined
MyCombo my_combobox;
now i've tried putting the my_combobox.AddString("yabbadabbadoo"); everywhere that i can think of. i tried putting it right before the DoMOdal(), i put it in the constructor of the Vew Class. darnit, where does ti go?
thanks for yer help...
|
|
|
|
|
The dialog window, nor any of its controls, exist prior to calling DoModal(). The only thing that exists at that point is the dialog object itself. The most common place to initialize controls is in the OnInitDialog() method.
|
|
|
|
|
yay! it works. i ended up adding the AddString function in my dodataexchange. but it works now.
Thanks for all your help!
|
|
|
|
|
I have a list of 50 variables all of type double.
They all have a min and max value that they have to be within.
I am trying to generate a numbers within this range for each of the variables, one that changes 3 times a second.
I thought about using the rand() function.
Any ideas on geting a random number between a specified range?
Do you think this is the way to go?
Thanks for the help,
sj;P
|
|
|
|
|
How about something like:
::srand(::time(NULL));
int min = 10;
int max = 20;
for (int i = 0; i < 100; i++)
{
int n = min + (::rand() % (max - min + 1));
TRACE(_T("n = %d\n"), n);
}
Or something similar?
When I am king, you will be first against the wall.
|
|
|
|
|
Robert,
Makes sense but, I am not familiar with the TRACE
could you explain this a bit more?
TRACE(_T("n = %d\n"), n);}
Thanks,
sj
|
|
|
|
|
It's part of MFC. It outputs to the debug window when in Debug mode, and does nothing in Release mode.
|
|
|
|
|
It works great thanks,
sj
|
|
|
|
|
Not to pick nits or anything, but I believe that the randomness of rand() is not guaranteed if you do a mod. You are essentially only using a subset of the random bits. If you want to be proper, you should divide the result by RAND_MAX to get a float in [0.0,1.0) which you can then scale apropriately.
J
"You can get anything you want at Alice's Restaurant."
|
|
|
|
|
When I divide by RAND_MAX, I get a 0 as the value.
When I divided by the mod I get a number between my min and max value, but it was a int.
How can I get the rand() to return a value between 2 doubles.
Here is my code, it might give you a better idea.
thanks,
sj
<br />
double createRandNum(TSimSignal &s, double min, double max){<br />
<br />
double n; <br />
<br />
for(int i = 0; i < 100; i++){ <br />
n = min + ((double)rand()) % (max - min + 1.0));<br />
or<br />
n = min + ((double)rand()/RAND-MAX) % ((double)(max - min + 1))); <br />
}<br />
cout << endl << "The random number is : " << rand()<< " N is : " << n << "\n";<br />
return n;<br />
}<br />
<br />
|
|
|
|
|
int randInRange(int minVal, int maxVal)
{
double scale = rand() / static_cast<double>(RAND_MAX);
return static_cast<int>(minVal + scale * (maxVal - minVal));
}
This returns a value in the range [minVal, maxVal). If you need [minVal, maxVal] you'll have to add 1 to the (maxVal - minVal) in the last line.
J
"You can get anything you want at Alice's Restaurant."
|
|
|
|
|
Does anyone know if it is possible to find the creation date\time of an executable from within the file ?
thanks in advance!
|
|
|
|
|
You could try fetching the full path of the EXE using ::GetModuleFileName and then use CFileStatus::GetStatus(...) to get the creation date...
When I am king, you will be first against the wall.
|
|
|
|