分享

Calling the Win32 API from Java | J/Invoke

 sdyjmc 2010-10-09

Calling the Win32 API from Java

To make calling the Win32 API easier, the com.jinvoke.win32 package provides helper classes that contain J/Invoke declaration of functions for the most commonly used Win32 DLLs. You just need to import the class you need and directly call the stubbed out Java method corresponding to the Win32 API you want to call.

The available APIs are declared in a set of classes, one for each Windows DLL, as shown in the following table.

J/Invoke Win32 Helper Class

DLL Name

Functionality

com.jinvoke.win32.Kernel32

KERNEL32.DLL

Base services

com.jinvoke.win32.Gdi32

GDI32.DLL

Graphics device interface

com.jinvoke.win32.User32

USER32.DLL

User interface

com.jinvoke.win32.Advapi32

ADVAPI32.DLL

Crypto API, event logging

com.jinvoke.win32.Shell32

SHELL32.DLL

Windows shell API

com.jinvoke.win32.Winmm

WINMM.DLL

Multimedia

com.jinvoke.win32.WinInet

WININET.DLL

Internet

The Win32 API uses many constants and structures which are defined in com.jinvoke.win32.WinConstants class and the com.jinvoke.win32.structs package respectively.

For instance, MessageBox is contained in USER32 .DLL and therefore declared in the User32 class. Import this class and you can call MessageBox directly. Thus, the previous example could be simplified as shown below:

import com.jinvoke.win32.User32;
import
 static com.jinvoke.win32.WinConstants.*;

public class CallingWin32API {
    public static void main(String[] args) {
        User32.MessageBox(0, "This MessageBox is a native Win32 MessageBox", "Caption", MB_ICONINFORMATION|MB_OK);
    }
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多