using HWND in C++ CLR build error (.NET core 8)

cebuhax0r 46 Reputation points
2024-07-02T09:32:16.24+00:00

I have a C++ CLR that contains windows forms on it, the project is a C++ CLR DLL, somewhat related to this: https://learn.microsoft.com/en-us/answers/questions/1745336/porting-c-clr-net-framework-winform-to-net-8

however, when I declare a variable for native HWND, without even using it. I get the following build error

1>C:\dump\ProjectMigrateNet8\WinformDLL\MyForm.h(19,3): error C2327: 'System::Windows::Forms::Control::HWND': is not a type name, static, or enumerator

here is the code

#pragma once
#include <wtypes.h>
namespace WinformDLL {
	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
	{
	private:
		HWND m_window;
	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:
		/// <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();
			// 
			// MyForm
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(509, 211);
			this->Name = L"MyForm";
			this->Text = L"MyForm";
			this->ResumeLayout(false);
		}
#pragma endregion
	};
}

I already added the following framework references in the project file

    <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
    <FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" />
    <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />

The thing is, Im doing this as I am porting a C++ CLR project that uses HWND in some place, i created the above code just to test.

How do I resolve the issue?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,625 questions
{count} votes