|
Hi!
I am making a program which will cut a file into several pieces. Using fstream.h functions I am reading a file byte by byte and writing it into another file ( in the size I want ). The problem is that I don't know how to automatically generate necessary files. Lets say my file to cut is 10000bytes. Ad I want to cut it into 10byte pieces, I will have to generate 1000 files but I don't know how to generate 1000files! The code i use is this:
------------------
LPCTSTR file1 = "data/filein.bin";
LPCTSTR fileoutf1 = "data/fileout1.bin";
LPCTSTR fileoutf2 = "data/fileout2.bin";
char * buffer;
int i= 0;
long l,m;
long bigness;
long requiredf = 0;
ifstream filecount(file1, ios::in|ios::binary);
l = filecount.tellg();
filecount.seekg(0, ios::end);
m = filecount.tellg();
filecount.close();
bigness = m - l;
requiredf = bigness / targetbytes + 1;
ifstream filein(file1, ios::in|ios::binary);
ofstream fileout1(fileoutf1, ios::out|ios::binary);
ofstream fileout2(fileoutf2, ios::out|ios::binary);
buffer = new char[1];
do{
filein.read(buffer, 1);
fileout1.write(buffer, 1);
i++;
}while(i
|
|
|
|
|
char szFilename[MAX_PATH];
int max_number_of_files;
max_number_of_files = size_of_file / 10000;
if ((size_of_file % 10000) != 0)
max_number_of_files++;
for (int x = 1; x <= max_number_of_files; x++)
{
sprintf(szFilename, "outfile%d", x);
}
|
|
|
|
|
I have a long time operation. In order to be able to interrupt it, the operation runs in different shorter steps. After each step I get a callback message where I can return if I want to continue the operation or not. Since the user should be able to abort the operation I developed a modless dialog box with a cancel button. The dialog class has 2 methods: one is the event handler for the cancel button (I set an internal flag if the user clicks on the button) and the other is a query method which I call in my callback handler which I mentioned above.
The query method which I call regularly contains the following code
<br />
MSG msg;<br />
while (::PeekMessage(&msg, NULL, <br />
NULL, NULL, PM_NOREMOVE))<br />
{<br />
AfxGetThread()->PumpMessage();<br />
}<br />
return m_bAbortedByUser;<br />
My problem is, that I can not click on the cancel button in my dialog. But the weird thing is that I can cancel the operation by closing the dialog using the X button of the dialog.
So why does the dialog gets the closing message via the X button but not the click message on the button? Anyone an idea how I can fix it?
Thanks in advance.
|
|
|
|
|
i think u should see split/merge files project by Bijesh as your lead of clue.
the project use CWinThread as working process and there is a good example how to interact to that working process from your main window. you can start and you also cancel the operation too nicely there.
the project you could find it codeproject, i forgat the link, but u could always search it
((
_; )
((
|
|
|
|
|
Thank you for the answer. But I think that my problem is not the interaction. And cancel the operation seems to generally work with my code (if you press the X button of the dialog). But my main problem is that although I keep the windows message loop running in my query method I don't get the OnCancel message from windows if I click on the cancel button. So I primary want to know why the messages are handled differently (has the X button message a higher priority?).
|
|
|
|
|
Put the "long time operation" code in another thread. This will allow the primary thread to respond to user events (e.g., clicking the Cancel button). Anything else is going to be kludgy at best.
|
|
|
|
|
Thanks, I will keep that in mind and look what I can do.
|
|
|
|
|
hi,
i have a MFC Dialog with a CPropertySheet with one CPropertyPage holding a CRichEditCtrl, and i want to add multiple strings into it, which all should be displayed in a separated line.
I can't find a function which can add a string into this f***ing EditCtrl, except SetWindowText and SetDlgItemText, but these functions are nonsense.
Can anybody help me?
Thanks in advance!
|
|
|
|
|
Welcome to the funny world of the CRichEditCtrl.
Maybe you have a look at some articles in codeproject.com dealing with rich edit controls. I find them very useful if I have to use a rich edit control.
http://www.codeproject.com/richedit/
|
|
|
|
|
but i don't know how to implement it. can anyone give me some source code about it or give me some clue? thanks in advance
|
|
|
|
|
My brain is fried - is there an API I can call to do convert a digit CString to an int ? I suppose I could walk the CString and do a manual conversion, but I was looking for a Unicode analog of:
char szNumber [64];
strcpy (szNumber, "123");
long nValue = -1;
sccanf (szNumber, "%d", &nValue);
In other words:
CString strNumber = _T("123");
long nValue = -1;
xxx (strNumber, _T("%d"), &nValue);
Thanks,
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
Dear All,
I am developing an application in MFC VC++ Version 6.0 for Windows 2000.
I am making an uninstallation program, in which i have to delete some files associated with my program and the application exe itself which is running.
ie. I am running EZ.exe, and at click of an event, I want it to be deleted itself after next restart.
Is there any way out?? I know that there are some pending rename operations like the one we use in MoveFileEx API, but how can we use it to delete the application .
Feel free to ask any further queries in this regards,
Thanks
Rohit Dhamija
|
|
|
|
|
From the MSDN documentation on MoveFileEx
If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and lpNewFileName is NULL, MoveFileEx registers the lpExistingFileName file to be deleted when the system restarts. If lpExistingFileName refers to a directory, the system removes the directory at restart only if the directory is empty.
Magnus
|
|
|
|
|
You can also create a batch file which will start when windows starts and delete the files and the main exe with it...
Well... I am a beginner ...
|
|
|
|
|
Dear scolinks,
MoveFileEx worked exact. Thanks.
...
You can also create a batch file which will start when windows starts and delete the files and the main exe with it...
Answer) This is also a solution , but in this case who will clean (ie delete) the batch file ??? Again the problem remains there then !!
Rohit
|
|
|
|
|
uh... you can create a second batch for cleaning the first one!
Well... I am a beginner ...
|
|
|
|
|
MoveFileEx is the right way to do it.
But, a batfile can delete itself
This way you can call a batchfile from your program, make the batchfile loop while trying to delete your program, when your program exists the batchfile deletes it and can delete itself
- Anders
Money talks, but all mine ever says is "Goodbye!"
http://SourceLocker.net[^] SourceControl and DefectTracker Project.
nsms@spyf.dk <- Spam Collecting
|
|
|
|
|
Can anyone help me...
I have build a simple listening socket program using winsock2 in windows xp. when i start the listening socket it works fine.
i send 1000 concurent message in one time, the socket works fine. until i send 1000 message again, then the send application receive error message "address already in use" (WSAEADDRINUSE).
then i shutdown the listening application and start it up again, then i try to send a message again using the same port, i cannot connect to the listening port, it says the same error.
is there any way that i could done in order to get listening socket status if the send application receive that error. coz, once that error occure, i can't send any message to listening socket. i want to clean up the listening socket again so i can use it again.
thanks...
((
_; )
((
|
|
|
|
|
So you have 2 apps:
- a server
- a client
In the client you have the error WSAEADDRINUSE.
You probably try to recreate a socket with the same port in the client after you send the first 1000 messages. Are you sure that the first transfer completed succesfully? If not the port will be opened, hence your error.
If you shutdown the server while there are active connections to the socket, this will not close and the port will not be closed. Hence the error when you try to restart the server and it tries to bind on an already opened port.
-----
We are what we repeatedly do. Excellence, then, is not an act, but a habit.
|
|
|
|
|
Thanks for the reply,
yes i have 2 apps, n i think i have to explain how those two works.
server app works like any other server apps. it's listen to the port i have specify.
in the client, it works like this. if i want to send 10 message for example, for the first message i create socket then i send it to server, after i have send it, i close the socket right away. when i want to send another one, i use the same method again. the reason i do this, because i want to simulate my server as if it was hit by noumerous connection in one time.
the strange thing is, after the client receive that error, i shutdown the server, and i shut down the client. after that, when i try to connect to server without starting the server app, it retreive WSAEADDRINUSE rather than WSAECONNREFUSED error message.
i have to wait for sometimes, than after that i can receive WSAECONNREFUSED error in my client app, which specify that the current port is not in use.
during that time (when client app rec WSAEADDRINUSE with server app off), if i start my server app, it works just fine, there is no error message, as if it was in listen state normally. but when i try to send a message from the client app, i would receive WSAEADDRINUSE in my client app.
is there any explaination about this? n how i should deal woth this problem?
i was sure the transfer completed, coz i receive the message from the client n i close the client socket normaly too.
((
_; )
((
|
|
|
|
|
i want to convert the string "2003-8-27 20:30:26" to a CTime
object.how can i do?
thanks!
Habbit--Beginner In MFC
|
|
|
|
|
COleDateTime::ParseDateTime()
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I posted this in the FAQ section but didnt receive a reply, assuming that no one really visits that message board, I decided to post here, PLEASE feel free to delete that post, I am NOT cross-posting(at least I dont intend to anyways, )
I read FAQ 2.5[C++ Faqs] as well as the relevant topics on MSDN but didn't get this:
1) What is the difference between using *automatic pre compiled headers* and *creating/using pre compiled headers*[presumably only through using stdafx.h and stafx.cpp]
2) Which is better and why?
3) *When* is it advisable to use either and why.
Sorry I can't be more specific , but this is all I know at this time and am going crazy reading MSDN which offers little to me at this time.
Thanks in advance!
Any help will be appreciated.
|
|
|
|
|
My personal opinoin - I always use the "Automatic" option. It is nice because if a source file has the precompiled header (e.g., "stdafx.h") as its first include, it uses it. If not, it doesn't use precompiled headers for that file. You don't have to worry about any funky build steps to make the PCH either (I seem to recall running into situations where I have to build the PCH separately or specially if I use the "Use precompiled headers" option.
And for really small projects, with say one or two CPP files, I don't use precompiled headers at all.
I know that's not very comprehensive, but it's what works for me.
"When a man sits with a pretty girl for an hour, it seems like a minute. But let him sit on a hot stove for a minute and it's longer than any hour. That's relativity." - Albert Einstein
|
|
|
|