|
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!
|
|
|
|
|
8) You don't declare and give value for "length". This is why you get error C2065. For example:
<code>
int main()
{
int i = 100 * x;
}
</code>
To solve problem:
<code>
int main()
{
int x = 1;
int i = 100 * x;
}
</code>
Here is one possible way to calculate length.
<code>
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)
{
long length = _lseeki64( theFile, 0L, SEEK_END );
if( length == -1L )
{
size = 0L;
switch( errno )
{
case EBADF:
break;
case EINVAL:
break;
default:
break;
}
}
if( length <= 0 )
{
length = 1L;
}
_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))
{
done += size;
int percent = (int) (((long double)done / (long double)length) * 100);
::PostMessage(Progress, PBM_SETPOS, percent, 0);
}
}
}
close(theFile);
}
</code>
11) Your header file did have declaration for method called "Calculate", but I didn't see
any implementation for that code. (You declared identifier "Calculate" as method that doesn't return anything and takes three parameters, but you didn't provide code for that method (definition)).
I hope that you know what you are doing. There is ready CRC32 implementation for Managed code in .NET platform. And some some ready code for native C++. So you might not need to do this byself (unless you are trying to learn native C++).
|
|
|
|
|
Hegot the code from http://www.codeproject.com/cpp/crc32_large.asp[^]
I do not know why he didn't ask his question in the article forum there, instead of posting partial code here
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
I installed Managed DirectX but I don't have access to the namespaces. When I try using Microsoft:: all I have access to is Win32.
I have the includes folder list with "C:\DX90SDK\Include" at the top and "C:\DX90SDK\Lib" at the top of the library folder list. Those directories contain the files, but for some reason it is not reading them.
Any help would be great.
|
|
|
|
|
I think that you need to add reference to managed DirectX DLL. "References" -> Right click -> Add reference -> .NET -> Browse to .DLL.
|
|
|
|
|
|
I am calling DllImport so I need the namespace "System::Runtime::InteropServices" but I keep getting the error:
error C2872: 'FILETIME' : ambiguous symbol
If I comment out the namespace, this problem goes away, instead it gives me this error:
error C2337: 'DllImport' : attribute not found; it is neither a built-in nor a custom attribute that is accessible in the current namespace
Any help would be great.
|
|
|
|
|
use _FILETIME instead.
Sonork 100.41263:Anthony_Yio
Life is about experiencing ...
|
|
|
|
|
I have an app that I recently ported to .Net (an SDI app with Richedit as the view type). Everything is working fine and it runs fine with native and managed code mixed. But when I close the app, I get this error message: An unhandled exception of type 'System.NullReferenceException' occurred in FB.exe
Additional information: Object reference not set to an instance of an object.
this is happening in the following procedure, which I have never touched. (the offending line is pointed out)
CRichEditCntrItem* CRichEditView::GetInPlaceActiveItem() const
{
ASSERT(m_lpRichEditOle != NULL);
CRichEditDoc* pDoc = GetDocument();
CRichEditCntrItem* pItem = NULL;
CReObject reo;
HRESULT hr = m_lpRichEditOle->GetObject(REO_IOB_SELECTION, &reo,
REO_GETOBJ_ALL_INTERFACES);
if (GetScode(hr) == S_OK && (reo.dwFlags & REO_INPLACEACTIVE))
{
pItem = pDoc->LookupItem(reo.poleobj);
if (pItem == NULL)
pItem = pDoc->CreateClientItem(&reo);
ASSERT(pItem != NULL);
}
return pItem;
} I hope anyone can help me. Thanks
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Need to devise code for the following problem
String Line
Character CharSelect
Integer Begin
Returns the index of the first occurrence of the character CharSelect in string Line starting from index Begin
If Line has value “Most people find this hard” and if CharSelect has value ‘t’ and Begin has value 5 then 18 is returned.
Any help much appreciated.
Bill
|
|
|
|
|
String *Line = S"Most people find this hard";
String *char = S"t";
Int16 iBegin = 5;
//Substring Line to all characters from iBegin on
//Find index of 'char' in the substring
Int16 iIndex = Line->Substring(iBegin)->IndexOf( char );
//Index total by adding whatever iIndex found with iBegin
Console::Write( iIndex + iBegin );
***
That's probably the most simple way. There are some other ways (using IndexOf/IndexOfAny, or some other string functions that I don't recall at the moment) that may also work for finding a character within a specific range.
Cyric
|
|
|
|
|
I have just started moving to Visual C++ 2003, and I have faced the following problem. I want to make an index (std::map<int, int> and std::map<string, int> in VC6.0). I have seen the Hashtable and the SortedList, but I couldn't use them. I got the error that myHashtable->Add(1, 2) can't convert from int to a managed object, and I couldn't solve it.
I hope someone can help me solve this problem. Thank you in advance.
|
|
|
|
|
Why don't you keep using the STL ? Just because you're using managed C++ ( why? ) does not mean you have to use .NET containers, does it ?
It looks like MC++ sucks, and cannot handle that a number is not an object. C# would box it for you automatically.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Thank you very much for the idea. I would really like to use the STL, but I couldn't make std::map<int, String*> for example. I get an error in the following line for example:
myMap.insert(std::pair<int, String*>(1,S"One");
I get an error telling me that I can't make the pair, because the pair is unmanaged and I can't include a managed pointer in an unmanaged pair.
Thank you for all your help and patience.
|
|
|
|
|
Can you use std::string, or do you need to use the managed string ?
This is just convincing me more and more that MC++ sucks. And for the record, I use C# every day, I don't hate .NET.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
|
Christian Graus wrote:
C# would box it for you automatically.
And that is bad. At least under some circumstances.
|
|
|
|
|
when you have a value like that that is not an object you simply put __box(1) or __box(2005), whatever the case may be
If it's broken, I probably did it
bdiamond
|
|
|
|
|
Hi,
We have created this Group, 'CUIPL Mailing Group', which we think
you might also be interested in.
CUIPL is an Image Processing Library written in ANSI C++ in order to
be platform independent.
We thought that it would be more useful if we put it on the internet
as an open source, this way people can use it, but most important
they can extend it to cover areas not covered in the initial release.
This library is intended to be a tiny step towards a huge arabian
open soucre community, where we can build the software we need.
We don't have to rely on the west to supply us with - at least - our
software needs, we can do our own, and we are old enough to do so
we have the knowledge, experties, and the tools to achieve our goal.
So,
WHAT ARE WE WAITING FOR!!?
the group address is
http://www.smartgroups.com/groups/cuipl
Email us back if you need any help, or what it's all about...
Regards
Ahmed Mohamed Abdelsalam am_abdelsalam@msn.com
Mohamed Galal El-Din Mohamed eng_mg@yahoo.com
|
|
|
|
|
I have a VC 6 project that I'm converting to .Net and I'm trying to use managed extensions. In the project properties, I've set the 'Use Managed Extensions' option to YES and added the following using directives to my stdafx.h file:
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
#using <System.dll>
using namespace System;
using namespace System::Windows::Forms;
using namespace System::Text::RegularExpressions;
now when I try to compile the project, I get the following error:
cl : Command line error D2016 : '/RTC1' and '/clr' command-line options are incompatible
can anyone help?
If it's broken, I probably did it
bdiamond
|
|
|
|
|
In my header file, I'm using only get_dataSectionPtr and no set (its value is set in the constructor) and I get the following errors:
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\byteme\AbfFileStruct.h(43) : error C2086: 'long AbfFileStruct::dataSectionPtr' : redefinition
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\byteme\AbfFileStruct.h(21) : see declaration of 'AbfFileStruct::dataSectionPtr'
AbfFileStruct.cpp(12) : error C2039: 'set_dataSectionPtr' : is not a member of 'AbfFileStruct'
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\byteme\AbfFileStruct.h(15) : see declaration of 'AbfFileStruct'
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\byteme\AbfFileStruct.h(43) : error C2086: 'long AbfFileStruct::dataSectionPtr' : redefinition
c:\Documents and Settings\administrator\My Documents\Visual Studio Projects\byteme\AbfFileStruct.h(21) : see declaration of 'AbfFileStruct::dataSectionPtr'
And the offending code seems to be this:
public __gc class AbfFileStruct
{
public:
//always need at least a FileStream to construct it
AbfFileStruct(FileStream *);
__property long get_dataSectionPtr()
{
return dataSectionPtr;
}
void PrintFileStruct();
private:
long dataSectionPtr;
}; //ENDCLASS
Ideas?
|
|
|
|
|
Oh, and there's another header file (AbfFileInfo.h) that has the get_ properties and doesn't give any errors...
|
|
|
|
|
The reason for this error is that your private member variable (dataSectionPtr) has the same name as your property. That's because from your get_ method, the compiler will generate a property dataSectionPtr. Just rename your private member variable, and your code will compile.
|
|
|
|
|
hi me again, ive been writting code that fills a vector with random numbers from two sources, all even elements are filled from source1 and odd ones from source2...this now works fine after much debuggingmyhead.
ive been trying to to do next part of my function which is more complex, it basically uses a iterator with a const value of 0.002. which is 20millseconds.
this iterator goes to every single element in the array and goes through every element in 0.002 segments..i.e if element value is 3.6 then it goes through it in 1,800 segements. basically splitting up the element into segments,
and it does this to distingusih between numbers from sourceone and sourcetwo because these numbers are usesd elsewhere.. i will paste the code which fills the vector and ive COMMENTEDout the 'new' but it doesnt work imnot sure what else to do.
#include <iostream><br />
#include <vector><br />
#include <stdlib><br />
#include <time><br />
#include <numeric><br />
#include <algorithm><br />
#include "exponentialgenerator.h"<br />
<br />
using namespace std;<br />
<br />
ExponentialGenerator one = 1.41;<br />
ExponentialGenerator two = 1.71;<br />
<br />
double nextNumber = reinterpret_cast<double>(one.generate());<br />
<br />
double nextNumber2 = reinterpret_cast<double>(two.generate());<br />
<br />
int counter = 0;<br />
<br />
void fillVectorToSum(vector<double>& v, double sum)<br />
{<br />
<br />
int total = 0;<br />
do {<br />
if (counter++ % 2){<br />
v.push_back(nextNumber);<br />
total += nextNumber;<br />
nextNumber = one.generate();<br />
}<br />
else {<br />
v.push_back(nextNumber2);<br />
total += nextNumber2;<br />
nextNumber2 = two.generate();<br />
}<br />
<br />
} while(total+nextNumber+nextNumber2 <= sum);<br />
if(total < sum)<br />
v.push_back(sum-total);<br />
}<br />
<br />
<br />
int main()<br />
{<br />
<br />
srand((unsigned) time(NULL));<br />
vector<double> v;<br />
fillVectorToSum(v, 30);<br />
<br />
cout << "Number of elements: " << v.size() << "\nTotal: "<br />
<< accumulate(v.begin(), v.end(), 0) << endl;<br />
copy(v.begin(), v.end(), ostream_iterator<double> (cout," "));<br />
<br />
<br />
<br />
<br />
<br />
<br />
}
|
|
|
|
|
I have a project (MFC Application) in wich I need to insert an Windows Form. So, I've changed my project from unmanaged into managed.
Problem 1:
I have a control "Microsoft Flex Grid". When my project was unmanaged everything was OK. Now, I Have a "Debug Assertion Error" when i try to open the dialog box with the grid control.
Solution1: function AfxOleInit => Problem 2: Everything works ok but after I close the principal dialog box of the application = another Debug Assertion Error (in cmdtarg.cpp in "~CCmdTarget()"). If there is sb who had the same problem or who has a solution...thank you.
Monica
|
|
|
|
|