First, you should let the application support the UNICODE 。 Next , I will tell you what to do in your application:
Create a project named EmuteUser of the MFC AppWizard(exe) based dialog.
Next, you should click sections of VC, Project->Settings,select C/C++ section, and in Preporcessors definitions, add UNICODE,_UNICODE, expression ,this shows your application support UNICODE.
Next , we should select Link section, and in it's Projects options, add /entry:"wWinMainCRTStartup", this tells your application's entry. In order to get more information ,you should look up MSDN.
Now , we have set the environment that support the UNICODE of the application.
Let's go to subject of the application.
In the application , I had added a List Box and a Button Control.In List Box,show the user's name of the OS, and Button was to realize the enumeration function.
Next, we should add some settings about the application:
#include
#include
#pragma comment(lib,"Netapi32.lib")
If application can use NetUserEnum() etc, we should add these settings.
And we add function named EmuteUser(),this function can enumerate all the users in our OS.The main code here:
void CEmuteUserDlg::EmuteUser()
{
LPUSER_INFO_0 pBuf = NULL;
LPUSER_INFO_0 pTmpBuf;
DWORD dwLevel = 0;
DWORD dwPrefMaxLen = -1;
DWORD dwEntriesRead = 0;
DWORD dwTotalEntries = 0;
DWORD dwResumeHandle = 0;
DWORD i;
DWORD dwTotalCount = 0;
NET_API_STATUS nStatus;
LPTSTR? pszServerName = NULL;
// The server is not the default local computer.
//
//
// Call the NetUserEnum function, specifying level 0;
// enumerate global user account types only.
//
do // begin do
{
nStatus = NetUserEnum(pszServerName,
dwLevel,
FILTER_NORMAL_ACCOUNT, // global users
(LPBYTE*)&pBuf,
dwPrefMaxLen,
&dwEntriesRead,
&dwTotalEntries,
&dwResumeHandle);
//
// If the call succeeds,
//
if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
{
if ((pTmpBuf = pBuf) != NULL)
{
//
// Loop through the entries.
//
for (i = 0; (i < dwEntriesRead); i++)
{
assert(pTmpBuf != NULL);
if (pTmpBuf == NULL)
{
AfxMessageBox(_T("An access violation has occurred"));
break;
}
//
// Print the name of the user account.
//
CString strUser;
strUser.Format(_T("%s"), pTmpBuf->usri0_name);
m_strList.AddString(strUser);
pTmpBuf++;
dwTotalCount++;
}
}
}
//
// Otherwise, print the system error.
//
else
{
CString strError;
strError.Format(_T( "A system error has occurred: %d"), nStatus);
AfxMessageBox(strError);
}
if (pBuf != NULL)
{
NetApiBufferFree(pBuf);
pBuf = NULL;
}
}
while (nStatus == ERROR_MORE_DATA); // end do
if (pBuf != NULL)
NetApiBufferFree(pBuf);
}
But how can we call this function? Now ,it's code :
m_strList.ResetContent();
EmuteUser();
In settings , you can fall across this question :
When you compile the application , you can receive the error report:
LINK : fatal error LNK1104: cannot open file "mfc42ud.lib"
How can we do?
Ok! You should select Project->Settings, in General section,in Microsoft Foundation Classes:,
you can select Use MFC in a Static Library.
VC+ WINXP+VSP5
MFC应用支持UNICODE及用户枚举功能实现
博客介绍了让MFC应用支持UNICODE的设置步骤,包括项目创建、C/C++和Link部分的配置。还添加了List Box和Button Control,实现用户枚举功能,给出了核心代码。此外,针对编译时出现的“LINK : fatal error LNK1104”问题,提供了解决办法。
9979

被折叠的 条评论
为什么被折叠?



