HANDLE hFile=CreateFIle(_T("C:\\TEST.DAT"),GENERIC_WRITE,FILE_SHARE_READ,NULL,
CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile==INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Couldn't create the file!"));
else
{
CFile myFile(hFile);
static const char sz[]="Hockey is best!";
myFile.Write(sz.1strlen(sz));
myFile.Close();
}这是一段关于MFC文件系统的代码.有几个地方不明白:
1.代码中的两处 _T 是什么转换,在哪儿定义的?为什么要在这里使用?可以取掉吗?
我查了msdn,下面是CreateFile的函数原型
HANDLE CreateFile(
LPCTSTR lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
);
其中关于lpFileName又有lpFileName
[in] Pointer to a null-terminated string that specifies the name of the object to create or open.
Windows NT/2000/XP: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Windows 95/98/Me: This string must not exceed MAX_PATH characters. 而File Name Conventions里也没有涉及_T
看到很多地方都用到了这个_T,不太明白(是不是以下划线_开头的是一种特别的变量或者函数?)2.Afx开头的标是什么意思?是不是什么全局变量?请告知准确的中文含义?
为什么在MessageBox这个本身就可以用的API函数的前面还要加上Afx?
什么时候使用它们合适?是否需要包含<afx.h>或者<afxwin.h>,二者有什么差别?
还有以Afx开头的包括哪些?比如这里的API函数,或者变量等等?3.如果要使用MFC里的CFile类,需要包含哪些头文件?
我看到某个例子使用了#include<iostream>;
using namespace std;
名字空间我本以为是C#才引入的,现在才知道C++里已经有了,能大概解释一下什么意思吗?本人是VC初学者,请各位高手指教以上问题,能解答多少算多少,不甚感激!
CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile==INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Couldn't create the file!"));
else
{
CFile myFile(hFile);
static const char sz[]="Hockey is best!";
myFile.Write(sz.1strlen(sz));
myFile.Close();
}这是一段关于MFC文件系统的代码.有几个地方不明白:
1.代码中的两处 _T 是什么转换,在哪儿定义的?为什么要在这里使用?可以取掉吗?
我查了msdn,下面是CreateFile的函数原型
HANDLE CreateFile(
LPCTSTR lpFileName, // file name
DWORD dwDesiredAccess, // access mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // SD
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to template file
);
其中关于lpFileName又有lpFileName
[in] Pointer to a null-terminated string that specifies the name of the object to create or open.
Windows NT/2000/XP: In the ANSI version of this function, the name is limited to MAX_PATH characters. To extend this limit to nearly 32,000 wide characters, call the Unicode version of the function and prepend "\\?\" to the path. For more information, see File Name Conventions.
Windows 95/98/Me: This string must not exceed MAX_PATH characters. 而File Name Conventions里也没有涉及_T
看到很多地方都用到了这个_T,不太明白(是不是以下划线_开头的是一种特别的变量或者函数?)2.Afx开头的标是什么意思?是不是什么全局变量?请告知准确的中文含义?
为什么在MessageBox这个本身就可以用的API函数的前面还要加上Afx?
什么时候使用它们合适?是否需要包含<afx.h>或者<afxwin.h>,二者有什么差别?
还有以Afx开头的包括哪些?比如这里的API函数,或者变量等等?3.如果要使用MFC里的CFile类,需要包含哪些头文件?
我看到某个例子使用了#include<iostream>;
using namespace std;
名字空间我本以为是C#才引入的,现在才知道C++里已经有了,能大概解释一下什么意思吗?本人是VC初学者,请各位高手指教以上问题,能解答多少算多少,不甚感激!
2.Afx好象是为了和以前的版本兼容才用的。
名字空间是为了避免你的名字和别人的名字相同时引起混乱引入的一种机制。加上名字空间就好像加上了一个前缀一样,就不容易相同了。
不过我对msdn还不太熟练,只知道search,不知道如何直接找到要找的内容,就像刚买电脑的时候不知道如何使用注册表一样