0

当我尝试在 Visual Studio Express 2010 中构建和运行我的代码时,我收到以下错误:

1>  Generating Code...
1>Purple Health.obj : error LNK2028: unresolved token (0A000035) "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx@@$$J18YGHIK@Z) referenced in function "private: void __clrcall PurpleHealth::FormOutOfTime::btnLogout_Click(class System::Object ^,class System::EventArgs ^)" (?btnLogout_Click@FormOutOfTime@PurpleHealth@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>FormLauncher.obj : error LNK2028: unresolved token (0A000031) "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx@@$$J18YGHIK@Z) referenced in function "private: void __clrcall PurpleHealth::FormOutOfTime::btnLogout_Click(class System::Object ^,class System::EventArgs ^)" (?btnLogout_Click@FormOutOfTime@PurpleHealth@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>FormLauncher.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx@@$$J18YGHIK@Z) referenced in function "private: void __clrcall PurpleHealth::FormOutOfTime::btnLogout_Click(class System::Object ^,class System::EventArgs ^)" (?btnLogout_Click@FormOutOfTime@PurpleHealth@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
1>Purple Health.obj : error LNK2001: unresolved external symbol "extern "C" int __stdcall ExitWindowsEx(unsigned int,unsigned long)" (?ExitWindowsEx@@$$J18YGHIK@Z)
1>C:\Users\Graham\documents\visual studio 2010\Projects\Purple Health\Debug\Purple Health.exe : fatal error LNK1120: 3 unresolved externals

我的代码看起来像这样(删除了不重要的部分):

#include "FormParentalOverride.h"
#include "Windows.h"
#include <iostream>
#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#pragma once

namespace PurpleHealth {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;
    using namespace System::IO;
    using namespace System::Text;

    public ref class FormOutOfTime : public System::Windows::Forms::Form
    {
    private: System::Void btnLogout_Click(System::Object^  sender, System::EventArgs^  e) {
                 ExitWindowsEx(EWX_LOGOFF, SHTDN_REASON_MAJOR_APPLICATION);
                 //ExitWindows(0, 0);
             }
};
}

任何建议都非常感谢!

4

2 回答 2

1

将 User32.dll 添加到您的链接阶段。

注意:名称具有误导性,因为 64 位和 32 位版本都称为 user32。

于 2012-07-22T00:30:33.620 回答
1

使用 #include<windows.h> 而不是 #include "Windows.h"

于 2013-05-15T20:18:21.427 回答