我嘗試在VS 2010中創建一個託管C++程序集,以與WinAPI進行接口並將其用於其他C#程序集。我讀過所有文章,甚至在GitHub的代碼中搜索,但都沒有成功。 也許它關於錯誤消息中的__clrcall,它不應該是__stdcall嗎?有任何想法嗎?無法從'LRESULT(__clrcall ....)'轉換爲'WNDPROC'
確切的錯誤信息是:
錯誤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;
}
};
}
試試'w.lpfnWndProc =(WNDPROC)WindowProc;' –
@BartekBanachewicz這可能不起作用。它將刪除編譯器錯誤,但您可能會收到運行時錯誤。 – user1610015
試試'w.lpfnWndProc =&Win32Demo :: WindowProc;' – acraig5075