|
Honestly, it really does not work. My new string does not appear anywhere in the file - or as expected, after the old string.
|
|
|
|
|
OK, I beleive you!
I can think of two things:
First:
Does the expression
if(csCurrLine==_T("String")) evaluate to a value != 0
That is, does your program find "String" in your present file?
Second:
Do you check the return code of the write-statement?
|
|
|
|
|
Yes, the program finds the evaluated string. I'm sure with that.
And yes, it can write coz i tried writing to a file without reading and it does write. WriteString doesn't have a return value - it returns void.
|
|
|
|
|
OK, it doesn't have a return value, but it does throw an exception for error conditions? Does it?
There simply must be a reason why the file won't change after Write.
|
|
|
|
|
Can u give more details.. What happened?
did the execution comes to
oFile.WriteString(_T("Overwrite String")); ..
more over.. When u read usinf ReadString, the filepointer advance to the next line..So before writting u musk seek back to the staring of the line that u have to replace..
nave
|
|
|
|
|
Why does WriteString() fail?
TRY
{
oFile.WriteString(_T("Overwrite String"));
}
CATCH(CFileException, pEx)
{
AfxMessageBox(_T("Exception encountered."));
}
END_CATCH
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Hello.
You can see a file as a number of bytes. There are no intervening spaces or "records" in it.
You can open a file for both reading and writing, but then you (usually) has to fseek between read and writes.
You can overwrite parts of a file, but you can't insert (or delete) new bytes in the beginning or middle of an existing file. (Acually, you can, but that means you have to write the "move" code yourself, and it won't be very effective).
The only way you can change an existing file is at the end. You can append to the file or remove (by setting the file length to a shorter value than before.
The easiest way to change the contents of a file (other than overwriting a fix number of bytes) is to create a temp file, and then rename the temp file to the name of the original file.
|
|
|
|
|
Hi this is ramu
I got a problem in transwering the image buffer. Actually the problem is at receiving side. The receive statement not receiving the whole data sent.
Some body advised to send the length as a heder first and get it at the client side and make a loop untill the whole length is received.
But i dont know how to make the length as heade in serverside to send and
how to put the receive statement in loop.
So please some body help me out in this problem.
Thank you.
Ramu
|
|
|
|
|
There are several ways. An easy way could be by sending i.e. an unsigned long (if has the capacity needed) as the first data.
Kind of like this:
Sending side
<br />
unsigned long datalength = imageLength;<br />
Send(&datalength, sizeof(unsigned long));<br />
while(moreDataToSend) {<br />
send(data);<br />
}<br />
At the receiving side (assuming that the Read function returns the number of bytes read from the socket):
<br />
unsigned long receivedDataLength;<br />
Read(&receivedDataLength, sizeof(unsigned long));<br />
<br />
unsigned long receivedBytes = 0L;<br />
<br />
while(receivedBytes < receivedDataLength) {<br />
receivedBytes += (unsigned long) Read(buffer, sizeof(buffer);<br />
}<br />
If an unsigned long isn't enough, the use some other variable type. Just make sure it's the same on both sides.
|
|
|
|
|
Hi,
Can we tell me as to create ActiveX control from MutiDocument/View project????
Because I have project which is create on MultiDocument/View architecture and I need reconstruct on ActiveX...
Thanks
|
|
|
|
|
Have the document class support automation.
Create a new SDI or MDI application with AppWizard and check the "support automation" for the document class.
Hope this helps
--
Roger
It's supposed to be hard, otherwise anybody could do it!
Regarding CodeProject: "resistance is pointless; you will be assimilated"
|
|
|
|
|
Hi,
In View I get DC
as
CDC *dc = GetDC();
I do whatever..
and function exits..
Is there need to release this dc or it will be done automatically as function exits.. If I release will there be harm to views DC.
What is the right way. SHould I always use CClientDC in views rather than CDC
regards
ppatel
|
|
|
|
|
From the docs:Unless the device context belongs to a window class, the ReleaseDC member function must be called to release the context after painting.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
How can I know if the device context belongs to windows?
Which function/syntax shows that dc belongs to windows?
ppatel
|
|
|
|
|
The simple answer is don't bother. Here's a quote from MSDN on the ReleaseDC function:
"The ReleaseDC function releases a device context (DC), freeing it for use by other applications. The effect of the ReleaseDC function depends on the type of DC. It frees only common and window DCs. It has no effect on class or private DCs."
So always call ReleaseDC and let the system worry about the details.
Steve
|
|
|
|
|
Hi Stephen Hewitt
and use DeleteDC()
if use CreateCompatibleDC or CreateDC
WhiteSky
|
|
|
|
|
From doco on DeleteDC
"An application must not delete a DC whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the DC."
If you use CreateCompatibleDC of CreateDC you need to delete it when done by calling DeleteDC .
Calling ReleaseDC doesn't actually delete a DC. To quote again from MSDN:
"The ReleaseDC function releases a device context (DC), freeing it for use by other applications."
Steve
|
|
|
|
|
hi,
I have a recordset which contains the results of a query, and I want to get the number of records in the recordset.
I tried to use the GetRecordCount function, but I understood that I have to go through the whole recordset in order to get the number of records. So I have this loop in my code which is very inefficient:
while (!pSet->IsEOF()) //pSet is a pointer to the recordset
pSet->MoveNext();
I thouhgt to do an SQL query using COUNT, but it requires a simple query (something like: SELECT COUNT (*) FROM Table1 ) and my query is not a simple one. It contains selection of a number of records, and Inner joins of tables and an ORDER BY clause.
Is there another way to get the number of records in a recordset? Any suggestions?
|
|
|
|
|
Been a long time since i programmed in ADO but IIRC you don't need to
while (!pSet->IsEOF())
pSet->MoveNext();
pSet->MoveLast();
pSet->GetRecordCount();
Hope it helps
The statement below is true. The statement above is false.
|
|
|
|
|
Nope - I tried that and it doesn't work
It gives 1 record as the result...
|
|
|
|
|
U just move to the first record and now loop until the end of records take a variable and increment it inside the loop with MOVENEST() function.
the variable holds the total records count
|
|
|
|
|
I don't understand what you mean...
can you write some code maybe?
and by the way, I would rather not use a loop - it's not very efficient...
I need an efficient solution
|
|
|
|
|
Monty2 wrote: pSet->GetRecordCount();//something like this
This will simply give you the “high water mark” — the highest-numbered record yet seen as the user moves through the records.
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|
|
Yeah - I know. That's why I need another solution...
Is there another way to get the number of records in a recordset other than going through the recordset with a loop or using COUNT?
-- modified at 9:23 Tuesday 16th May, 2006
|
|
|
|
|
SWDevil wrote: Is there another way to get the number of records in a recordset other than going through the recordset with a loop or using COUNT?
Have you considered/tried a stored procedure?
"The largest fire starts but with the smallest spark." - David Crow
|
|
|
|