无法找到入口点

时间:2012-05-07 12:03:09

标签: 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^ 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!");

当我在控制台中写作例如Chess Titans关闭时我有一个错误 Unable to find an entry point named 'FindWindow' in DLL 'user32'

什么切入点?

1 个答案:

答案 0 :(得分:2)

您正在使用ExactSpelling属性。 user32.dll中没有FindWindow函数,就像异常消息所说的那样。有FindWindowA和FindWindowW。第一个处理传统的8位字符串,第二个使用Unicode字符串。任何接受字符串的Windows api函数都有两个版本,你不会在C或C ++代码中看到这个,因为UNICODE宏在两者之间进行选择。

避免在winapi函数上使用ExactSpelling,pinvoke marshaller知道如何处理这个问题。你有其他一些错误,正确的声明是:

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