Search in sources :

Example 1 with Function

use of com.sun.jna.Function in project jna by java-native-access.

the class StdCallFunctionMapper method getFunctionName.

/**
     * Convert the given Java method into a decorated {@code stdcall} name, if possible.
     *
     * @param library The {@link NativeLibrary} instance
     * @param method The invoked {@link Method}
     * @return The decorated name
     */
@Override
public String getFunctionName(NativeLibrary library, Method method) {
    String name = method.getName();
    int pop = 0;
    Class<?>[] argTypes = method.getParameterTypes();
    for (Class<?> cls : argTypes) {
        pop += getArgumentNativeStackSize(cls);
    }
    String decorated = name + "@" + pop;
    int conv = StdCallLibrary.STDCALL_CONVENTION;
    try {
        Function func = library.getFunction(decorated, conv);
        name = func.getName();
    } catch (UnsatisfiedLinkError e) {
        // try with an explicit underscore
        try {
            Function func = library.getFunction("_" + decorated, conv);
            name = func.getName();
        } catch (UnsatisfiedLinkError e2) {
        // not found; let caller try undecorated version
        }
    }
    return name;
}
Also used : Function(com.sun.jna.Function)

Example 2 with Function

use of com.sun.jna.Function in project jna by java-native-access.

the class COMInvoker method _invokeNativeVoid.

protected void _invokeNativeVoid(int vtableId, Object[] args) {
    Pointer vptr = this.getPointer().getPointer(0);
    // we take the vtable id and multiply with the pointer size (4 bytes on
    // 32bit OS)
    Function func = Function.getFunction(vptr.getPointer(vtableId * Pointer.SIZE));
    func.invokeVoid(args);
}
Also used : Function(com.sun.jna.Function) Pointer(com.sun.jna.Pointer)

Example 3 with Function

use of com.sun.jna.Function in project jna by java-native-access.

the class COMInvoker method _invokeNativeInt.

protected int _invokeNativeInt(int vtableId, Object[] args) {
    Pointer vptr = this.getPointer().getPointer(0);
    // we take the vtable id and multiply with the pointer size (4 bytes on
    // 32bit OS)
    Function func = Function.getFunction(vptr.getPointer(vtableId * Pointer.SIZE));
    return func.invokeInt(args);
}
Also used : Function(com.sun.jna.Function) Pointer(com.sun.jna.Pointer)

Example 4 with Function

use of com.sun.jna.Function in project jna by java-native-access.

the class COMInvoker method _invokeNativeObject.

protected Object _invokeNativeObject(int vtableId, Object[] args, Class<?> returnType) {
    Pointer vptr = this.getPointer().getPointer(0);
    // we take the vtable id and multiply with the pointer size (4 bytes on
    // 32bit OS)
    Function func = Function.getFunction(vptr.getPointer(vtableId * Pointer.SIZE));
    return func.invoke(returnType, args);
}
Also used : Function(com.sun.jna.Function) Pointer(com.sun.jna.Pointer)

Example 5 with Function

use of com.sun.jna.Function in project jna by java-native-access.

the class OpenGL32Util method countGpusNV.

/**
     * Count GPUs
     * @return the number of available GPUs
     */
public static int countGpusNV() {
    // create a dummy window
    HWND hWnd = User32Util.createWindow("Message", null, 0, 0, 0, 0, 0, null, null, null, null);
    HDC hdc = User32.INSTANCE.GetDC(hWnd);
    // set a compatible pixel format
    PIXELFORMATDESCRIPTOR.ByReference pfd = new PIXELFORMATDESCRIPTOR.ByReference();
    pfd.nVersion = 1;
    pfd.dwFlags = WinGDI.PFD_DRAW_TO_WINDOW | WinGDI.PFD_SUPPORT_OPENGL | WinGDI.PFD_DOUBLEBUFFER;
    pfd.iPixelType = WinGDI.PFD_TYPE_RGBA;
    pfd.cColorBits = 24;
    pfd.cDepthBits = 16;
    pfd.iLayerType = WinGDI.PFD_MAIN_PLANE;
    GDI32.INSTANCE.SetPixelFormat(hdc, GDI32.INSTANCE.ChoosePixelFormat(hdc, pfd), pfd);
    // create the OpenGL context to get function address
    WinDef.HGLRC hGLRC = OpenGL32.INSTANCE.wglCreateContext(hdc);
    OpenGL32.INSTANCE.wglMakeCurrent(hdc, hGLRC);
    Pointer funcPointer = OpenGL32.INSTANCE.wglGetProcAddress("wglEnumGpusNV");
    Function fncEnumGpusNV = (funcPointer == null) ? null : Function.getFunction(funcPointer);
    OpenGL32.INSTANCE.wglDeleteContext(hGLRC);
    // destroy the window
    User32.INSTANCE.ReleaseDC(hWnd, hdc);
    User32Util.destroyWindow(hWnd);
    // abort if the nVidia extensions are not present
    if (fncEnumGpusNV == null)
        return 0;
    // enumerate nVidia adapters
    HGLRCByReference hGPU = new HGLRCByReference();
    for (int i = 0; i < 16; i++) {
        Boolean ok = (Boolean) fncEnumGpusNV.invoke(Boolean.class, new Object[] { Integer.valueOf(i), hGPU });
        if (!ok.booleanValue())
            return i;
    }
    return 0;
}
Also used : HDC(com.sun.jna.platform.win32.WinDef.HDC) HWND(com.sun.jna.platform.win32.WinDef.HWND) PIXELFORMATDESCRIPTOR(com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR) Pointer(com.sun.jna.Pointer) HGLRCByReference(com.sun.jna.platform.win32.WinDef.HGLRCByReference) Function(com.sun.jna.Function) HGLRCByReference(com.sun.jna.platform.win32.WinDef.HGLRCByReference)

Aggregations

Function (com.sun.jna.Function)5 Pointer (com.sun.jna.Pointer)4 HDC (com.sun.jna.platform.win32.WinDef.HDC)1 HGLRCByReference (com.sun.jna.platform.win32.WinDef.HGLRCByReference)1 HWND (com.sun.jna.platform.win32.WinDef.HWND)1 PIXELFORMATDESCRIPTOR (com.sun.jna.platform.win32.WinGDI.PIXELFORMATDESCRIPTOR)1