Click here to Skip to main content
15,910,211 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralCombo box problem Pin
Martin McCready15-Apr-04 4:24
Martin McCready15-Apr-04 4:24 
GeneralRe: Combo box problem Pin
User 91483318-Apr-04 13:09
User 91483318-Apr-04 13:09 
Questionhow to fix this error?? Pin
don7cry14-Apr-04 16:03
don7cry14-Apr-04 16:03 
GeneralFrom managed Object* to unmanaged IUnknown Pin
Member 78199113-Apr-04 13:26
Member 78199113-Apr-04 13:26 
GeneralRe: From managed Object* to unmanaged IUnknown Pin
ian mariano25-Apr-04 14:13
ian mariano25-Apr-04 14:13 
GeneralCRC32 Pin
Member 10035669-Apr-04 20:59
Member 10035669-Apr-04 20:59 
GeneralRe: CRC32 Pin
Mikko Puonti9-Apr-04 23:15
Mikko Puonti9-Apr-04 23:15 
GeneralRe: CRC32 Pin
Anonymous10-Apr-04 4:50
Anonymous10-Apr-04 4:50 
Hi,

Thanks for the reply. I had implement my codes as per your advise. Few more questions: what do you mean by:-
8) int percent = (int) (((long double)done / (long double)length) * 100); --> You need to calculate length from somewhere.
11) void Calculate (const LPBYTE buffer, UINT Size, ULONG &crc); --> Where is method definition?
(any more clear example to explain above two?)

After debugging(implemented code as follwoing), I have an error now which is as I underline in my code (prompt me erroe 2065, 'lenght': undeclared identifier, error executing cl.exe). How can I solve this?


//header file remain the same as previsous sent

#include "CRC32.h"
#include <io.h>
#include <fcntl.h>
#include <share.h>
#include <tchar.h>
#include <tchar.h>
#include <commctrl.h>
#include <windows.h>

#define BUFFERSIZE 102400

DWORD WINAPI CRC_32::CRC32ThreadProc(LPVOID lpVoid)
{
LPCRCSTRUCT pCRCSt = (LPCRCSTRUCT)lpVoid;
ULONG CRC = 0xFFFFFFFF;
HWND Progress = NULL;

if (::IsWindow(pCRCSt->hWnd))

{
Progress = pCRCSt->hWnd;
::PostMessage(Progress, PBM_SETPOS, 0,0);
::PostMessage(Progress, PBM_SETRANGE32, 0, 100);
}

if (pCRCSt->pByte)

{
for (UINT offset = 0; offset < pCRCSt->size; offset += BUFFERSIZE)
{
pCRCSt->pCRC_32->Calculate(pCRCSt->pByte + offset, (pCRCSt->size - offset > BUFFERSIZE) ? BUFFERSIZE : (pCRCSt->size - offset), CRC);

if (::IsWindow(Progress))
{
int percent = offset > pCRCSt->size ? 100 : (int)(((double) offset / (double)pCRCSt->size) * 100);
::PostMessage(Progress, PBM_SETPOS, percent, 0);
}
}
}

else if (pCRCSt->FileName)
{
LONGLONG done = 0;
UINT size = BUFFERSIZE;
BYTE buffer [BUFFERSIZE];


int theFile = _tsopen(pCRCSt->FileName, _O_RDONLY | _O_SEQUENTIAL | _O_BINARY, _SH_DENYWR);
if (theFile != -1)
{
_lseeki64 (theFile, 0L, SEEK_SET);


while (size == BUFFERSIZE)
{
size = _read(theFile, buffer, BUFFERSIZE);
if (size)
{
pCRCSt->pCRC_32->Calculate(buffer, size, CRC);
if (::IsWindow(Progress))
{
//update progcess bar
done += size;
int percent = (int) (((long double)done / (long double)length) * 100);
::PostMessage(Progress, PBM_SETPOS, percent, 0);
}
}
}
close(theFile);
}
}

CRC ^= 0xFFFFFFFF;

if (IsWindow(Progress))
::PostMessage(::GetParent(Progress), WM_CRC_THREAD_DONE, (WPARAM)pCRCSt->Thread, CRC);
delete pCRCSt->pByte;
delete pCRCSt;

return CRC;
}


CRC_32::CRC_32()
{
ULONG ulPolynomial = 0x04C11DB7;

for (int i = 0; i <=0xFF; i++)
{
Table[i] = Reflect(i, 8) <<24;
for (int j = 0; j < 8; j++)
Table[i] = (Table[i] << 1) ^ (Table[i] & (1 << 31) ? ulPolynomial : 0);
Table[i] = Reflect(Table[i], 32);
}
}


ULONG CRC_32::Reflect (ULONG ref, char ch)
{
ULONG value = 0;
//swap bit 0 for bit 7, 1 for 6, 2 for 5 and so on
for (int i = 1; i < (ch + 1); i++)
{
if (ref & 1)
value |= 1 << (ch - 1);
ref >>= 1;
}
return value;
}


DWORD CRC_32::CalcCRC(LPVOID buffer, UINT size, HWND ProgressWnd)
{
if (!buffer || !size)
return 0;

if (!IsWindow(ProgressWnd))
{
DWORD CRC = 0xFFFFFFFF;
Calculate ((LPBYTE)buffer, size, CRC);
return CRC ^ 0xFFFFFFFF;
}

LPCRCSTRUCT pCRCSt = new CRCStruct();
DWORD ThreadID;
HANDLE Handle = ::CreateThread(NULL, 0, CRC32ThreadProc, (LPVOID)pCRCSt, CREATE_SUSPENDED, &ThreadID);

if (Handle)
{
//sucessful created thread
pCRCSt->pCRC_32 = this;
pCRCSt->FileName[0] = 0;
pCRCSt->pByte = new BYTE[size];
memcpy(pCRCSt->pByte, buffer, size);
pCRCSt->size = size;
pCRCSt->hWnd = ProgressWnd;
pCRCSt->Thread = Handle;
::ResumeThread(Handle);
}
else
delete pCRCSt;
return (DWORD) Handle;
}


DWORD CRC_32::CalcCRC(LPCTSTR FileName, HWND ProgressWnd)
{
DWORD attrib = ::GetFileAttributes(FileName);
if (attrib == 0xFFFFFFFF || attrib & FILE_ATTRIBUTE_DIRECTORY)
return 0;

LPCRCSTRUCT pCRCSt = new CRCStruct();
pCRCSt->pCRC_32 = this;
_tcsncpy(pCRCSt->FileName, FileName, MAX_PATH);
pCRCSt->pByte = NULL;
pCRCSt->size = 0;
pCRCSt->hWnd = ProgressWnd;
pCRCSt->Thread = NULL;

if (!IsWindow(ProgressWnd))
{
return CRC32ThreadProc((LPVOID)pCRCSt);
}

DWORD ThreadID;
HANDLE Handle = ::CreateThread(NULL, 0, CRC32ThreadProc, (LPVOID)pCRCSt, CREATE_SUSPENDED, &ThreadID);

if (Handle)
{
pCRCSt->Thread = Handle;
::ResumeThread(Handle);
}
else
delete pCRCSt;
return (DWORD) Handle;
}

Again, thanks in advance!
GeneralRe: CRC32 Pin
Mikko Puonti12-Apr-04 20:24
Mikko Puonti12-Apr-04 20:24 
GeneralRe: CRC32 Pin
PJ Arends18-Apr-04 14:59
professionalPJ Arends18-Apr-04 14:59 
GeneralManaged DirectX problem Pin
reznod9-Apr-04 8:59
reznod9-Apr-04 8:59 
GeneralRe: Managed DirectX problem Pin
Mikko Puonti9-Apr-04 23:18
Mikko Puonti9-Apr-04 23:18 
GeneralRe: Managed DirectX problem Pin
reznod10-Apr-04 7:04
reznod10-Apr-04 7:04 
GeneralDllImport problem Pin
reznod8-Apr-04 7:11
reznod8-Apr-04 7:11 
GeneralRe: DllImport problem Pin
Anthony_Yio13-Apr-04 0:42
Anthony_Yio13-Apr-04 0:42 
GeneralRichEditView error when closing VC.Net app Pin
BlackDice8-Apr-04 6:47
BlackDice8-Apr-04 6:47 
GeneralStrings Pin
Billly1237-Apr-04 23:41
sussBillly1237-Apr-04 23:41 
GeneralRe: Strings Pin
Cyric7419-Apr-04 13:55
Cyric7419-Apr-04 13:55 
GeneralCasting Problem for a beginner Pin
Hosam CFJ6-Apr-04 11:21
Hosam CFJ6-Apr-04 11:21 
GeneralRe: Casting Problem for a beginner Pin
Christian Graus6-Apr-04 11:41
protectorChristian Graus6-Apr-04 11:41 
GeneralRe: Casting Problem for a beginner Pin
Hosam CFJ6-Apr-04 12:18
Hosam CFJ6-Apr-04 12:18 
GeneralRe: Casting Problem for a beginner Pin
Christian Graus6-Apr-04 12:20
protectorChristian Graus6-Apr-04 12:20 
GeneralRe: Casting Problem for a beginner Pin
Nemanja Trifunovic6-Apr-04 13:14
Nemanja Trifunovic6-Apr-04 13:14 
GeneralRe: Casting Problem for a beginner Pin
Nemanja Trifunovic6-Apr-04 13:16
Nemanja Trifunovic6-Apr-04 13:16 
GeneralRe: Casting Problem for a beginner Pin
BlackDice12-Apr-04 11:07
BlackDice12-Apr-04 11:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.