1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "sal/config.h" 29 30 #include <stddef.h> 31 32 #include <Windows.h> 33 34 #include "jni.h" 35 #include "sal/types.h" 36 37 static HMODULE module; 38 39 static FARPROC getFunction(char const * name) { 40 return GetProcAddress(module, name); 41 } 42 43 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 44 (void) lpvReserved; 45 if (fdwReason == DLL_PROCESS_ATTACH) { 46 wchar_t path[32767]; 47 DWORD size; 48 size = GetModuleFileNameW(hinstDLL, path, 32767); 49 if (size == 0) { 50 return FALSE; 51 } 52 path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */ 53 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 54 if (module == NULL) { 55 return FALSE; 56 } 57 } 58 return TRUE; 59 } 60 61 SAL_DLLPUBLIC_EXPORT void JNICALL 62 Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI( 63 JNIEnv * env, jobject obj_this, jstring name) 64 { 65 (*(void (*)(JNIEnv *, jobject, jstring)) 66 getFunction("PipeConnection_create"))(env, obj_this, name); 67 } 68 69 SAL_DLLPUBLIC_EXPORT void JNICALL 70 Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI( 71 JNIEnv * env, jobject obj_this) 72 { 73 (*(void (*)(JNIEnv *, jobject)) 74 getFunction("PipeConnection_close"))(env, obj_this); 75 } 76 77 SAL_DLLPUBLIC_EXPORT jint JNICALL 78 Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI( 79 JNIEnv * env, jobject obj_this, jobjectArray buffer, jint len) 80 { 81 return (*(jint (*)(JNIEnv *, jobject, jobjectArray, jint)) 82 getFunction("PipeConnection_read"))(env, obj_this, buffer, len); 83 } 84 85 SAL_DLLPUBLIC_EXPORT void JNICALL 86 Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI( 87 JNIEnv * env, jobject obj_this, jbyteArray buffer) 88 { 89 (*(void (*)(JNIEnv *, jobject, jbyteArray)) 90 getFunction("PipeConnection_write"))(env, obj_this, buffer); 91 } 92 93 SAL_DLLPUBLIC_EXPORT void JNICALL 94 Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI( 95 JNIEnv * env, jobject obj_this) 96 { 97 (*(void (*)(JNIEnv *, jobject)) 98 getFunction("PipeConnection_flush"))(env, obj_this); 99 } 100