首页 > 代码库 > 为啥报错误函数未定义
为啥报错误函数未定义
我在做一个控制NTFS文件夹权限的 vc project
东查西找,
AddAccessAllowedAce
SetSecurityDescriptorDacl
SetFileSecurity
用这些API可以搞定.
但是发现生成的权限只是对文件夹本身生效.而不是我所期望的文件夹与子文件夹及子文件
后来发现 AddAccessAllowedAceEx 这个函数支持这个参数.
改好代码后,一编译,说这个函数未声明.
奇怪啊,我又 #include <winbase.h> 还是不管用.
最后一研究.该函数必须要 WINNT 5.0 以上才支持的,也就是说
要在 stdafx.h 的最开头,添加如下一句
#define _WIN32_WINNT 0x0500
表示你所编译的是系统内核是NT 5.0以上的,就OK了.(也就是win2000以上的系统,非win98以下)
类似这样的函数很多.其实,要仔细一点就会发现,在msdn中有这么一行隔膜计量泵说明.
QuickInfo
Windows NT: Requires version 5.0 or later.
有时,登录的用户名是带有域名的,比如说 mydomain\user1
但是如果调用 GetUserName,则不论你是登录的本机,还是登录的域,获取的都是user1,而不能获得域名.
GetUserNameEx这个函数,就可以获得全名称.
不过,如果是在vc6情况下,就没办法直接使用这个函数了,我尝试将隔膜计量泵对应的.h和.lib复制过来,却总是不行.最后想到的一招还是使用LoadLibrary/GetProcAddres
typedef enum
{
// Examples for the following formats assume a fictitous company
// which hooks into the global X.500 and DNS name spaces as follows.
//
// Enterprise root domain in DNS is
//
// widget.com
//
// Enterprise root domain in X.500 (RFC 1779 format) is
//
// O=Widget, C=US
//
// There exists the child domain
//
// engineering.widget.com
//
// equivalent to
//
// OU=Engineering, O=Widget, C=US
//
// There exists a container within the Engineering domain
//
// OU=Software, OU=Engineering, O=Widget, C=US
//
// There exists the user
//
// CN=John Doe, OU=Software, OU=Engineering, O=Widget, C=US
//
// And this user‘s downlevel (pre-ADS) user name is
//
// Engineering\JohnDoe
// unknown name type
NameUnknown = 0,
// CN=John Doe, OU=Software, OU=Engineering, O=Widget, C=US
NameFullyQualifiedDN = 1,
// Engineering\JohnDoe
NameSamCompatible = 2,
// Probably "John Doe" but could be something else. I.e. The
// display name is not necessarily the defining RDN.
NameDisplay = 3,
// String-ized GUID as returned by IIDFromString().
// eg: {4fa050f0-f561-11cf-bdd9-00aa003a77b6}
NameUniqueId = 6,
// engineering.widget.com/software/John Doe
NameCanonical = 7,
// johndoe@engineering.com
NameUserPrincipal = 8,
// Same as NameCanonical except that rightmost ‘/‘ is
// replaced with ‘\n‘ - even in domain-only case.
// eg: engineering.widget.com/software\nJohn Doe
NameCanonicalEx = 9,http://www.tju.edu.cn/
// www/srv.engineering.com/engineering.com
NameServicePrincipal = 10,
// DNS domain name + SAM username
// eg: engineering.widget.com\JohnDoe
NameDnsDomain = 12
} EXTENDED_NAME_FORMAT, * PEXTENDED_NAME_FORMAT;
typedef BOOLEAN (SEC_ENTRY *MYGETUSERNAMEEX) (EXTENDED_NAME_FORMAT,LPSTR,PULONG);
char buffer[200];
ULONG len=200;
HINSTANCE LibHandle;
LibHandle = LoadLibrary("secur32.dll");
if( LibHandle )
{
MYGETUSERNAMEEX func;
func = (MYGETUSERNAMEEX)GetProcAddress(LibHandle,"GetUserNameExA");
if( func )
{
(func)(NameSamCompatible,buffer,&len);
AfxMessageBox(buffer);