|
The checksum is generally the twos-complement of the low byte of the sum, so I would code it like this:
BYTE CalculateChecksum(BYTE *pData, UINT dataSize)
{
UINT sum = 0;
for(int i=0; i<dataSize; i++)
sum += pData[i];
sum = -sum;
return (BYTE)(sum & 0xff);
} Where pData is a pointer to you data buffer, and dataSize is the length of the data. I'll leave it to you to translate this to VB
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hello Dudley,
It is perfectly acceptable to have the sum of all the bytes "roll over" beyoung the maximum value of the data type you are using, 8 bit or byte. If your running checksum is a byte something like the following will probably happen:
Lets say you want to add the following three bytes 127, 63, and 98. The running 8 bit checksum and 16 bit check sum would be the following.
Checksum Total
Byte (8 bit) (16 bit)
127(0x7F) 127(0x7F) 127(0x7F)
63(0x3F) 190(0xBE) 190(0xBE)
98(0x62) 32(0x20) 288(0x0120)
The 8 bit check sum is just the 8 LSB or the 16 bit checksum.
In your implementation, you can just use a BYTE for your checksum and add all the data bytes, or you can use a larger data type like an int for your checksum and your 8 bit checksum would be the 8 Least Significant Bits.
Don't forget that after you have added all the bytes you need to do the 2's complement.
Invert all the bits and add one.
(C language)
checksum = ~checksum + 1;
The final checksum for the above example would be:
224(0xE0)
When you add the sum of all the bytes and the final checksum together, you should get zero.
32(0x20) + 224(0xE0) = 256(0x100);
But 256 is really 0 for a 8 bit data type (0x00);
Hope this helps.
Tim
|
|
|
|
|
Thanks Guys I think I understand alot better now.
I will reply here when I get this working.
=================================
When I was in school, all I wanted was to get out into the real world.
Now that I'm in the real world, all I want is to go back to school.
|
|
|
|
|
Please help.How to extract audio from AVI fimes using VC++ and DirectX?
|
|
|
|
|
Use DirectShow - it comes with Direct X - try reading the docs
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
i'm supposed to write an application that detects the laser pointer on the image captured from a webcam(which has an infra-red camera in front of it). so first i'm grabbing a frame(as a bitmap file). next i should process this file(check its pixels one by one) but i don't know how to do that part. is there anyone to help me?
|
|
|
|
|
i assume, that there is a red spot where the laser pointer is!
code kinda filter, which creates a second bitmap in memory...
it should scan the original bitmap line by line, and check the pixels for red.
if they are red, they should be white in the second bitmap, if not, then black.
then you check for a small white spot on the second bitmap and you got it!
Don't try it, just do it!
|
|
|
|
|
Hello ppl, i am trying to learn multi-threaded c++ programming and have tried the MSDN example. It works fine with just a simple main function and a thread function. But when i try to implement it in a win32 application, i get the following error.
error C2664: '_beginthread' : cannot convert parameter 1 from 'void (void *)' to 'void (__cdecl *)(void *)'
I am using VC++ 6 with the 2003 platform sdk installed. My project is generated by the WTL AppWizard provided with WTL 7.0. I have put my thread function as a member function to the main dialog class. I have included process.h in stdafx.h
_beginthread(ThreadFunc, 0, NULL);<br />
...<br />
void CMainDlg::ThreadFunc(void * dummy)<br />
{<br />
...<br />
}
Any help/pointer will be very helpful. Thankx in advance.
-Tareq
|
|
|
|
|
Have you declared the thread function as a static ?
~RaGE();
|
|
|
|
|
In the Thread function You must specify the
Calling convention of the Function
Like
unsigned __stdcall YourThreadFunction(void* pVoid)
{
return something;
}
and try to write the fucntion a a pubic, not a member
|
|
|
|
|
Thankx Rage for the quick reply. I didnt make the function static. That was the problem. Now it works fine but i have another problem. Can i access any objects declared in the mail dlg class? I have an edit box named _edit. if i use _edit.AppendText("blah blah"), it gives me the following error.
error C2228: left of '.AppendText' must have class/struct/union type
Thankx again for your response.
-Tareq
|
|
|
|
|
You're inside a static function of a class - therefor you can't access member functions. Typically what people do is pass in a application variable to the thread's void* argument. In your case, this would be a pointer to the instance of your Dialog class. then you could refernece it.
However with that solved your next problem will arise in making changes to UI controls from outside the main UI thread of execution. You must be very careful when doing this or risk causing lock, or various other wicked and evil things to happen. To simplify this, you might consider Posting a message back to your dialog class instance and then accessing the control there. This way you ensure that you're back in the context of the main UI thread.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
1. modify your ThreadFunc like this:
void ThreadFunc(void * dummy)
2. call _beginthread like this:
_beginthread(ThreadFunc, 0, this);
3. again, modify your ThreadFunc to call a member function of your CMainDlg:
void ThreadFunc(void * dummy)
{
CMainDlg* m_pDlg = (CMainDlg*)dummy;
if(m_pDlg != NULL)
m_pDlg->ThreadFunc(NULL);
}
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
Your thread ThreadFunc is CMainDlg mamber. To use
CRT _beginthread try to declare it as separate function as:
void ThreadFunc(void * dummy)
{
}
Or try to use AfxBeginThread, or CreateThread
Hope it help.
Vitali
|
|
|
|
|
Thank you all for your replys. Greg S. your solution worked like a charm and its so obvious ... i only forgot to cast it to the editor pointer inside the thread function. ... again thank you all for your solutions.
-Tareq
|
|
|
|
|
Hi,
Can somebody tell me how to do this:
I need to get all .c files from a directorie, and all of its subdirs, without having the user to selected them al manually --> he only needs to select one directory!
Thanks
|
|
|
|
|
MFC CFileFind
Win32 FindFirstFile, FindNextFile
And then recurse down the tree when you find a file that is a sub directory. There MUST be an example on CP
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
a quick example if you don't find one:
WIN32_FIND_DATA findData = {0};
HANDLE findHandle = FindFirstFile( "c:\\my\\dir\\of\\cfiles\\*.c", &findData );
if ( INVALID_HANDLE_VALUE != findHandle ) {
do {
printf( "found file: %s\n", findData.cFileName );
} while ( FindNextFile( findHandle, &findData ) );
}
else {
}
I think that will only go into the dir you specify - to recurse down into sub dirs you'll have to add some extra code
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
|
|
|
|
|
Hi,
Suppose I'm writing a program wich uses 3 windows:
1: select a mode
2: select an input\output path
3: perform some actions (and supply the program with the actions properties)
ans suppose i call those windows win1,win2, and win3.
After havig performed the actions in win3, I'd like to show win1 again and let all the others disappear.
HOW CAN I DO THIS?
all those windows are inherited from CDialog and are showed by calling the DoModal method.
Thank you in advance,
|
|
|
|
|
And i forgot:
If i try to get back to the last windows (for instance from win3 to win2), both dont react anymore .
CAn you tell me how this is possible (or rather how to solve it)?
|
|
|
|
|
After win3.DoModal() returns with ID_OK , you call win1.DoModal() again.
Or am I missing something? If yes, please post (relevant!) code.
Good luck!
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
How to let it return ID_OK?
|
|
|
|
|
I am sorry, it was IDOK .
And you did read the MSDN article about CDialog::DoModal() , did you?
Sorry to be rude, but I think it is the minimum requirement to have read the relevant MSDN articles before asking questions.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
Ok,
thanks --> I did, and it worked quite well
|
|
|
|
|
But,
I now need to make my own IDs, instead of IDOK i want to use (for instance IDready): can can I do this?
PS: I've already looked in the MSDN
|
|
|
|