LNK2028 和 LNK2019 错误

发布于 2025-01-04 11:12:35 字数 3362 浏览 4 评论 0原文

我对 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 分钟,但无法理解从解决方案到有关这些错误的线程的任何内容。这是表格1:

#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
    };
}

I'm a total n00b to c++ and am trying to make a simple form app, but run into this kind of problem:

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)

Googled for 30 minutes and couldn't understand a thing from solutions to threads about these errors. This is 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
    };
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦与时光遇 2025-01-11 11:12:35

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

According to Microsoft's documentation for SetWindowRgn you need to link to User32.lib. This will provide the necessary hooks into User32.dll which resides within Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文