Archive for the ‘Win32 API’ Category

  1. Hello, Win32 API(C++/CLI) World!

    Posted on 4月 15th, 2012 by cx20

    Win32 API(C++/CLI)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は C++/CLI からの呼出し例である。

    ソースコード

    #include <windows.h>
    #include <tchar.h>
     
    int _tmain( int argc, TCHAR* argv[] )
    {
        MessageBox( NULL, _T("Hello, Win32 API(C++/CLI) World!"), _T("Hello, World!"), MB_OK );
        return 0;
    }

    コンパイル方法(Visual C++)

    C:¥> cl hello.cpp /clr /link user32.lib

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API(C++/CLI) World!
    ---------------------------
    OK   
    ---------------------------
  2. Hello, Win32 API(C++) World!

    Posted on 4月 14th, 2012 by cx20

    Win32 API(C++)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は C++ からの呼出し例である。

    ソースコード

    #include <windows.h>
    #include <tchar.h>
     
    int _tmain( int argc, TCHAR* argv[] )
    {
        MessageBox( NULL, _T("Hello, Win32 API(C++) World!"), _T("Hello, World!"), MB_OK );
        return 0;
    }

    コンパイル方法(Visual C++)

    C:¥> cl hello.cpp /link user32.lib

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API(C++) World!
    ---------------------------
    OK   
    ---------------------------
  3. Hello, Win32 API(C言語) World!

    Posted on 4月 13th, 2012 by cx20

    Win32 API(C言語)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。
    以下は C言語 からの呼出し例である。

    ソースコード

    #include <windows.h>
    #include <tchar.h>
     
    int _tmain( int argc, TCHAR* argv[] )
    {
        MessageBox( NULL, _T("Hello, Win32 API World!"), _T("Hello, World!"), MB_OK );
        return 0;
    }

    コンパイル方法(Visual C++)

    C:¥> cl hello.c /link user32.lib

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API World!
    ---------------------------
    OK   
    ---------------------------
  4. Hello, Win32 API(GUI) World!

    Posted on 4月 12th, 2012 by cx20

    Win32 API(GUI)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。

    ソースコード

    #include <windows.h>
    #include <tchar.h>
     
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
    {
        MessageBox( NULL, _T("Hello, Win32 API(GUI) World!"), _T("Hello, World!"), MB_OK );
        return 0;
    }

    コンパイル方法(Visual C++)

    C:¥> cl hello.c /link user32.lib /SUBSYSTEM:WINDOWS

    実行結果

    ---------------------------
    Hello, World!
    ---------------------------
    Hello, Win32 API(GUI) World!
    ---------------------------
    OK   
    ---------------------------
  5. Hello, Win32 API(CUI) World!

    Posted on 4月 11th, 2012 by cx20

    Win32 API(CUI)

    Win32 API は、Windows の機能にアクセスする為の API(Application Programming Interface)である。

    ソースコード

    #include <windows.h>
    #include <tchar.h>
     
    int _tmain( int argc, TCHAR* argv[] )
    {
        HANDLE  hStdOutput;
        DWORD   dwSize;
        TCHAR   szBuf[256];
     
        lstrcpy( szBuf, _T("Hello, Win32 API(CUI) World!n") );
        hStdOutput = GetStdHandle( STD_OUTPUT_HANDLE );
        WriteConsole( hStdOutput, szBuf, lstrlen(szBuf), &dwSize, NULL );
     
        return 0;
    }

    コンパイル方法(Visual C++)

    C:¥> cl hello.c /link /SUBSYSTEM:CONSOLE

    実行結果

    Hello, Win32 API(CUI) World!