|
As I explained above, it is because your DialogProc() does not match the definition required by Windows. Check the documentation[^] and make sure that your declaration matches in every respect.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
You are right. But the conflict is :
DialogProc function Return INT_PTR while the WinMain which return the DialogProc "must return int."
I think I must find a way to convert from IntPtr to int safely ...
Thank you.
|
|
|
|
|
In the special case of WinMain you may use a static cast for the return value without running into any problems:
return static_cast<int>(DialogProc());
Or just assign the return value to a variable and set the value returned by WinMain (usually a non-zero value if the program terminates due to errors):
INT_PTR nRet = DialogProc();
return nRet != ID_OK ? 1 : 0;
|
|
|
|
|
Thank you,I will try all the solutions here.
|
|
|
|
|
Smart Arab wrote: DialogProc function Return INT_PTR while the WinMain which return the DialogProc "must return int." What do you mean, these are two different functions?
Smart Arab wrote: I think I must find a way to convert from IntPtr to int safely .. No, you just need to follow the information provided by the documentation, as I suggested before, and use a cast to satisfy the compiler thus:
return DialogBox(hInstance, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DialogProc);
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Thank you,I will try all the solutions here.
|
|
|
|
|
That is not a big deal.
As already suggested, you don't need to return directly the DialogBox call result, quite the opposite, is better break it into a two stage approach:
- Assign the
DialogBox return value to an (INT_PTR ) variable (say result ). - Based on
result value, return an appropriate (int ) number from the WinMain function.
This is convenient, since DialogBox and WinMain use different conventions for they return values (see DialogBox[^] and WinMain[^] at MSDN).
Veni, vidi, vici.
|
|
|
|
|
Thank you,I will try all the solutions here.
|
|
|
|
|
You are welcome.
Veni, vidi, vici.
|
|
|
|
|
Hi,
I have a slider control on a dialog box in mfc. When user clicks on the slider bar, the thumb moves by the ticks. I want to place the slider thumb directly at the place where user clicked the mouse on the slider bar.
Any sample code for the above scenario.?
Anybody have any idea.?
Regards,
Mbatra
|
|
|
|
|
Hi!
I've to select a number radomly from 1 t0 6. What is the C++ code for this?
|
|
|
|
|
pix_programmer wrote: I've to select a number radomly from 1 t0 6. What is the C++ code for this?
int number;
srand ( time(NULL) );
number = rand() % 6 + 1;
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
Since (from rand() as cplusplus.com[^]):
Notice though that this modulo operation does not generate a truly uniformly distributed random number in the span (since in most cases lower numbers are slightly more likely), but it is generally a good approximation for short spans.
An alternative is:
int n = 1 + 6.0 * rand() / (RAND_MAX + 1.0);
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: Notice though that this modulo operation does not generate a truly uniformly distributed random number in the span (since in most cases lower numbers are slightly more likely), but it is generally a good approximation for short spans.
That's wrong.
I startet a small programm generating one billion random number for each of the two solutions repeatly.
The are no difference and the reason is obvious.
Of course smaller numbers are more likely, but it doesn't matter how big a number is when you use modulo as it depends on divisibility. And there is no difference for small or large numbers.
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
It depends on the goodness of the pseudo random generator , of course (hint: it is not the reminder function that is 'broken').
The test depends also on the periodicity of the random generator.
How did you perform the test?
Veni, vidi, vici.
|
|
|
|
|
CPallini wrote: How did you perform the test?
I had just two arrays of long integer, filled with random numbers. Then I calculated the difference between the two, printed them and repeated the test, adding the differences.
Of course there are differences but they are neglectable and there is no scheme that they will raise with higher numbers.
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
This should do it.
<pre>int randomizedValueInRange = (rand()%(maxRange-minRange+1))+minRange;
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
The code is as follows : int random_number = (rand() % 6) + 1;
Example of use:
#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std ;
int main(void)
{
srand(static_cast<unsigned>(time(0)));
cout<<" \nDICE GAME\n";
int random_number = (rand() % 6) + 1;
cout<<" \nYou threw a ["<<random_number <<"]\n\n";
return 0;
}
|
|
|
|
|
Typically these requests for code result in a lot of sarcastic responses, and being down voted into oblivion what makes one different?
|
|
|
|
|
Where did you see a sarcastic reply in this thread?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I suppose he is wondering why there are not.
Veni, vidi, vici.
|
|
|
|
|
I didn't, that's why I'm curious, no 'google it' posts, no links to 'how to ask a question' specifically the part about not doing others' homework, etc... So I asked what makes this post unique?
|
|
|
|
|
Good mood?
I don't know, really.
Veni, vidi, vici.
|
|
|
|
|
Wellness Wednesday?
|
|
|
|
|
I got an application MFC and openGL are used. When I run the application it should load a 3D graphics model. But my tool bar, menu bar everything is coming properly but the 3D model window with the model is not appearing. There is no error or no dll problem. Everything linked propely. Why the 3D model is not coming. Please help me someone. Thanks Sujan
Please check this link for the screen shot
https://www.dropbox.com/sh/5thffcacwx7ye6u/i_mmqIgerU?m[^]
|
|
|
|