|
take a look at http://www.math.keio.ac.jp/matumoto/cokus.c for a set of C functions that generate a 32 bit random number.
To get a number between nLower and nUpper
UINT number = randomMT();
number /= (UINT_MAX / (nUpper - nLower));
number += nLower;
---
Multitasking: Screwing up several things at once.
|
|
|
|
|
From what I understand:
You use Structured Exception Handling when using the Win32 API without MFC.
You use MFC Exceptions (obviously) when using MFC.
When do you mix them? When do you not? Any anecdotal experiences that you wouldn't find in the manual? (MSDN just relaunched their site and it's impossible to get to any of the pages today... how evil) Thanks in advance
--
Peace,
Amit Jain
|
|
|
|
|
I think you left one out - C++ exception handling, though it does get a bit confusing since MS does make use of SEH in implementing their C++ exception handling.
Jeffrey Richters 'Advenced Windows' has a whole chapter on SEH. I would say that if you are using the C language with the windows API SEH is the way to go, and in the rare case that you need to trap and _identify_ floating point and processor traps, but otherwise stick to C++.
If you are dealing with MFC classes that throw MFC exceptions its a no brainer - but you don't have to derive from CException for your own stuff, thats up to you.
|
|
|
|
|
|
Why I need the UDP ?
i want to create something (Like OCX or DLL) to let the server send a message to the client(s) inform them to refresh ,redirect ,there is new email, XXX is logged on.
how i'm thinking to solve this problem?
create client OCX (without using the WinSock.OCX) to wait and manage the server message. and create an DLL on the server that will send the message to the Client OCX. (i think this is a good solution ?! do you think that ????!! )
What i want ?
i do not know how to write a code deal with UDP ?!
if you have another idea ?? i'll be pleased to you if you send it to me
Note : I’m talking about intranet.
Can any one there help me ? or give and any article(s) that could help ?!
web programmer.
|
|
|
|
|
Create a SOCK_DGRAM type socket, and use sendto() and recvfrom() to send and receive UDP datagrams.
|
|
|
|
|
thank you very mach "markkuk" .
web programmer
|
|
|
|
|
The app my company sells allows the user to print JPG files. Under Windows NT 4.0 (service pack level doesn't seem to matter), the printjob spools up but once in the spooler, it just goes away without being printed. I *think* this is the only printer it happens on, and the same app/printer combo works fine under Win95/98.
Has anyone else had similar problems with the NT/950C combo while printing graphics?
I think it's a driver problem, but HP has told our hardware tech that it's the program we're using that is at fault.
I stepped through the code, but nothing seems to be out of place or weird about it.
BTW, StrechBlt is used to "display" the output to the printer. I tried using BitBlt instead, but that didn't help the problem. Removing the call to StrechBlt altogether allows the printer to at least eject a blank page.
|
|
|
|
|
I have a string in VB and a string in VC++. I need to check and make sure they are the same. I believe if I show their hex representation or their bit representation I can compare them.
|
|
|
|
|
They almost certainly are not identical. VB uses "BSTR"s, which store a lenght value and then an array of character data, while C/C++ generally use null terminated character arrays as strings. It's a pain in the rear to go back and forth, but not hard once you grock the two concepts.
For a good overview of different flavors of strings, see the string article at:
http://www.pgh.net/~newcomer/mvp_tips.htm
Jim
|
|
|
|
|
Thanks, thats a good site, it helps. I am still looking for a way to display these strings in bit or hex form.
|
|
|
|
|
We just had this discussion over at microsoft.public.vc.mfc
Here is one example from that discussion:
<br />
CString strBytes("ff10ab");<br />
char buffer[2];
buffer[0] = 0;
int digit;<br />
for(int i=0;i<strBytes.GetLength();i++)<br />
{ <br />
buffer[0] = strBytes[i];<br />
digit = strtol( buffer, 0, 16 );
TRACE("Digit %i is %d in decimal, %x in hex\n",i,digit,digit);<br />
}<br />
|
|
|
|
|
|
Of it should it should. I knew that, I just wanted to make sure that you knew it also!
Jim
|
|
|
|
|
Fist iam a newbie with MFC!
But i was asked to make an program that reads from the Comport, that is connected whit a windmachine.The windmachine sends me diffrent sort of kordinates(16 diffrent cords).
My problem here is that the user wants to choose how many kords he wants to display,my idea was to create a new ChildFrame for each kord that is selected to show.And store the ChildFrames in a array and if there comes new kords from the Comport use the ChildeFrame array to send right kords to the right ChildFrame.
The ChildFrame has a ChildView(CWnd derived) wich recives the kords for painting(OnPaint()).
I used the appwizzard (MDI,No doc/view)
I wounder if i am on the right track?
If u have a better soulotion for doing this a better way post a message here !
(Sorry my bad english)
|
|
|
|
|
when ever i run a program in debug mode, after i exit the program, i always get a message "Detected Memory Leak".. what do i do about it??? can you tell me where i am missing or making an error??
Nitish
|
|
|
|
|
It's telling you you created heap objects and never deleted them. For every new that's executed there needs to be a delete.
You may need to add destructors to some of your classes to delete anything the class allocates.
Think about the lifetime of everything you create with new. Are you overwriting the only pointer to an object (orphaning it)?
|
|
|
|
|
Have a look at "HOWTO: Use _crtBreakAlloc to Debug a Memory Allocation"
Article ID: Q151585 in the MSDN.
|
|
|
|
|
if you make a variable with new, use delete.
if you make an array of variables with new, use delete[].
--
Peace,
Amit Jain
|
|
|
|
|
Does VC++ distinguish between delete and delete[] then? With most compilers the [] is no more than a comment.
|
|
|
|
|
Hm, I wonder if that's a bug with VC++ or the other compilers? But yes, VC++ DEFINITELY distinguishes between the two... You should too, just in case.
--
Peace,
Amit Jain
|
|
|
|
|
In order to properly delete an array (call the destructors of each element) the delete routine must work out the size of the array from hidden runtime information, probably the allocation size is stored immediately before the pointer. It would follow that there's very little point in using a separate delete implementation for arrays and single object allocations (a single object allocation being indistinguishable from an array of length 1).
|
|
|
|
|
I'm sure that's true and all, but regardless, if you're doing it in VC++, you're using delete[] for a dynamically allocated array, and delete for a single item.
--
Peace,
Amit Jain
|
|
|
|
|
Yes you should (for clarity at least).
I'd be surprised, though, if it makes any difference to the code generated.
|
|
|
|
|
> I'd be surprised, though, if it makes any difference to
> the code generated.
It makes a substantial difference. If you use new to allocate an array of objects and delete without square brackets, the destructors will not be called except one for element at 0th index.
CMyClass *p = new CMyClass[10];
// ... use p
delete p; // error -> only one d'tor call
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|