如何从Cygwin程序中调用Win32 API

red*_*ike 6 winapi cygwin

我正在寻找在我正在开发的项目中使用Win32 API.但是我不知道如何从我的cygwin项目中调用Win32 API.有人能指出我正确的方向吗?

Ama*_*9MF 6

可以通过包含"windows.h"头文件从cygwin程序访问Win32 API.这意味着你安装了win32软件包,当然.这是一个示例程序:

#include <iostream>
#include <string>
#include <windows.h>

int main(int argc, char *argv[])
{
    std::string val;

    if (argc > 1)
    {
        val = argv[1];
    }

    std::cout << "You typed: " << val << std::endl;
    ::MessageBox(NULL, val.c_str(), "You Typed:", MB_OK);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

这可以编译并与"make filename"链接,其中filename.cpp包含上述源.然后在bash提示符下键入./filename xxxx来执行.然后xxxx将出现在消息框窗口中.

  • 我觉得我刚刚找到了一张 100 美元的钞票……说真的:这正是我要找的东西! (2认同)