|
|
Thanks Gary, this definitely gives me more options.
|
|
|
|
|
You're welcome .
|
|
|
|
|
Hello friends,
How do I check if a file is open or close?
Suppose I've 1 file and I want to find out if it is open or not How can
we do that?
I don't want to open the file for which I am going to check if it is open
or close.
Thanks in advance to all of you.
ritz1234
|
|
|
|
|
u an use this function in case of CFile.
BOOL GetStatus(
CFileStatus& rStatus
) const;
static BOOL PASCAL GetStatus(
LPCTSTR lpszFileName,
CFileStatus& rStatus
);
|
|
|
|
|
u can use this in case of fstream
bool is_open( );
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
To use is_open() function we have to open the file first.
I don't want to open the file to check it is open or close.
ritz1234
|
|
|
|
|
it works dear,
Case:1 if u run the apliation than it shows msg box means file is open.
fstream fs("C:\\fstream.txt", ios::out );
//fs.close();
if(fs.is_open())
{
AfxMessageBox("Test::File is Open");
}
Case:2 if u run the apliation than it is not show the msg box means file is not open.
fstream fs("C:\\fstream.txt", ios::out );
fs.close();
if(fs.is_open())
{
AfxMessageBox("Test::File is Open");
}
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Thanks for the cooperation,
But the problem is not solved
Here is the first part of the code I've tested.
<br />
int nOpen;<br />
fstream fs("C:\\Documents and ettings\\Rigel\Desktop\\SerialNumbers.txt",ios::out );<br />
nOpen=fs.is_open(); <br />
if(nOpen)<br />
{<br />
AfxMessageBox("Test::File is Open");<br />
}<br />
case 1: When the SerialNumber.txt is not already open by the user.
It doesn't show me the msgbox that's right because the file is not open.
case 2: When the SerialNumber.txt is opened by the user by double cliking the file.
In this case this code doesn't show me the messagebox that's wrong.
ritz1234
|
|
|
|
|
Use BOOL in place of int in "int nOpen;"
1 for tue and 0 for false.
and use this condition::
if(nOpen=0)
{
AfxMessageBox("Test::File is Open");
}
or
if(nOpen=1)
{
AfxMessageBox("Test::File is Open");
}
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
Thanks for the reply,
But the result is the same.
It doesn't show the messge either the file is opened or not.
I've nOpen==1 instead of nOpen=1 in the code posted by you.
Have you copy the code in VC 6.0 project and try on it?
ritz1234
|
|
|
|
|
Thanks for the reply,
But in Getstatus() we can have the attributes of the file.
No information is there about the file is opened or close.
ritz1234
|
|
|
|
|
ritz1234 wrote: Suppose I've 1 file and I want to find out if it is open or not How can
we do that?
Unless you are capable of writing a low-level device driver, you'll need to open the file in exclusive mode. If it fails, you'll know that it is open elsewhere. This has already been discussed at length yesterday. What's still troubling you?
"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
|
|
|
|
|
Hello, I was reading one of the tutorials on your site and thought I would try code something that could download files off the internet.
However, when I try to download large files or ones that use weird characters the files become corrupt and do not work. This is the case for .rar,.zip and many other formats. Further, I am unable to get information from .asp sites at all!? Any help would be greatly appreciated.
g++ ws.cpp -lws2_32
Note: Include files altered to work with this forum, missing "<"
<br />
#include winsock2.h><br />
#include ws2tcpip.h><br />
#include stdio.h><br />
#include iostream><br />
#include fstream><br />
<br />
using namespace std;<br />
<br />
<br />
int main() {<br />
<br />
char servername[40] = "members.myserver.com";<br />
char filepath[40] = "/username/file.rar";<br />
char filename[20] = "downloadedfile.rar";<br />
char buff[512];<br />
struct hostent *hp;<br />
unsigned int addr;<br />
struct sockaddr_in server;<br />
int y;<br />
<br />
<br />
WSAData wsaData;<br />
int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);<br />
if (iResult != 0) {<br />
printf("WSAStartup failed: %d\n", iResult);<br />
return 1;<br />
}<br />
<br />
<br />
<br />
SOCKET conn;<br />
conn=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);<br />
if(conn==INVALID_SOCKET)<br />
return 0;<br />
<br />
<br />
if(inet_addr(servername)==INADDR_NONE)<br />
{<br />
hp=gethostbyname(servername);<br />
}<br />
else<br />
{<br />
addr=inet_addr(servername);<br />
hp=gethostbyaddr((char*)&addr,sizeof(addr),AF_INET);<br />
}<br />
if(hp==NULL)<br />
{<br />
closesocket(conn);<br />
return 0;<br />
}<br />
<br />
<br />
server.sin_addr.s_addr=*((unsigned long*)hp->h_addr);<br />
server.sin_family=AF_INET;<br />
server.sin_port=htons(80);<br />
if(connect(conn,(struct sockaddr*)&server,sizeof(server)))<br />
{<br />
closesocket(conn);<br />
return 0;<br />
}<br />
<br />
<br />
sprintf(buff,"GET %s\r\n\r\n",filepath);<br />
send(conn,buff,strlen(buff),0);<br />
<br />
<br />
ofstream file;<br />
file.open(filename);<br />
<br />
while(y=recv(conn,buff,512,0))<br />
{<br />
file << buff;
}<br />
<br />
<br />
file.close();<br />
closesocket(conn);<br />
<br />
<br />
WSACleanup();<br />
<br />
return 0;<br />
}<br />
Thanks! =D
|
|
|
|
|
Hi all,
i want to find out values of language,computer name and user name through coding....
I am unable to find it in registry. How could i find them
Thanks in advance
|
|
|
|
|
char RemoteFileName[60];
TCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1;
if(GetComputerName(chrComputerName,&dwBufferSize)) {
// We got the name, set the return value.
strcpy(RemoteFileName,chrComputerName);
you may need to #include <windows.h>
|
|
|
|
|
try this,
TCHAR tszComputerName[MAX_COMPUTERNAME_LENGTH + 1];
DWORD dwBufLen = sizeof(tszComputerName);
DWORD nSize;
GetComputerName(tszComputerName, &dwBufLen);
AfxMessageBox(tszComputerName);
GetSystemDirectory(tszComputerName,MAX_PATH);
AfxMessageBox(tszComputerName);
tszComputerName[0] = TEXT('\0');
nSize = sizeof(tszComputerName) / sizeof(TCHAR);
GetUserName(tszComputerName, &nSize);
AfxMessageBox(tszComputerName);
|
|
|
|
|
|
I would like to put a copyright notice in the Help About box. I know how to change the text in this box in the Visual C++ environment, but I don't know how to put the copyright symbol (a circle with a c enclosed in the circle)into my text string. How can I put this special symbol in my text string. I'm using Visual C++ 6.0.
Thanks
|
|
|
|
|
Run charmap.exe and copy the symbol from there.
"It is better to remain silent and be thought a fool, than to open your mouth and remove all doubt."
--Groucho Marx
|
|
|
|
|
thanks both,
this is useful for me in many other contexts.
|
|
|
|
|
Typing Alt-0169 (on the number pad) will give you that symbol when using the ANSI character set.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
Hi!
One of my include file used to be like this:
my_include.h
<br />
struct tagInfo<br />
{<br />
int a;<br />
int b;<br />
} stInfo;<br />
Then I added the element c:
<br />
struct tagInfo<br />
{<br />
int a;<br />
int b;<br />
int c;<br />
} stInfo;<br />
My program goes something like this:
<br />
#include "my_include.h"<br />
MyProg ()<br />
{<br />
CString string1.Format("%d", stInfo.a);<br />
CString string2.Format("%d", stInfo.c);<br />
}<br />
In the string#.Format statement, when I type the . after stInfo, VC++ open a popup window with a list of all elements included in the structure stInfo. That list still shows a and b only. The element c is not showed but it compiles properly. I know I have the right file because if I change the element a to z in my include file, then the code does not compile because a is not a member of stInfo.
I guess I need to refresh something but I don't know what.
Thanks for your help.
jpyp
|
|
|
|
|
If you are using Visual C++ 6, Visual Studio .NET (2002), or Visual Studio .NET 2003, the IntelliSense file has gotten corrupted. This file has the extension .ncb, and will have the same name as your project file. Exit Studio, delete the .ncb file, and it will be recreated automatically when you open the project again.
Visual Studio 2005/2008 may use the same thing, but I don't use them regularly so I don't know for sure.
|
|
|
|
|
Im completely new to MFC and we got this project for creating a GSM cellular network ...what I want to know is how can I open a new dialog box on clicking a button that allows the user to enter some information. I know its a very basic question but I really cant figure it out !!!
|
|
|
|