【问题标题】:How do I use Windows.h in c++/clr如何在 c++/clr 中使用 Windows.h
【发布时间】:2022-10-03 05:37:03
【问题描述】:

我正在制作一个应用程序,它有一个附加到正在运行的进程的按钮,但是当我尝试使用 windows.h 函数时,例如。 FindWindowA 它说未解析的令牌 (0A000038) extern C。 如果工作正常,它应该在按下按钮时附加到进程,然后运行一些我还没有编码的代码

这是按钮代码

#pragma once
#include<Windows.h>


namespace projname {

    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 MyForm
    /// </summary>
    public ref class MyForm : public System::Windows::Forms::Form
    {
    public:
        MyForm(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~MyForm()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^ injectButton;
    protected:
    private: System::Windows::Forms::TextBox^ windowName;

    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->injectButton = (gcnew System::Windows::Forms::Button());
            this->windowName = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // injectButton
            // 
            this->injectButton->Font = (gcnew System::Drawing::Font(L\"MS UI Gothic\", 48, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                static_cast<System::Byte>(0)));
            this->injectButton->Location = System::Drawing::Point(12, 384);
            this->injectButton->Name = L\"injectButton\";
            this->injectButton->Size = System::Drawing::Size(537, 87);
            this->injectButton->TabIndex = 0;
            this->injectButton->Text = L\"Inject\";
            this->injectButton->UseVisualStyleBackColor = true;
            this->injectButton->Click += gcnew System::EventHandler(this, &MyForm::injectButton_Click);
            // 
            // windowName
            // 
            this->windowName->Location = System::Drawing::Point(13, 358);
            this->windowName->Name = L\"windowName\";
            this->windowName->Size = System::Drawing::Size(536, 20);
            this->windowName->TabIndex = 1;
            this->windowName->Text = L\"Window Name\";
            // 
            // MyForm
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(561, 483);
            this->Controls->Add(this->windowName);
            this->Controls->Add(this->injectButton);
            this->Name = L\"MyForm\";
            this->Text = L\"projname\";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void injectButton_Click(System::Object^ sender, System::EventArgs^ e) {
        HWND hwnd = FindWindowA(NULL, \"window to attach to\");
        if (hwnd == NULL) { exit(-1); }
        else {
            DWORD procID;
            GetWindowThreadProcessId(hwnd, &procID);
            HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);

            if (procID == NULL) { exit(-1); }
        }
    }
    };
}

    标签: windows user-interface c++-cli


    【解决方案1】:

    如果您将 kernel32.lib 和其他一些添加到链接器中,如果您需要更多帮助,它会起作用 unresolved token (0A000038) extern C 并且存在堆栈溢出问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 2021-09-15
      • 2017-11-13
      相关资源
      最近更新 更多