在Visual Studio中构建示例Windows程序时出错

时间:2019-05-27 20:30:31

标签: c++ windows visual-studio

我正在尝试构建一个C ++控制台应用程序,该应用程序要求用户输入用户名和密码,并且我已经找到带有CredUIPromptForCredentials函数的Microsoft Wincred.h库。我已经去了Microsoft网站,并从示例中复制了确切的代码,并将其粘贴到了我的代码中,但是当我尝试构建文件时,出现了错误:“在函数_main中引用的未解析的外部符号__imp__CredUIPromptForCredentialsW @ 40。我即使我已经包含了windows.h和wincred.h,也不明白为什么代码无法正常工作,因此,非常感谢您提供有关如何进行此编译和工作的帮助。这是我从{{3 }}

//我包括:iostream,Windows.h,字符串和wincred.h

使用命名空间标准;

int main() {

CREDUI_INFO cui;

TCHAR pszName[CREDUI_MAX_USERNAME_LENGTH + 1];

TCHAR pszPwd[CREDUI_MAX_PASSWORD_LENGTH + 1];

BOOL fSave;

DWORD dwErr;


cui.cbSize = sizeof(CREDUI_INFO);
cui.hwndParent = NULL;
//  Ensure that MessageText and CaptionText identify what credentials
//  to use and which application requires them.
cui.pszMessageText = TEXT("Enter administrator account information");
cui.pszCaptionText = TEXT("CredUITest");
cui.hbmBanner = NULL;
fSave = FALSE;
SecureZeroMemory(pszName, sizeof(pszName));
SecureZeroMemory(pszPwd, sizeof(pszPwd));
dwErr = CredUIPromptForCredentialsW(
    &cui,                         // CREDUI_INFO structure
    TEXT("TheServer"),            // Target for credentials
    NULL,                         // Reserved
    0,                            // Reason
    pszName,                      // User name
    CREDUI_MAX_USERNAME_LENGTH + 1, // Max number of char for user
    pszPwd,                       // Password
    CREDUI_MAX_PASSWORD_LENGTH + 1, // Max number of char for pw
    &fSave,                       // State of save check box
    NULL);

if (!dwErr)
{
    //  Put code that uses the credentials here.

    //  When you have finished using the credentials,
    //  erase them from memory.
    SecureZeroMemory(pszName, sizeof(pszName));
    SecureZeroMemory(pszPwd, sizeof(pszPwd));
}

}

0 个答案:

没有答案