|
Have you tried GetFileAttributes() ?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Thanks for the co-operation friends,
But I want to find out if the file is
closed or not without opening the file.
Because in my application after user downloads the file I am going to
open that file using ShellExecute.I'll upload this file on the server
when the file is closed by the user.
How can I do this?
Once again thanks for the reply.
ritz1234
|
|
|
|
|
ritz1234 wrote: But I want to find out if the file is
closed or not without opening the file.
And what exactly does that have to do with reading the attributes of files?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Extremely Sorry,
I was my mistake.
I was thinking that it might give me that whether the file is opened or not.
Thanks for the reply.
But what about the solution?
ritz1234
|
|
|
|
|
Try opening the file in exclusive mode. If it fails, you'll know that it is open elsewhere.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi David,
For testing pupose,
I've set the Timer and in the event of the timer I am trying to open the file.
I've run the application after manually openning the file.
After opening the file when I run the application it give me the message
of the file is opened.But when I close the file manually it doesn't give
the message of file is closed and I am getting the same message every
timer irrespective of the file is opened or not.Following is the code.
<br />
void CFilesDlg::OnTimer(UINT nIDEvent) <br />
{<br />
<br />
CDialog::OnTimer(nIDEvent);<br />
<br />
CFile ob;<br />
BOOL res;<br />
CFileException ex;<br />
res=ob.Open("C:\\Documents and Settings\\Rigel\\Desktop\\SerialNumbers.txt",CFile::modeRead | CFile::shareExclusive, &ex);<br />
if (!res)<br />
{<br />
<br />
TCHAR szError[1024];<br />
ex.GetErrorMessage(szError, 1024);<br />
MessageBox("The File is Closed");<br />
KillTimer(ID_TIMER1);<br />
}<br />
else<br />
{<br />
MessageBox("The File is opened");<br />
}<br />
}<br />
ritz1234
|
|
|
|
|
ritz1234 wrote: ...I am getting the same message every timer irrespective of the file is opened or not.
How are you "manually" opening the file? Notepad, for example, does not leave file handles open after it reads the contents.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I can't understand what you have said.
Please explain in brief.
ritz1234
|
|
|
|
|
You previously indicated that you were "manually" opening the file. I simply asked how.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
manually = double clicking the file with the mouse.
ritz1234
|
|
|
|
|
Whether you used the mouse or keyboard is irrelevant. What program are you using to open the file?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
The program to open the file depends on its extension that is registered
with OS.
OS uses that extension to open an application for that file.
One more thing I want to know If I want to continue with this question
without posting new question for the issue
tommorow what should I do?
Right now I am not going anywhere, and waiting for your reply.
ritz1234
|
|
|
|
|
ritz1234 wrote: The program to open the file depends on its extension that is registered
with OS. OS uses that extension to open an application for that file.
I'm well aware of this.
ritz1234 wrote: Right now I am not going anywhere, and waiting for your reply.
I tried your code snippet and it worked as expected. The only change I made was to the messages, like:
if (! res)
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
AfxMessageBox(szError);
}
else
AfxMessageBox("The file was opened successfully."); Are you opening SerialNumbers.txt with Notepad?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
Hi Guys, I have a program that consumes a lot of memory. First of all it dynamically creates an array of char and reads a binary file, as shown below:
---------------
char * memblock; //Pointer to Char array used to read binary file
char unsigned * memcopyblock; //Pointer to char unsigned array used to create int array
ifstream file (fileName, ios::in|ios::binary|ios::ate);
count = file.tellg();
memblock = new char [count];
file.seekg (0, ios::beg); //Set the postion of the pointer to the start of the file
file.read (memblock, count); //Read the 2 minute log file
file.close(); //Close the log file
----------------
it then converts all the 'chars' into 'char unsigned'.
-------------------------------------
memcopyblock = new char unsigned [count];
for (int i=0;i<=count;i++)
memcopyblock[i] = memblock[i]; //copy
delete []memblock;
---------------------------------------------
However, this approach uses twice as much memory as the size of the binary file. Is it possible to read a binary file into a dynamic array of 'char unsigned' or to use a dynamic memory map (i.e. union stucture) to half the amount of memory used by this program?
Cheers,
Aubs
|
|
|
|
|
Member 3363498 wrote: Is it possible to read a binary file into a dynamic array of 'char unsigned'...
What makes you think it would not work?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
If I change modify memblock from:
char * memblock;
memblock = new char[count];
to
char unsigned * memblock;
memblock = new unsigned char[count];
I get the compilation error:
Error 315 error C2664: 'std::basic_istream<_Elem,_Traits>::read' : cannot convert parameter 1 from 'unsigned char *' to 'char *' e:\projects\global\readbinary.cpp 16
against the line:
file.read(memblock, count);
Is there a simpler efficient way of reading a binary file into a dynamic 'char unsigned' array?
|
|
|
|
|
Yes, it is:
file.read((char*) memblock, count);
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
I have an app written in CodeGear C++ Builder 2007 which uses a COM port. If I run this app on an XP-system (my laptop) and I set the programm to use COM6 (USB->Serial) the app works fine. If I copy the app to a XPe environment (without C++) I get system error 2 (FILE NOT FOUND) if I try to create the COM connection (with FileCreate).
Is there a difference in the naming of the ports in XP and XPe, and if so, what do I have to do to solve this?
When I run the programm from the Programming environment, it creates an exe file. I copy the exe and all the files/directories in this directory to the XPe environment, and until now it didn't cause any problem, but maybe I have to it in an other way?
|
|
|
|
|
XPe ? XP Embedded ?
Did you check that the COM port is the same on the other machine ? If you use a USB to serial, the port number might change from PC to PC.
What is the complete string that you are using to open the com port ?
|
|
|
|
|
XPe = XP embedded.
It is not the same COM port (On laptop with USB to Serial on COM 6; On XPe system on COM2) I've changed that before moving the app.
<br />
char portName[] = "COM6";<br />
hComm = CreateFile (portName,GENERIC_READ|GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);<br />
|
|
|
|
|
I didn't use XP embedded before but I used winCE (but there, the binaries are different so you need to compile your code specifically for winCE).
As far as I remember, you have to specify the port name this way on WinCE:
char portName[] = "\\\\.\\COM6";
If that doesn't work, check also with a colon at the end:
char portName[] = "COM6:";
|
|
|
|
|
Cedric Moonen wrote: char portName[] = "\\\\.\\COM6";
did it, but now I am doubting myself... I believe I've tested this solution but I'm not sure anymore.
Anyway... thanks
Frank Peeters
|
|
|
|
|
Cedric Moonen wrote: As far as I remember, you have to specify the port name this way on WinCE:
char portName[] = "\\\\.\\COM6";
I thought this format was required only for COM ports 10 and higher.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I'm writing a SDI windows win32 .exe program using Visual C++ 6.0. If in the future I want the program to run on PCs other than with the Windows Operating system, is there anything I should incorporate into the code now, or is it compatible with most other operating systems already, or does it need to be rewritten?
Thanks!
|
|
|
|