From 6bd7355e47e40bf8f8030b4533a0f2da0b1e2b58 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Wed, 4 Mar 2015 14:04:16 -0500 Subject: Bug 459971 Windows native for Serial Port. Not checking the binaries in until I get closer to the end. Still some API changes I want to make to do more buffering. Done as a Visual Studio 2013 project. I also brough winreg into that sln file as I though I had to make a change in it but didn't in the end. But really should bring them all. Change-Id: I6e7d472763381cdc0ae558d8cd63993bb0460457 Signed-off-by: Doug Schaefer --- core/org.eclipse.cdt.core.win32/library/.gitignore | 8 + .../library/cdt-win32.sln | 47 ++++ .../library/serial/.gitignore | 2 + .../library/serial/dllmain.cpp | 28 ++ .../library/serial/serial.cpp | 149 ++++++++++ .../library/serial/serial.vcxproj | 180 ++++++++++++ .../library/serial/serial.vcxproj.filters | 36 +++ .../library/serial/stdafx.cpp | 14 + .../library/serial/stdafx.h | 22 ++ .../library/serial/targetver.h | 18 ++ .../library/winreg/.gitignore | 1 + .../library/winreg/Makefile | 28 -- .../library/winreg/dllmain.cpp | 28 ++ .../library/winreg/stdafx.cpp | 14 + .../library/winreg/stdafx.h | 22 ++ .../library/winreg/targetver.h | 18 ++ .../library/winreg/winreg.cpp | 304 ++++++++++----------- .../library/winreg/winreg.vcxproj | 175 ++++++++++++ .../library/winreg/winreg.vcxproj.filters | 36 +++ 19 files changed, 949 insertions(+), 181 deletions(-) create mode 100644 core/org.eclipse.cdt.core.win32/library/.gitignore create mode 100644 core/org.eclipse.cdt.core.win32/library/cdt-win32.sln create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/.gitignore create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/dllmain.cpp create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/serial.cpp create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj.filters create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/stdafx.cpp create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/stdafx.h create mode 100644 core/org.eclipse.cdt.core.win32/library/serial/targetver.h create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/.gitignore delete mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/Makefile create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/dllmain.cpp create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/stdafx.cpp create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/stdafx.h create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/targetver.h create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj create mode 100644 core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj.filters (limited to 'core/org.eclipse.cdt.core.win32') diff --git a/core/org.eclipse.cdt.core.win32/library/.gitignore b/core/org.eclipse.cdt.core.win32/library/.gitignore new file mode 100644 index 00000000000..4d4ec54ac04 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/.gitignore @@ -0,0 +1,8 @@ +/ipch/ +*.obj +*.idb +*.pdb +*.sdf +*.suo +*.pch +*.log diff --git a/core/org.eclipse.cdt.core.win32/library/cdt-win32.sln b/core/org.eclipse.cdt.core.win32/library/cdt-win32.sln new file mode 100644 index 00000000000..da36400d228 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/cdt-win32.sln @@ -0,0 +1,47 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "serial", "serial\serial.vcxproj", "{2E2DB53A-62BE-4690-8FCB-209885DD9B3C}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "winreg", "winreg\winreg.vcxproj", "{4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Mixed Platforms = Release|Mixed Platforms + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Debug|Win32.ActiveCfg = Debug|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Debug|Win32.Build.0 = Debug|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Debug|x64.ActiveCfg = Debug|x64 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Debug|x64.Build.0 = Debug|x64 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Release|Mixed Platforms.Build.0 = Release|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Release|Win32.ActiveCfg = Release|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Release|Win32.Build.0 = Release|Win32 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Release|x64.ActiveCfg = Release|x64 + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C}.Release|x64.Build.0 = Release|x64 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Debug|Win32.ActiveCfg = Debug|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Debug|Win32.Build.0 = Debug|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Debug|x64.ActiveCfg = Debug|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Release|Mixed Platforms.Build.0 = Release|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Release|Win32.ActiveCfg = Release|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Release|Win32.Build.0 = Release|Win32 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Release|x64.ActiveCfg = Release|x64 + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/core/org.eclipse.cdt.core.win32/library/serial/.gitignore b/core/org.eclipse.cdt.core.win32/library/serial/.gitignore new file mode 100644 index 00000000000..5d72c45d207 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/.gitignore @@ -0,0 +1,2 @@ +/serial.tlog/ +/serial.vcxproj.user diff --git a/core/org.eclipse.cdt.core.win32/library/serial/dllmain.cpp b/core/org.eclipse.cdt.core.win32/library/serial/dllmain.cpp new file mode 100644 index 00000000000..6e297985f3b --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/dllmain.cpp @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#include "stdafx.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/core/org.eclipse.cdt.core.win32/library/serial/serial.cpp b/core/org.eclipse.cdt.core.win32/library/serial/serial.cpp new file mode 100644 index 00000000000..69a1de31a31 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/serial.cpp @@ -0,0 +1,149 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#include "stdafx.h" + +extern "C" +JNIEXPORT jlong JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_open0 +(JNIEnv *env, jobject jobj, jstring portName, jint baudRate, jint byteSize, jint parity, jint stopBits) +{ + const wchar_t * cportName = (const wchar_t *) env->GetStringChars(portName, NULL); + HANDLE handle = CreateFile(cportName, + GENERIC_READ | GENERIC_WRITE, + 0, + NULL, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + NULL); + + if (handle != INVALID_HANDLE_VALUE) { + DCB dcb = { 0 }; + + if (!GetCommState(handle, &dcb)) { + fprintf(stderr, "Error getting DCB: %S\n", cportName); + return -1; + } + + dcb.BaudRate = baudRate; + dcb.ByteSize = (BYTE) byteSize; + + switch (parity) { + case 0: // None + dcb.fParity = FALSE; + break; + case 1: // Even + dcb.fParity = TRUE; + dcb.Parity = EVENPARITY; + break; + case 2: // Odd + dcb.fParity = TRUE; + dcb.Parity = ODDPARITY; + break; + } + + switch (stopBits) { + case 0: + dcb.StopBits = ONESTOPBIT; + break; + case 1: + dcb.StopBits = TWOSTOPBITS; + break; + } + + if (!SetCommState(handle, &dcb)) { + fprintf(stderr, "Error setting DCB: %S\n", cportName); + return -1; + } + } + + return (jlong) handle; +} + +extern "C" +JNIEXPORT void JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_close0 +(JNIEnv *env, jobject jobj, jlong handle) +{ + CloseHandle((HANDLE) handle); +} + +extern "C" +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_read0 +(JNIEnv *env, jobject jobj, jlong jhandle) +{ + OVERLAPPED olp = { 0 }; + + olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (olp.hEvent == NULL) { + fprintf(stderr, "Error creating event\n"); + fflush(stderr); + return -1; + } + + char buff; + DWORD nwritten; + HANDLE handle = (HANDLE)jhandle; + + if (!ReadFile(handle, &buff, sizeof(buff), &nwritten, &olp)) { + if (GetLastError() != ERROR_IO_PENDING) { + fprintf(stderr, "Error reading from port: %d\n", GetLastError()); + fflush(stderr); + return -1; + } + else { + switch (WaitForSingleObject(olp.hEvent, INFINITE)) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(handle, &olp, &nwritten, FALSE)) { + if (GetLastError() != ERROR_OPERATION_ABORTED) { + fprintf(stderr, "Error waiting for read: %d\n", GetLastError()); + fflush(stderr); + } + return -1; + } + break; + } + } + } + + CloseHandle(olp.hEvent); + return buff; +} + +extern "C" +JNIEXPORT void JNICALL Java_org_eclipse_cdt_utils_serial_SerialPort_write0 +(JNIEnv *env, jobject jobj, jlong jhandle, jint b) +{ + OVERLAPPED olp = { 0 }; + + olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (olp.hEvent == NULL) { + fprintf(stderr, "Error creating event\n"); + return; + } + + char buff = (char) b; + DWORD nwritten; + HANDLE handle = (HANDLE) jhandle; + + if (!WriteFile(handle, &buff, sizeof(buff), &nwritten, &olp)) { + if (GetLastError() != ERROR_IO_PENDING) { + fprintf(stderr, "Error writing to port\n"); + } + else { + switch (WaitForSingleObject(olp.hEvent, INFINITE)) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(handle, &olp, &nwritten, FALSE)) { + fprintf(stderr, "Error waiting for write\n"); + } + } + } + } + + CloseHandle(olp.hEvent); +} diff --git a/core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj b/core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj new file mode 100644 index 00000000000..8e8c5b153d1 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj @@ -0,0 +1,180 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {2E2DB53A-62BE-4690-8FCB-209885DD9B3C} + Win32Proj + serial + + + + DynamicLibrary + true + v120 + Unicode + + + DynamicLibrary + true + v120 + Unicode + + + DynamicLibrary + false + v120 + true + Unicode + + + DynamicLibrary + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + true + + + false + $(SolutionDir)..\..\org.eclipse.cdt.core.win32.x86\os\win32\x86\ + + + + false + $(SolutionDir)..\..\org.eclipse.cdt.core.win32.x86_64\os\win32\x86_64\ + + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;SERIAL_EXPORTS;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Windows + true + + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;SERIAL_EXPORTS;%(PreprocessorDefinitions) + true + MultiThreadedDebug + + + Windows + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;SERIAL_EXPORTS;%(PreprocessorDefinitions) + true + C:\Program Files\Java\jdk1.8.0_31\include;C:\Program Files\Java\jdk1.8.0_31\include\win32;%(AdditionalIncludeDirectories) + MultiThreaded + + + Windows + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;SERIAL_EXPORTS;%(PreprocessorDefinitions) + C:\Program Files\Java\jdk1.8.0_31\include;C:\Program Files\Java\jdk1.8.0_31\include\win32;%(AdditionalIncludeDirectories) + MultiThreaded + + + Windows + true + true + true + + + + + + + + + false + false + + + + + false + false + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj.filters b/core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj.filters new file mode 100644 index 00000000000..240d00d0c19 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/serial.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.win32/library/serial/stdafx.cpp b/core/org.eclipse.cdt.core.win32/library/serial/stdafx.cpp new file mode 100644 index 00000000000..c97de4cd232 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/stdafx.cpp @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/core/org.eclipse.cdt.core.win32/library/serial/stdafx.h b/core/org.eclipse.cdt.core.win32/library/serial/stdafx.h new file mode 100644 index 00000000000..0babced30e7 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/stdafx.h @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/core/org.eclipse.cdt.core.win32/library/serial/targetver.h b/core/org.eclipse.cdt.core.win32/library/serial/targetver.h new file mode 100644 index 00000000000..d27181a16d6 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/serial/targetver.h @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/.gitignore b/core/org.eclipse.cdt.core.win32/library/winreg/.gitignore new file mode 100644 index 00000000000..7d9b212a579 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg/.gitignore @@ -0,0 +1 @@ +/winreg.tlog/ diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/Makefile b/core/org.eclipse.cdt.core.win32/library/winreg/Makefile deleted file mode 100644 index 8335a7dc55d..00000000000 --- a/core/org.eclipse.cdt.core.win32/library/winreg/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -ifeq ($(JAVA_HOME),) -$(error JAVA_HOME not set in environment) -endif - -TARGET = $(INSTALL_DIR)/winreg.dll - -OBJS = winreg.o - -OS = win32 -ARCH = x86 - -JDK_INCLUDES = "$(JAVA_HOME)/include" -JDK_OS_INCLUDES = "$(JAVA_HOME)/include/$(OS)" - -CXX = g++ -CXXFLAGS = -DUNICODE -I$(JDK_INCLUDES) -I$(JDK_OS_INCLUDES) - -INSTALL_DIR = ../../../org.eclipse.cdt.core.$(OS).$(ARCH)/os/$(OS)/$(ARCH) - -all: $(TARGET) - -rebuild: clean all - -clean : - $(RM) $(OBJS) - -$(TARGET) : $(OBJS) - $(CXX) -Wl,--kill-at -shared -o $(TARGET) $(OBJS) diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/dllmain.cpp b/core/org.eclipse.cdt.core.win32/library/winreg/dllmain.cpp new file mode 100644 index 00000000000..6e297985f3b --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg/dllmain.cpp @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#include "stdafx.h" + +BOOL APIENTRY DllMain( HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/stdafx.cpp b/core/org.eclipse.cdt.core.win32/library/winreg/stdafx.cpp new file mode 100644 index 00000000000..c97de4cd232 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg/stdafx.cpp @@ -0,0 +1,14 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/stdafx.h b/core/org.eclipse.cdt.core.win32/library/winreg/stdafx.h new file mode 100644 index 00000000000..0babced30e7 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg/stdafx.h @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#pragma once + +#include "targetver.h" + +#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers +// Windows Header Files: +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/targetver.h b/core/org.eclipse.cdt.core.win32/library/winreg/targetver.h new file mode 100644 index 00000000000..d27181a16d6 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg/targetver.h @@ -0,0 +1,18 @@ +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp index 50818020978..231910a1f77 100644 --- a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp +++ b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.cpp @@ -1,153 +1,151 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 QNX Software Systems - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * QNX Software Systems - initial API and implementation - *******************************************************************************/ -#include -#include -#include - -static jstring getValue(JNIEnv * env, HKEY key, jstring subkey, jstring name) { - const jchar * csubkey = env->GetStringChars(subkey, NULL); - const jchar * cname = env->GetStringChars(name, NULL); - jstring result = NULL; - - HKEY skey; - LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey); - if (rc == ERROR_SUCCESS) { - DWORD type; - wchar_t buffer[256]; - DWORD len = sizeof(buffer); - rc = RegQueryValueEx(skey, (const wchar_t *)cname, NULL, &type, (BYTE *)&buffer, &len); - if (rc == ERROR_SUCCESS) { - result = env->NewString((jchar *)buffer, wcslen(buffer)); - } - RegCloseKey(skey); - } - - env->ReleaseStringChars(subkey, csubkey); - env->ReleaseStringChars(name, cname); - - return result; -} - -extern "C" -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValue( - JNIEnv * env, jobject obj, jstring subkey, jstring name) -{ - return getValue(env, HKEY_LOCAL_MACHINE, subkey, name); -} - -extern "C" -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserValue( - JNIEnv * env, jobject obj, jstring subkey, jstring name) -{ - return getValue(env, HKEY_CURRENT_USER, subkey, name); -} - -/* - * Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0) - * to the key's array of values, return the name of the indexed value. - * The return value is null on any error or when the index is invalid. - */ - -static jstring getValueName(JNIEnv * env, HKEY key, jstring subkey, jint index) { - const jchar * csubkey = env->GetStringChars(subkey, NULL); - jstring result = NULL; - - HKEY skey; - LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey); - if (rc != ERROR_SUCCESS) - return NULL; - - wchar_t valueName[256]; - DWORD nameSize = sizeof(valueName) + 2; - - rc = RegEnumValue(skey, index, - valueName, // UNICODE string - &nameSize, - NULL, NULL, - NULL, // data string - NULL); // size in BYTE of data. - - if (rc == ERROR_SUCCESS) - { - result = env->NewString((jchar *)valueName, nameSize); - } - - RegCloseKey(skey); - - env->ReleaseStringChars(subkey, csubkey); - - return result; -} - -extern "C" -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValueName( - JNIEnv * env, jobject obj, jstring subkey, jint index) -{ - return getValueName(env, HKEY_LOCAL_MACHINE, subkey, index); -} - -extern "C" -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserValueName( - JNIEnv * env, jobject obj, jstring subkey, jint index) -{ - return getValueName(env, HKEY_CURRENT_USER, subkey, index); -} - -/* - * Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0) - * to the key's array of keys, return the name of the indexed key. - * The return value is null on any error or when the index is invalid. - */ - -static jstring getKeyName(JNIEnv * env, HKEY key, jstring subkey, jint index) { - const jchar * csubkey = env->GetStringChars(subkey, NULL); - jstring result = NULL; - - HKEY skey; - LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey); - if (rc != ERROR_SUCCESS) - return NULL; - - wchar_t keyName[256]; - DWORD nameSize = sizeof(keyName) + 2; - - rc = RegEnumKeyEx(skey, index, - keyName, // UNICODE string - &nameSize, - NULL, NULL, - NULL, - NULL); // size in BYTE of data. - - if (rc == ERROR_SUCCESS) - { - result = env->NewString((jchar *)keyName, nameSize); - } - - RegCloseKey(skey); - - env->ReleaseStringChars(subkey, csubkey); - - return result; -} - -extern "C" -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineKeyName( - JNIEnv * env, jobject obj, jstring subkey, jint index) -{ - return getKeyName(env, HKEY_LOCAL_MACHINE, subkey, index); -} - -extern "C" -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserKeyName( - JNIEnv * env, jobject obj, jstring subkey, jint index) -{ - return getKeyName(env, HKEY_CURRENT_USER, subkey, index); -} +/******************************************************************************* + * Copyright (c) 2015 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation + *******************************************************************************/ +#include "stdafx.h" + +static jstring getValue(JNIEnv * env, HKEY key, jstring subkey, jstring name) { + const jchar * csubkey = env->GetStringChars(subkey, NULL); + const jchar * cname = env->GetStringChars(name, NULL); + jstring result = NULL; + + HKEY skey; + LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey); + if (rc == ERROR_SUCCESS) { + DWORD type; + wchar_t buffer[256]; + DWORD len = sizeof(buffer); + rc = RegQueryValueEx(skey, (const wchar_t *)cname, NULL, &type, (BYTE *)&buffer, &len); + if (rc == ERROR_SUCCESS) { + result = env->NewString((jchar *) buffer, (jsize) wcslen(buffer)); + } + RegCloseKey(skey); + } + + env->ReleaseStringChars(subkey, csubkey); + env->ReleaseStringChars(name, cname); + + return result; +} + +extern "C" +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValue( +JNIEnv * env, jobject obj, jstring subkey, jstring name) +{ + return getValue(env, HKEY_LOCAL_MACHINE, subkey, name); +} + +extern "C" +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserValue( +JNIEnv * env, jobject obj, jstring subkey, jstring name) +{ + return getValue(env, HKEY_CURRENT_USER, subkey, name); +} + +/* +* Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0) +* to the key's array of values, return the name of the indexed value. +* The return value is null on any error or when the index is invalid. +*/ + +static jstring getValueName(JNIEnv * env, HKEY key, jstring subkey, jint index) { + const jchar * csubkey = env->GetStringChars(subkey, NULL); + jstring result = NULL; + + HKEY skey; + LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey); + if (rc != ERROR_SUCCESS) + return NULL; + + wchar_t valueName[256]; + DWORD nameSize = sizeof(valueName) + 2; + + rc = RegEnumValue(skey, index, + valueName, // UNICODE string + &nameSize, + NULL, NULL, + NULL, // data string + NULL); // size in BYTE of data. + + if (rc == ERROR_SUCCESS) + { + result = env->NewString((jchar *)valueName, nameSize); + } + + RegCloseKey(skey); + + env->ReleaseStringChars(subkey, csubkey); + + return result; +} + +extern "C" +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineValueName( +JNIEnv * env, jobject obj, jstring subkey, jint index) +{ + return getValueName(env, HKEY_LOCAL_MACHINE, subkey, index); +} + +extern "C" +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserValueName( +JNIEnv * env, jobject obj, jstring subkey, jint index) +{ + return getValueName(env, HKEY_CURRENT_USER, subkey, index); +} + +/* +* Given a subkey (string) under HKEY_LOCAL_MACHINE, and an index (starting from 0) +* to the key's array of keys, return the name of the indexed key. +* The return value is null on any error or when the index is invalid. +*/ + +static jstring getKeyName(JNIEnv * env, HKEY key, jstring subkey, jint index) { + const jchar * csubkey = env->GetStringChars(subkey, NULL); + jstring result = NULL; + + HKEY skey; + LONG rc = RegOpenKeyEx(key, (const wchar_t *)csubkey, 0, KEY_READ, &skey); + if (rc != ERROR_SUCCESS) + return NULL; + + wchar_t keyName[256]; + DWORD nameSize = sizeof(keyName) + 2; + + rc = RegEnumKeyEx(skey, index, + keyName, // UNICODE string + &nameSize, + NULL, NULL, + NULL, + NULL); // size in BYTE of data. + + if (rc == ERROR_SUCCESS) + { + result = env->NewString((jchar *)keyName, nameSize); + } + + RegCloseKey(skey); + + env->ReleaseStringChars(subkey, csubkey); + + return result; +} + +extern "C" +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getLocalMachineKeyName( +JNIEnv * env, jobject obj, jstring subkey, jint index) +{ + return getKeyName(env, HKEY_LOCAL_MACHINE, subkey, index); +} + +extern "C" +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_utils_WindowsRegistry_getCurrentUserKeyName( +JNIEnv * env, jobject obj, jstring subkey, jint index) +{ + return getKeyName(env, HKEY_CURRENT_USER, subkey, index); +} diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj new file mode 100644 index 00000000000..994ba556f5a --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj @@ -0,0 +1,175 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {4CA57EA3-42F2-4CC1-8E95-5C707A8E7363} + Win32Proj + winreg + + + + DynamicLibrary + true + v120 + Unicode + + + DynamicLibrary + true + v120 + Unicode + + + DynamicLibrary + false + v120 + true + Unicode + + + DynamicLibrary + false + v120 + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + true + + + false + $(SolutionDir)..\..\org.eclipse.cdt.core.win32.x86\os\win32\x86\ + + + + false + $(SolutionDir)..\..\org.eclipse.cdt.core.win32.x86_64\os\win32\x86_64\ + + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;WINREG_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + + + Use + Level3 + Disabled + WIN32;_DEBUG;_WINDOWS;_USRDLL;WINREG_EXPORTS;%(PreprocessorDefinitions) + + + Windows + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;WINREG_EXPORTS;%(PreprocessorDefinitions) + C:\Program Files\Java\jdk1.8.0_31\include;C:\Program Files\Java\jdk1.8.0_31\include\win32 + MultiThreaded + + + Windows + true + true + true + + + + + Level3 + Use + MaxSpeed + true + true + WIN32;NDEBUG;_WINDOWS;_USRDLL;WINREG_EXPORTS;%(PreprocessorDefinitions) + C:\Program Files\Java\jdk1.8.0_31\include;C:\Program Files\Java\jdk1.8.0_31\include\win32 + MultiThreaded + + + Windows + true + true + true + + + + + + + + + false + false + + + + + false + false + + + + + + + Create + Create + Create + Create + + + + + + + \ No newline at end of file diff --git a/core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj.filters b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj.filters new file mode 100644 index 00000000000..41d99849235 --- /dev/null +++ b/core/org.eclipse.cdt.core.win32/library/winreg/winreg.vcxproj.filters @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file -- cgit v1.2.3