c++ - LNK2028 和 LNK2019 错误

标签 c++ winforms window hwnd

我完全不了解 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
    };
}

最佳答案

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

关于c++ - LNK2028 和 LNK2019 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9234549/

相关文章:

windows - 使用 CEF 使父窗口透明和子窗口不透明

c++ - 在 windows(W32) 上安装 opencv 以与代码块一起使用

windows - Vista 如何为与我的应用程序关联的文档生成图标?

c# - DatagridView C# 中的额外列

c# - 正确的列表框事件来处理列表框中的更改? (C#)

javascript - 如何使用 Javascript 调整弹出窗口的大小?

c++ - 如何在调整窗口大小时使文本显示在窗口中央,visual c++

c++ - 在死锁 futex 中调用 malloc 和程序时出现段错误

c++ - 使用从文件中获取的维度创建一个双数组

c++ - Boost ASIO 设计,工作线程 SQl 查询 'practical' Web 服务器