我尝试在 VS 2010 中创建一个托管 C++ 程序集以与 WinAPI 交互并在我的其他 C# 程序集中使用它。我已经阅读了所有帖子,甚至在 GitHub 中的代码中搜索过,但都没有成功。也许是关于错误消息中的__clrcall,不应该是__stdcall吗?有任何想法吗?
确切的错误信息是:
错误 C2440:“=”:无法从“LRESULT (__clrcall xxx::Win32Demo::*)(HWND,UINT,WPARAM,LPARAM)”转换为“WNDPROC”
源代码:
#pragma once
using namespace System;
using namespace System::Drawing;
#include "stdafx.h"
#include "windows.h"
namespace xxx
{
ref class Win32Demo
{
private: HWND__ * handle;
private: static Char * windowClass;
public:
Win32Demo(void)
{
}
static Win32Demo()
{
tagWNDCLASSEXW w;
windowClass = (wchar_t*) L"Hello";
w.cbSize = sizeof(tagWNDCLASSEXW);
w.style = 0x803;
w.lpfnWndProc = WindowProc; // Error
w.cbClsExtra = 0;
w.cbWndExtra = 0;
w.hInstance = 0;
w.hIcon = 0;
w.hCursor = 0;
w.hbrBackground = CreateSolidBrush(0);
w.lpszMenuName = NULL;
w.lpszClassName = windowClass;
w.hIconSm = 0;
}
public :
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return 0;
}
};
}