C++ cli 找不到入口点

C++ cli 找不到入口点,c++-cli,pinvoke,C++ Cli,Pinvoke,我导入两个WinApi函数并在类中使用它们 using namespace System::Runtime::InteropServices; [DllImport("user32",ExactSpelling = true)] extern bool CloseWindow(int hwnd); [DllImport("user32",ExactSpelling = true)] extern int FindWindow(String^ classname,String^ windowna

我导入两个WinApi函数并在类中使用它们

using namespace System::Runtime::InteropServices;

[DllImport("user32",ExactSpelling = true)]
extern bool CloseWindow(int hwnd);
[DllImport("user32",ExactSpelling = true)]
extern int FindWindow(String^ classname,String^ windowname);

public ref class WinApiInvoke
{
public:
    bool CloseWindowCall(String^ title)
    {
        int pointer = FindWindow(nullptr,title);
        return CloseWindow(pointer);
    }
};
然后我在主程序中创建对象并调用
CloseWindowCall
方法

Console::WriteLine("Window's title");
String ^s = Console::ReadLine();
WinApiInvoke^ obj = gcnew WinApiInvoke();
if (obj->CloseWindowCall(s))
    Console::WriteLine("Window successfully closed!");
else Console::WriteLine("Some error occured!");
例如,当我在控制台中编写要关闭的国际象棋泰坦时,我有一个错误
在DLL“user32”中找不到名为“FindWindow”的入口点


什么入口点?

您不正确地使用了ExactSpelling属性。user32.dll中没有FindWindow函数,就像异常消息所说的那样。有芬德温多瓦和芬德温多瓦。第一个处理传统的8位字符串,第二个使用Unicode字符串。接受字符串的任何Windows API函数都有两个版本,在C或C++代码中没有看到这一点,因为Unicode宏在两个之间进行选择。 避免winapi函数的拼写错误,pinvoke marshaller知道如何处理这个问题。如果您有其他错误,正确的声明是:

[DllImport("user32.dll", CharSet = CharSet::Auto, SetLastError = true)]
static IntPtr FindWindow(String^ classname, String^ windowname);

我认为它必须是
[DllImport(“user32.dll”)]
。为什么要从C++/CLI使用p/invoke?您可以只使用混合模式程序集和
#include