|
Thanks, that's EXACTLY what I needed!
|
|
|
|
|
The Free Ram will droped down,I want to frees up ram by myself,but I don't
know how to do it.Please give me some advice,a part of source code is perfect.
|
|
|
|
|
ummmmm are you saying u have a memory leak in your code somewhere? if so u just gots to go look hard and find it
"... and so i said to him ... if it don't dance (or code) and you can't eat it either f**k it or throw it away" biz stuff about me
|
|
|
|
|
thank you
yes,i meet the problem,but now i want to make little program just like FreeRam, can u give me some advice
|
|
|
|
|
Hi Guys,
I asked this before and didn't get any favourable answers, and I'm still struggling with this:
Issue:
When I read a BINARY file, and writing to back, I get an ASSERT
ASSERT(lpBuf != NULL);
because my binary files contain spaces and null. And when I write it back, the program treats the buffer as NULL so it throws the ASSERT.
********However, it works for text files.*******
Is there anything I'm missing? After couple of loops of the binary read operation, buf is.... buf=""; but the bytes read still the right amount. Any help will be really appreciated.
Do these kind of things happen to everyone or just me?
CClient::Read(BYTE *buf, int iSize){
CFile pFile (sFilename, CFile::modeRead|typeBinary);
while(true){
iReadSize = pFile.Read(pBuf, 4045);
if(iReadSize == 0)
break;
}
}
//this is in an async. callback fn..the event will call it up
CServer::Write(BYTE *buf, int iSize)
{
CFile pFile (sFilename, CFile::modeWrite|typeBinary);
pFile.Write(buf, iSize);
}
My ass is on fire and my brain's on smoke.
JJ
|
|
|
|
|
Merc wrote:
ASSERT(lpBuf != NULL);
This seems to indicate that you are passing a NULL pointer not that the data is NULL.....So are you sure your pointer is good?
Merc wrote:
buf is.... buf="";
Do you mean: buf (the pointer) is NULL --or-- *buf is 0 ???
Merc wrote:
Do these kind of things happen to everyone or just me?
Don't worry...It happens to all of us...
Merc wrote:
CClient::Read(BYTE *buf, int iSize){
CFile pFile (sFilename, CFile::modeRead|typeBinary);
while(true){
iReadSize = pFile.Read(pBuf, 4045);
if(iReadSize == 0)
break;
}
}
I'm just wondering: shouldn't this be more like:
CClient::Read( BYTE *buf, int iSize )<br />
{<br />
CFile pFile( sFilename, CFile::modeRead|typeBinary );<br />
while( iTotalRead < iSize )<br />
{<br />
iJustRead = pFile.Read(pBuf + iTotalRead, iSize - iTotalRead );<br />
if( iJustRead == 0 )<br />
{<br />
break;<br />
}<br />
else<br />
{<br />
iTotalRead += iJustRead;<br />
}<br />
} <br />
}
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hi,
The code you gave logically right. But, you don't have to add pBuf+iTotalRead. File pointer will automatically move itself to the next position. Adding so yields the buffer stays at one piont, considering that the buffer is a limited size. Say 4096.
Merc wrote:
ASSERT(lpBuf != NULL);
>This seems to indicate that you are passing a NULL pointer not >that the data is NULL.....So are you sure your pointer is >good?
Yes it's good since it reads all text/wri files. Since binary files do have NULL chars inside them, it's throwing that assert.
Merc wrote:
buf is.... buf="";
>Do you mean: buf (the pointer) is NULL --or-- *buf is 0 ???
Hm, I mean under debug watch window, my buf shows as pBuf=""
meaning nothing inside the buf. Do I've to reinitialize the buffer once in a while????
Thanks for writing me and sharing you thoughts.
Regards,
jj
|
|
|
|
|
Merc wrote:
ASSERT(lpBuf != NULL);
If this assert is firing....then I'd wager you have a null pointer...Seems you are not passing a good address to your read function
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Hi,
Are you sure? Cuz when I debug and go through the loop, it's reading fine, meaning even though the reading buf is pBuf="" in the watch window, the read size is right and it goes on thorugh the loop. And after couple of loops of pBuf="", the buffer is then filled with actual ascii contents of the file. Is that normal? I assume so because it's a binary file, so it may have spaces, nulls, and all kinds of garbage chars. The assert only fires only on the receving end where I tried to write.
Thanks for the inputs bud.
jey
|
|
|
|
|
if i hava a class
class a
{
int a;
CString str;
};
i want to write an object into a file and send that file through a network to different computer and i want to recive that object again if i have the same class there.
may i read the same object on network from a file?
any body can explain my idea into code like
how to write object into file ?
how to read object on the network (having same class there) from file ?
r00d0034@yahoo.com
|
|
|
|
|
Dude,
are you going to send a instance of a class containig some stuff... like an array object which has some name/address/tp etc in them?
You've to serialize them. To do so, use CArchive class to read the objects into archive, and send it along the network. Look for the ref. on how to use CArhive, CSocket, and CSocketFile on msdn website.
Jey
|
|
|
|
|
How do I change the mouse cursor to hourglass so that the use can NOT click anywhere after a long task? then change back to normal cursor.
Thanks in advance.
|
|
|
|
|
HCURSOR SetCursor(
HCURSOR hCursor // handle to cursor
);
Just trying to keep the forces of entropy at bay
|
|
|
|
|
If you're using MFC:
BeginWaitCursor();
...
EndWaitCursor();
Ty
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein
|
|
|
|
|
TyMatthews wrote:
If you're using MFC:
BeginWaitCursor();
...
EndWaitCursor();
Better yet, use the RAII class CWaitCursor .
|
|
|
|
|
New question of the day. How can you download a file that needs you to accept a security certificate? Also I get a fail on the username/password using the http://UserName:Password@URL.com/file.ext. This may be due to the security certificate as well. Is there a way around this?
Darroll
Not one person lives in the present. Only the past. I can prove it.
|
|
|
|
|
Try using OpenSSL and Curl.
OpenSSL and Curl are two libraries that are used together to interface with Secure HTTP.
They're available for Dos, Windows, Unix, and Linux platforms.
You can download these libraries from the following links:
http://curl.sourceforge.net/
http://www.openssl.org/
Top ten member of C++ Expert Exchange.
http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/
|
|
|
|
|
Hi.
I discovered an interesting bug in an MFC multithreaded program. I found that when you delete a pointer to the worker thread's parameter (declared using new operator), the destructor of the class that is part of the parameter is called.
-----
// This is global.
struct THREADPARAMS
{
ClassA *pCA;
}
// This code is in the primary or main thread.
THREADPARAMS *ptp = new THREADPARAMS;
// Assume that clObject is a member variable and is an instance
// of a ClassA.
ptp->pCA = &clObject;
...
CWinThread *Thread = AfxBeginThread(ThreadFunction, ptp, ...);
// Assume everything works.
// Here is ThreadFunction
UINT ThreadFunction(LPVOID *pParams)
{
THREADPARAMS *ptp = reinterpret_cast<threadparams *="">(pParams);
ClassA *pClassA = ptp->pCA;
// Here is the code that causes the bug.
// I studied Jeff Prosise book on MFC.
// Prosise deleted the new struct inside the worker thread.
delete ptp;
-----
Okay. Lets get to the point. "delete ptp" calls ClassA destructor. I am not sure how to get this working.
My goal is to pass into a worker thread pointers to private data members of the primary thread (main) including primitive data type and ADT. I would like to know is the situation above normal or is there a flaw in my design?
Thanks,
Kuphryn
|
|
|
|
|
I can't see why "delete ptp" should touch ClassA. That said you haven't included the declaration for ClassA, and the answer may lie there.
Have you stepped into the delete ptp in the debugger to see if the ClassA destructor is really being called there?
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
Okay. Thanks.
Yeah something is definitely wrong. I will try to setup more breakpoints to see what triggers ClassA destructor. As far as I know right now, ClassA destructor gets triggered before the worker thread begins and even before the worker thread is resumed (note I declared the worker thread as suspended in order to duplicated its handle).
Kuphryn
|
|
|
|
|
I see that you assign ptp->pCA = &clObject ....
Question: Does clObject go out of scope? ( it is automatic in the function where you are filling out the ptp structure ) .... that could do it you know......
Why not : ptp->pCA = new ClassA; ????
Just trying to keep the forces of entropy at bay
|
|
|
|
|
Okay. Thanks.
I see the problem.
You were right. The problem had to do with scope. The class destructor gets called as the function goes out of scope.
I fixed the bug.
Kuphryn
|
|
|
|
|
Can somebody tell me what is a good book that i can buy that is a good started guide for VS .Net.
I am really looking forward to learning everything about VS.NET and I need a good book that will help me.
Thanks everyone!
|
|
|
|
|
|
Hi,
here is a tricky question... I have a customized listbox (own colors). Now I'd like to specify the background of the listbox's scrollbar (a child of the listbox). Is this possible?
|
|
|
|