Make Windows delay delay-load the FTDI driver itself

This commit is contained in:
hedgecrw85 2018-04-03 11:13:14 -05:00
parent 75e850fb8a
commit b15e79a4d9
13 changed files with 42 additions and 9 deletions

View File

@ -5,7 +5,7 @@ apply plugin: 'osgi'
group = 'com.fazecast'
archivesBaseName = 'jSerialComm'
version = '2.0.0'
version = '2.0.1'
ext.moduleName = 'com.fazecast.jSerialComm'
assert hasProperty('java6Home'): "Set the property 'java6Home' in your gradle.properties file pointing to a Java 6 JDK installation"

View File

@ -2,9 +2,9 @@
COMPILE = cl
LINK = link
CFLAGS = /c /O2 /GF /GL /MT /EHsc /fp:precise /J /nologo /TP
LDFLAGS = /DLL /LTCG /NOASSEMBLY /NOLOGO
LDFLAGS = /DLL /LTCG /NOASSEMBLY /NOLOGO /DELAYLOAD:ftd2xx.dll
INCLUDES = /I"$(JDK_HOME)/include" /I"$(JDK_HOME)/include/win32"
LIBRARIES = Advapi32.lib SetupAPI.lib
LIBRARIES = Advapi32.lib SetupAPI.lib DelayImp.lib
DELETE = @del /q /f
RMDIR = @rd /q /s
MKDIR = @md

View File

@ -2,7 +2,7 @@
* SerialPort_Windows.c
*
* Created on: Feb 25, 2012
* Last Updated on: Apr 01, 2018
* Last Updated on: Apr 03, 2018
* Author: Will Hedgecock
*
* Copyright (C) 2012-2018 Fazecast, Inc.
@ -30,6 +30,7 @@
#define WIN32_LEAN_AND_MEAN
#include <initguid.h>
#include <windows.h>
#include <delayimp.h>
#include <stdlib.h>
#include <string.h>
#include <setupapi.h>
@ -56,6 +57,38 @@ jfieldID readTimeoutField;
jfieldID writeTimeoutField;
jfieldID eventFlagsField;
// FTDI DLL library loader
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
HINSTANCE hDllInstance = (HINSTANCE)&__ImageBase;
HMODULE LocalLoadLibrary(LPCSTR pszModuleName)
{
CHAR szPath[MAX_PATH] = "";
DWORD cchPath = GetModuleFileNameA(hDllInstance, szPath, MAX_PATH);
while (cchPath > 0)
{
switch(szPath[cchPath - 1])
{
case '\\':
case '/':
case ':':
break;
default:
--cchPath;
continue;
}
break;
}
lstrcpynA(szPath + cchPath, pszModuleName, MAX_PATH - cchPath);
return LoadLibraryA(szPath);
}
FARPROC WINAPI DllLoadNotifyHook(unsigned dliNotify, PDelayLoadInfo pdli)
{
if (dliNotify == dliNotePreLoadLibrary)
return (FARPROC)LocalLoadLibrary(pdli->szDll);
return NULL;
}
extern "C" const PfnDliHook __pfnDliNotifyHook2 = DllLoadNotifyHook;
JNIEXPORT jobjectArray JNICALL Java_com_fazecast_jSerialComm_SerialPort_getCommPorts(JNIEnv *env, jclass serialComm)
{
HKEY keyHandle1, keyHandle2, keyHandle3, keyHandle4, keyHandle5;

View File

@ -41,7 +41,7 @@ import java.util.Date;
* This class provides native access to serial ports and devices without requiring external libraries or tools.
*
* @author Will Hedgecock &lt;will.hedgecock@fazecast.com&gt;
* @version 2.0.0
* @version 2.0.1
* @see java.io.InputStream
* @see java.io.OutputStream
*/
@ -185,7 +185,7 @@ public final class SerialPort
tempNativeLibrary.deleteOnExit();
if (isWindows)
{
ftdiFileName = tempFileDirectory + (new Date()).getTime() + "-ftd2xx.dll";
ftdiFileName = tempFileDirectory + "ftd2xx.dll";
tempFtdiLibrary = new File(ftdiFileName);
tempFtdiLibrary.deleteOnExit();
}

View File

@ -31,7 +31,7 @@ import java.util.EventListener;
* This interface must be implemented to enable simple event-based serial port I/O.
*
* @author Will Hedgecock &lt;will.hedgecock@fazecast.com&gt;
* @version 2.0.0
* @version 2.0.1
* @see java.util.EventListener
*/
public interface SerialPortDataListener extends EventListener

View File

@ -31,7 +31,7 @@ import java.util.EventObject;
* This class describes an asynchronous serial port event.
*
* @author Will Hedgecock &lt;will.hedgecock@fazecast.com&gt;
* @version 2.0.0
* @version 2.0.1
* @see java.util.EventObject
*/
public final class SerialPortEvent extends EventObject

View File

@ -31,7 +31,7 @@ package com.fazecast.jSerialComm;
* <i>Note</i>: Using this interface will negate any serial port read timeout settings since they make no sense in an asynchronous context.
*
* @author Will Hedgecock &lt;will.hedgecock@fazecast.com&gt;
* @version 2.0.0
* @version 2.0.1
* @see com.fazecast.jSerialComm.SerialPortDataListener
* @see java.util.EventListener
*/