1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "sal/config.h" 25 26 #include <stddef.h> 27 28 #include <Windows.h> 29 30 #include "jni.h" 31 #include "sal/types.h" 32 33 static HMODULE module; 34 35 static FARPROC getFunction(char const * name) { 36 return GetProcAddress(module, name); 37 } 38 39 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { 40 (void) lpvReserved; 41 if (fdwReason == DLL_PROCESS_ATTACH) { 42 wchar_t path[32767]; 43 DWORD size; 44 size = GetModuleFileNameW(hinstDLL, path, 32767); 45 if (size == 0) { 46 return FALSE; 47 } 48 path[size - 5] = L'x'; /* ...\jpipe.dll -> ...\jpipx.dll */ 49 module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); 50 if (module == NULL) { 51 return FALSE; 52 } 53 } 54 return TRUE; 55 } 56 57 SAL_DLLPUBLIC_EXPORT void JNICALL 58 Java_com_sun_star_lib_connections_pipe_PipeConnection_createJNI( 59 JNIEnv * env, jobject obj_this, jstring name) 60 { 61 (*(void (*)(JNIEnv *, jobject, jstring)) 62 getFunction("PipeConnection_create"))(env, obj_this, name); 63 } 64 65 SAL_DLLPUBLIC_EXPORT void JNICALL 66 Java_com_sun_star_lib_connections_pipe_PipeConnection_closeJNI( 67 JNIEnv * env, jobject obj_this) 68 { 69 (*(void (*)(JNIEnv *, jobject)) 70 getFunction("PipeConnection_close"))(env, obj_this); 71 } 72 73 SAL_DLLPUBLIC_EXPORT jint JNICALL 74 Java_com_sun_star_lib_connections_pipe_PipeConnection_readJNI( 75 JNIEnv * env, jobject obj_this, jobjectArray buffer, jint len) 76 { 77 return (*(jint (*)(JNIEnv *, jobject, jobjectArray, jint)) 78 getFunction("PipeConnection_read"))(env, obj_this, buffer, len); 79 } 80 81 SAL_DLLPUBLIC_EXPORT void JNICALL 82 Java_com_sun_star_lib_connections_pipe_PipeConnection_writeJNI( 83 JNIEnv * env, jobject obj_this, jbyteArray buffer) 84 { 85 (*(void (*)(JNIEnv *, jobject, jbyteArray)) 86 getFunction("PipeConnection_write"))(env, obj_this, buffer); 87 } 88 89 SAL_DLLPUBLIC_EXPORT void JNICALL 90 Java_com_sun_star_lib_connections_pipe_PipeConnection_flushJNI( 91 JNIEnv * env, jobject obj_this) 92 { 93 (*(void (*)(JNIEnv *, jobject)) 94 getFunction("PipeConnection_flush"))(env, obj_this); 95 } 96