LNK2028和LNK2019错误

时间:2012-02-10 20:43:38

标签: c++ winforms window hwnd

我总是n00b到c ++,我正在尝试制作一个简单的表单应用程序,但遇到了这样的问题:

1>proyecto.obj : error LNK2028: unresolved token (0A00001E) "extern "C" int __stdcall SetWindowRgn(struct HWND__ *,struct HRGN__ *,int)" (?SetWindowRgn@@$$J212YGHPAUHWND__@@PAUHRGN__@@H@Z) referenced in function "public: __clrcall proyecto::Form1::Form1(void)" (??0Form1@proyecto@@$$FQ$AAM@XZ)
1>proyecto.obj : error LNK2028: unresolved token (0A000021) "extern "C" struct HRGN__ * __stdcall CreateRectRgn(int,int,int,int)" (?CreateRectRgn@@$$J216YGPAUHRGN__@@HHHH@Z) referenced in function "public: __clrcall proyecto::Form1::Form1(void)" (??0Form1@proyecto@@$$FQ$AAM@XZ)
1>proyecto.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall SetWindowRgn(struct HWND__ *,struct HRGN__ *,int)" (?SetWindowRgn@@$$J212YGHPAUHWND__@@PAUHRGN__@@H@Z) referenced in function "public: __clrcall proyecto::Form1::Form1(void)" (??0Form1@proyecto@@$$FQ$AAM@XZ)
1>proyecto.obj : error LNK2019: unresolved external symbol "extern "C" struct HRGN__ * __stdcall CreateRectRgn(int,int,int,int)" (?CreateRectRgn@@$$J216YGPAUHRGN__@@HHHH@Z) referenced in function "public: __clrcall proyecto::Form1::Form1(void)" (??0Form1@proyecto@@$$FQ$AAM@XZ)

用Google搜索30分钟,无法理解有关这些错误的解决方案。这是Form1:

#pragma once
#include <cstdlib>
#include <windows.h>

namespace proyecto {

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

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();

            HRGN hrgn = CreateRectRgn(0, 0, 300, 256);

            HWND hwnd=(HWND)Handle.ToPointer();

            SetWindowRgn(hwnd, hrgn, true);
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->SuspendLayout();
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(284, 262);
            this->ControlBox = false;
            this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
            this->Name = L"Form1";
            this->ShowIcon = false;
            this->Text = L"Form1";
            this->ResumeLayout(false);
        }
#pragma endregion
    };
}

1 个答案:

答案 0 :(得分:3)

根据Microsoft's documentation for SetWindowRgn,您需要链接到User32.lib。这将为驻留在Windows中的User32.dll提供必要的挂钩。