Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call the Win32 API from a Cygwin program

Tags:

cygwin

winapi

I'm looking to use the Win32 API in a project I'm working on. However I have no idea how to call the Win32 API from my cygwin project. Can someone point me in the correct direction?

like image 870
redhotspike Avatar asked Apr 02 '12 18:04

redhotspike


People also ask

On which operating system could you use the Win32 API?

Win32 APIs exist for many features and technologies in Windows 10, including core user interface and windowing APIs, audio and graphics, and networking.

How do I use Windows API?

To call a Windows API using the DllImport attribute Open a new Windows Application project by clicking New on the File menu, and then clicking Project. The New Project dialog box appears. Select Windows Application from the list of Visual Basic project templates. The new project is displayed.

What is Win32 APIs?

Alternatively referred to as the Windows API and WinAPI, Win32 is the main set of Microsoft Windows APIs used for developing 32-bit applications. These APIs are responsible for functions in the following categories: Administration and Management - Install, configure, and service applications or systems.

Is Win32 API written in C?

The windows API is implemented in the C programming language.


2 Answers

The Win32 API can be accessed from a cygwin program by including the "windows.h" header file. It implies that you have the win32 packages installed, of course. Here is an example program:

#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;
}

This can be compiled and linked with "make filename" where filename.cpp contains the above source. Then execute by typing ./filename xxxx at the bash prompt. Then xxxx will appear in a message box window.

like image 126
Amardeep AC9MF Avatar answered Nov 03 '22 15:11

Amardeep AC9MF


You could look at the Cygwin FAQ (specifically 6.9 How do I use Win32 API calls?)

Of course you will need to get a hold of the WIN32API headers -- your best option is to download/install a fre c++ compiler (e.g. MinGW) and refer to its headers.

like image 25
Attila Avatar answered Nov 03 '22 15:11

Attila