This commit is contained in:
34
cpp/JavaWinampApi/Makefile.win
Normal file
34
cpp/JavaWinampApi/Makefile.win
Normal file
@@ -0,0 +1,34 @@
|
||||
# Project: wpcom
|
||||
# Makefile created by Dev-C++ 4.9.9.2
|
||||
|
||||
CPP = g++.exe
|
||||
CC = gcc.exe
|
||||
WINDRES = windres.exe
|
||||
RES =
|
||||
OBJ = WinampController.o $(RES)
|
||||
LINKOBJ = WinampController.o $(RES)
|
||||
LIBS = -L"E:/java/Dev-Cpp/lib" --no-export-all-symbols --add-stdcall-alias
|
||||
INCS = -I"E:/java/Dev-Cpp/include" -I"E:/Program Files/Java/jdk1.6.0_11/include" -I"E:/Program Files/Java/jdk1.6.0_11/include/win32"
|
||||
CXXINCS = -I"E:/java/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"E:/java/Dev-Cpp/include/c++/3.4.2/backward" -I"E:/java/Dev-Cpp/include/c++/3.4.2/mingw32" -I"E:/java/Dev-Cpp/include/c++/3.4.2" -I"E:/java/Dev-Cpp/include" -I"E:/Program Files/Java/jdk1.6.0_11/include" -I"E:/Program Files/Java/jdk1.6.0_11/include/win32"
|
||||
BIN = ../../wpcom.dll
|
||||
CXXFLAGS = $(CXXINCS) -DBUILDING_DLL=1
|
||||
CFLAGS = $(INCS) -DBUILDING_DLL=1
|
||||
RM = rm -f
|
||||
|
||||
.PHONY: all all-before all-after clean clean-custom
|
||||
|
||||
all: all-before ../../wpcom.dll all-after
|
||||
|
||||
|
||||
clean: clean-custom
|
||||
${RM} $(OBJ) $(BIN)
|
||||
|
||||
DLLWRAP=dllwrap.exe
|
||||
DEFFILE=../../libwpcom.def
|
||||
STATICLIB=../../libwpcom.a
|
||||
|
||||
$(BIN): $(LINKOBJ)
|
||||
$(DLLWRAP) --output-def $(DEFFILE) --implib $(STATICLIB) $(LINKOBJ) $(LIBS) -o $(BIN)
|
||||
|
||||
WinampController.o: WinampController.c
|
||||
$(CC) -c WinampController.c -o WinampController.o $(CFLAGS)
|
||||
62
cpp/JavaWinampApi/WINAMPCMD.H
Normal file
62
cpp/JavaWinampApi/WINAMPCMD.H
Normal file
@@ -0,0 +1,62 @@
|
||||
#define WINAMP_FILE_QUIT 40001
|
||||
#define WINAMP_OPTIONS_PREFS 40012
|
||||
#define WINAMP_OPTIONS_AOT 40019
|
||||
#define WINAMP_FILE_REPEAT 40022
|
||||
#define WINAMP_FILE_SHUFFLE 40023
|
||||
#define WINAMP_HIGH_PRIORITY 40025
|
||||
#define WINAMP_FILE_PLAY 40029
|
||||
#define WINAMP_OPTIONS_EQ 40036
|
||||
#define WINAMP_OPTIONS_ELAPSED 40037
|
||||
#define WINAMP_OPTIONS_REMAINING 40038
|
||||
#define WINAMP_OPTIONS_PLEDIT 40040
|
||||
#define WINAMP_HELP_ABOUT 40041
|
||||
#define WINAMP_MAINMENU 40043
|
||||
#define WINAMP_BUTTON1 40044
|
||||
#define WINAMP_BUTTON2 40045
|
||||
#define WINAMP_BUTTON3 40046
|
||||
#define WINAMP_BUTTON4 40047
|
||||
#define WINAMP_BUTTON5 40048
|
||||
#define WINAMP_VOLUMEUP 40058
|
||||
#define WINAMP_VOLUMEDOWN 40059
|
||||
#define WINAMP_FFWD5S 40060
|
||||
#define WINAMP_REW5S 40061
|
||||
#define WINAMP_NEXT_WINDOW 40063
|
||||
#define WINAMP_OPTIONS_WINDOWSHADE 40064
|
||||
#define WINAMP_BUTTON1_SHIFT 40144
|
||||
#define WINAMP_BUTTON2_SHIFT 40145
|
||||
#define WINAMP_BUTTON3_SHIFT 40146
|
||||
#define WINAMP_BUTTON4_SHIFT 40147
|
||||
#define WINAMP_BUTTON5_SHIFT 40148
|
||||
#define WINAMP_BUTTON1_CTRL 40154
|
||||
#define WINAMP_BUTTON2_CTRL 40155
|
||||
#define WINAMP_BUTTON3_CTRL 40156
|
||||
#define WINAMP_BUTTON4_CTRL 40157
|
||||
#define WINAMP_BUTTON5_CTRL 40158
|
||||
#define WINAMP_OPTIONS_DSIZE 40165
|
||||
#define IDC_SORT_FILENAME 40166
|
||||
#define IDC_SORT_FILETITLE 40167
|
||||
#define IDC_SORT_ENTIREFILENAME 40168
|
||||
#define IDC_SELECTALL 40169
|
||||
#define IDC_SELECTNONE 40170
|
||||
#define IDC_SELECTINV 40171
|
||||
#define IDM_EQ_LOADPRE 40172
|
||||
#define IDM_EQ_LOADMP3 40173
|
||||
#define IDM_EQ_LOADDEFAULT 40174
|
||||
#define IDM_EQ_SAVEPRE 40175
|
||||
#define IDM_EQ_SAVEMP3 40176
|
||||
#define IDM_EQ_SAVEDEFAULT 40177
|
||||
#define IDM_EQ_DELPRE 40178
|
||||
#define IDM_EQ_DELMP3 40180
|
||||
#define IDC_PLAYLIST_PLAY 40184
|
||||
#define WINAMP_FILE_LOC 40185
|
||||
#define WINAMP_OPTIONS_EASYMOVE 40186
|
||||
#define WINAMP_FILE_DIR 40187
|
||||
#define WINAMP_EDIT_ID3 40188
|
||||
#define WINAMP_TOGGLE_AUTOSCROLL 40189
|
||||
#define WINAMP_VISSETUP 40190
|
||||
#define WINAMP_PLGSETUP 40191
|
||||
#define WINAMP_VISPLUGIN 40192
|
||||
#define WINAMP_JUMP 40193
|
||||
#define WINAMP_JUMPFILE 40194
|
||||
#define WINAMP_JUMP10FWD 40195
|
||||
#define WINAMP_JUMP10BACK 40197
|
||||
587
cpp/JavaWinampApi/WinampController.c
Normal file
587
cpp/JavaWinampApi/WinampController.c
Normal file
@@ -0,0 +1,587 @@
|
||||
/* meu .h */
|
||||
#include "WinampController.h"
|
||||
|
||||
/* mingw */
|
||||
#include <windows.h>
|
||||
#include <w32api.h>
|
||||
#include <winuser.h>
|
||||
|
||||
/* winamp sdk */
|
||||
#include "wa_ipc.h"
|
||||
#include "WINAMPCMD.H"
|
||||
|
||||
const int WA_CLOSE = 40001 ;
|
||||
const int WA_PLAY = WINAMP_BUTTON2;
|
||||
const int WA_STOP = WINAMP_BUTTON4;
|
||||
const int WA_PAUSE = WINAMP_BUTTON3;
|
||||
const int WA_PREVTRACK = WINAMP_BUTTON1;
|
||||
const int WA_NEXTTRACK = WINAMP_BUTTON5;
|
||||
const int WA_FWD5SECS = WINAMP_FFWD5S;
|
||||
const int WA_REW5SECS = WINAMP_REW5S;
|
||||
|
||||
const int WA_PLAYLISTLEN = IPC_GETLISTLENGTH;
|
||||
const int WA_SETVOLUME = IPC_SETVOLUME;
|
||||
const int WA_SETPLAYLISTPOS = IPC_SETPLAYLISTPOS;
|
||||
const int WA_WRITEPLAYLIST = IPC_WRITEPLAYLIST;
|
||||
const int WA_ENQUEUEFILE = IPC_ENQUEUEFILE;
|
||||
|
||||
const int WA_VOLUMEUP = WINAMP_VOLUMEUP;
|
||||
const int WA_VOLUMEDOWN = WINAMP_VOLUMEDOWN;
|
||||
|
||||
const int WA_CLEARPLAYLIST = IPC_DELETE;
|
||||
const int WA_NOTHING = 0;
|
||||
const int WA_TRACK_LENGTH = 1;
|
||||
|
||||
const int WA_RESTART = IPC_RESTARTWINAMP;
|
||||
const int WA_REFRESHPLCACHE = IPC_REFRESHPLCACHE;
|
||||
const int WA_GETSHUFFLESTATUS = IPC_GET_SHUFFLE;
|
||||
const int WA_GETREPEATSTATUS = IPC_GET_REPEAT;
|
||||
const int WA_SETSHUFFLESTATUS = IPC_SET_SHUFFLE;
|
||||
const int WA_SETREPEATSTATUS = IPC_SET_REPEAT;
|
||||
|
||||
const int WA_GETSTATUS = IPC_ISPLAYING;
|
||||
|
||||
const int WA_GETLISTPOS = IPC_GETLISTPOS;
|
||||
const int WA_GETTITLE = IPC_GETPLAYLISTTITLE;
|
||||
|
||||
const int WA_VERSION = IPC_GETVERSION;
|
||||
const int WA_FILENAMEINLIST = IPC_GETPLAYLISTFILE;
|
||||
const int WA_GETFILEINFO = IPC_GET_EXTENDED_FILE_INFO;
|
||||
|
||||
HWND hwnd_winamp = NULL;
|
||||
INT position = 0;
|
||||
STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;
|
||||
char messageReturn[255];
|
||||
wchar_t* wMessageReturn;
|
||||
|
||||
LPDWORD temp;
|
||||
|
||||
void initWinampHandle() {
|
||||
hwnd_winamp = NULL;
|
||||
if (hwnd_winamp == NULL) {
|
||||
hwnd_winamp = FindWindow("Winamp v1.x", NULL);
|
||||
}
|
||||
if (hwnd_winamp == NULL) {
|
||||
hwnd_winamp = FindWindow("Winamp v2.x", NULL);
|
||||
}
|
||||
if (hwnd_winamp == NULL) {
|
||||
hwnd_winamp = FindWindow("Winamp v3.x", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
jboolean runWinamp(unsigned char* pathWinamp) {
|
||||
|
||||
/* STARTUPINFO si;
|
||||
PROCESS_INFORMATION pi;*/
|
||||
|
||||
ZeroMemory( &si, sizeof(si) );
|
||||
si.cb = sizeof(si);
|
||||
ZeroMemory( &pi, sizeof(pi) );
|
||||
|
||||
|
||||
// Start the child process.
|
||||
if(!CreateProcess(pathWinamp,
|
||||
NULL,
|
||||
0,
|
||||
0,
|
||||
FALSE,
|
||||
CREATE_NEW_CONSOLE,
|
||||
0,
|
||||
0,
|
||||
&si,
|
||||
&pi))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
DWORD dwResult = WaitForInputIdle(pi.hProcess,INFINITE);
|
||||
if (dwResult != 0) return FALSE;
|
||||
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
||||
}
|
||||
|
||||
int getListPos() {
|
||||
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
|
||||
return SendMessage(hwnd_winamp,WM_USER,WA_NOTHING,WA_GETLISTPOS);
|
||||
|
||||
}
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
void getPluginMessage(int param, int sendMessage)
|
||||
{
|
||||
|
||||
LPCVOID message = (LPCVOID)SendMessageW(hwnd_winamp, WM_USER, param, sendMessage);
|
||||
ZeroMemory( &pi, sizeof(pi));
|
||||
GetWindowThreadProcessId(hwnd_winamp, &pi.dwThreadId);
|
||||
pi.hProcess = OpenProcess(PROCESS_ALL_ACCESS,FALSE,pi.dwThreadId);
|
||||
ReadProcessMemory(pi.hProcess, message, messageReturn,2056,temp);
|
||||
free(temp);
|
||||
CloseHandle(pi.hProcess);
|
||||
CloseHandle(pi.hThread);
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_run
|
||||
(JNIEnv *env, jobject obj) {
|
||||
|
||||
initWinampHandle();
|
||||
|
||||
if ( hwnd_winamp == NULL ) {
|
||||
|
||||
unsigned char path[MAX_PATH]="";
|
||||
DWORD size = MAX_PATH;
|
||||
|
||||
HKEY key;
|
||||
DWORD tipo;
|
||||
|
||||
if (!RegOpenKey(HKEY_LOCAL_MACHINE,"Software\\Clients\\Media\\Winamp\\shell\\open\\command",&key)==ERROR_SUCCESS)
|
||||
{
|
||||
|
||||
printf("0");
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
if (!(RegQueryValueEx(key,"",NULL,&tipo,path,&size))==ERROR_SUCCESS)
|
||||
{
|
||||
|
||||
RegCloseKey(key);
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
if (!runWinamp(path))
|
||||
{
|
||||
|
||||
RegCloseKey(key);
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
int version = SendMessage(hwnd_winamp,WM_WA_IPC,0,IPC_GETVERSION);
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_exit
|
||||
(JNIEnv *env, jobject obj) {
|
||||
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_CLOSE, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_play
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_PLAY, WA_NOTHING);
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_stop
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_STOP, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_resume
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_PAUSE, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_pause
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_PAUSE, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_previousTrack
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_PREVTRACK, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_nextTrack
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_NEXTTRACK, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_fwd5Secs
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_FWD5SECS, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_rew5Secs
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_REW5SECS, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_increaseVolume
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_VOLUMEUP, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_decreaseVolume
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_VOLUMEDOWN, WA_NOTHING);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_increaseVolumePercent
|
||||
(JNIEnv *env, jobject obj, jint percent) {
|
||||
initWinampHandle();
|
||||
int i = 0;
|
||||
if (hwnd_winamp != NULL) {
|
||||
for(i=0;i<percent;i++) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_VOLUMEUP, WA_NOTHING);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_decreaseVolumePercent
|
||||
(JNIEnv *env, jobject obj, jint percent) {
|
||||
initWinampHandle();
|
||||
int i = 0;
|
||||
if (hwnd_winamp != NULL) {
|
||||
for(i=0;i<percent;i++) {
|
||||
SendMessageA(hwnd_winamp, WM_COMMAND, WA_VOLUMEDOWN, WA_NOTHING);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setVolume
|
||||
(JNIEnv *env, jobject obj, jint pos) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_USER, pos, WA_SETVOLUME);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getVolume
|
||||
(JNIEnv *env, jobject obj, jint pos) {
|
||||
jint curVolume = -1;
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
curVolume = (jint)SendMessageA(hwnd_winamp, WM_USER, -666, WA_SETVOLUME);
|
||||
}
|
||||
|
||||
return curVolume;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_restart
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_RESTART);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setPlaylistPosition
|
||||
(JNIEnv *env, jobject obj, jint pos) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_USER, pos, WA_SETPLAYLISTPOS);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_clearPlayList
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_CLEARPLAYLIST);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_refreshPlayListCache
|
||||
(JNIEnv *env, jobject obj) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_REFRESHPLCACHE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getPlayListLength
|
||||
(JNIEnv *env, jobject obj) {
|
||||
jint length = -1;
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
length = (jint)SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_PLAYLISTLEN);
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_writePlayListToFile
|
||||
(JNIEnv *env, jobject obj) {
|
||||
jint length = -1;
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
length = SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_WRITEPLAYLIST);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_isShuffleStatusOn
|
||||
(JNIEnv *env, jobject obj) {
|
||||
jint status = 0;
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
status = (jint)SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_GETSHUFFLESTATUS);
|
||||
} else
|
||||
return -1;
|
||||
|
||||
return status>0?1:0;
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_isRepeatStatusOn
|
||||
(JNIEnv *env, jobject obj) {
|
||||
jint status = 0;
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
status = (jint)SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_GETREPEATSTATUS);
|
||||
} else
|
||||
return -1;
|
||||
|
||||
return status>0?1:0;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setRepeatStatusOn
|
||||
(JNIEnv *env, jobject obj, jboolean status) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_USER, status, WA_SETREPEATSTATUS);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setShuffleStatusOn
|
||||
(JNIEnv *env, jobject obj, jboolean status) {
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
SendMessageA(hwnd_winamp, WM_USER, status, WA_SETSHUFFLESTATUS);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_appendToPlayList
|
||||
(JNIEnv *env, jobject obj, jstring mp3filename) {
|
||||
initWinampHandle();
|
||||
jboolean iscopy;
|
||||
if (hwnd_winamp != NULL) {
|
||||
wMessageReturn = (wchar_t*)(*env)->GetStringChars(env, mp3filename, &iscopy);
|
||||
int length = wcslen(wMessageReturn);
|
||||
COPYDATASTRUCT cds;
|
||||
cds.dwData = IPC_PLAYFILEW;
|
||||
cds.lpData = (void*)wMessageReturn;
|
||||
cds.cbData = length * 2 + 2 ; // it sums white space
|
||||
|
||||
SendMessageW(hwnd_winamp, WM_COPYDATA, WA_NOTHING, (LPARAM)&cds);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getStatus
|
||||
(JNIEnv *env, jobject obj) {
|
||||
jint status = -1;
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
status = SendMessageA(hwnd_winamp, WM_USER, WA_NOTHING, WA_GETSTATUS);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getListPos
|
||||
(JNIEnv *env, jobject obj) {
|
||||
|
||||
return getListPos();
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getTitle
|
||||
(JNIEnv *env, jobject obj) {
|
||||
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
|
||||
char title[500] = "";
|
||||
GetWindowText(hwnd_winamp,title,500);
|
||||
return (*env)->NewStringUTF(env,title);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getTime
|
||||
(JNIEnv *env, jobject obj, jint mode) {
|
||||
|
||||
initWinampHandle();
|
||||
if (hwnd_winamp != NULL) {
|
||||
|
||||
return SendMessage(hwnd_winamp,WM_USER,mode,IPC_GETOUTPUTTIME);
|
||||
|
||||
}
|
||||
|
||||
return -2;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getFileNameInList
|
||||
(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
|
||||
initWinampHandle();
|
||||
|
||||
if (hwnd_winamp != NULL) {
|
||||
|
||||
getPluginMessage(index, WA_FILENAMEINLIST);
|
||||
char* filePath = messageReturn;
|
||||
jstring strReturn = (*env)->NewStringUTF(env,filePath);
|
||||
return strReturn;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
JNIEXPORT jstring JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getFileNamePlaying
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
|
||||
initWinampHandle();
|
||||
|
||||
if (hwnd_winamp != NULL) {
|
||||
|
||||
getPluginMessage(WA_NOTHING, IPC_GET_PLAYING_FILENAME);
|
||||
wchar_t* fileName = (wchar_t*)messageReturn;
|
||||
int length = wcslen(fileName);
|
||||
jstring strReturn = (*env)->NewString(env,fileName,length);
|
||||
return strReturn;
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
285
cpp/JavaWinampApi/WinampController.h
Normal file
285
cpp/JavaWinampApi/WinampController.h
Normal file
@@ -0,0 +1,285 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class WinampController */
|
||||
|
||||
|
||||
#ifndef _Included_WinampController
|
||||
#define _Included_WinampController
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void initWinampHandle();
|
||||
|
||||
jboolean runWinamp(unsigned char* pathWinamp);
|
||||
|
||||
int getListPos();
|
||||
|
||||
void getPluginMessage(int param, int sendMessage);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: run
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_run
|
||||
(JNIEnv *, jclass);
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: exit
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_exit
|
||||
(JNIEnv *, jclass);
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: play
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_play
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: stop
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_stop
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: resume
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_resume
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: pause
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_pause
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: previousTrack
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_previousTrack
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: nextTrack
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_nextTrack
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: fwd5Secs
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_fwd5Secs
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: fwd5Secs
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_rew5Secs
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: increaseVolume
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_increaseVolume
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: decreaseVolume
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_decreaseVolume
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: increaseVolumePercent
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_increaseVolumePercent
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: decreaseVolumePercent
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_decreaseVolumePercent
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: setVolume
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setVolume
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: setVolume
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getVolume
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: restart
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_restart
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: setPlaylistPosition
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setPlaylistPosition
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: clearPlayList
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_clearPlayList
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: refreshPlayListCache
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_refreshPlayListCache
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: getPlayListLength
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getPlayListLength
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: writePlayListToFile
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_writePlayListToFile
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: isShuffleStatusOn
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_isShuffleStatusOn
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: isRepeatStatusOn
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_isRepeatStatusOn
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: setRepeatStatusOn
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setRepeatStatusOn
|
||||
(JNIEnv *, jclass, jboolean);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: setShuffleStatusOn
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_setShuffleStatusOn
|
||||
(JNIEnv *, jclass, jboolean);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: appendToPlayList
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_qotsa_jni_controller_JNIWinamp_appendToPlayList
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: getStatus
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getStatus
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: getListPos
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getListPos
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: getTitle
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getTitle
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: getTime
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getTime
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: getFileNameInList
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getFileNameInList
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: WinampController
|
||||
* Method: getFileNamePlaying
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_qotsa_jni_controller_JNIWinamp_getFileNamePlaying
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
1
cpp/JavaWinampApi/cpy.bat
Normal file
1
cpp/JavaWinampApi/cpy.bat
Normal file
@@ -0,0 +1 @@
|
||||
copy /y wpcom.dll c:\winnt\system32\
|
||||
58
cpp/JavaWinampApi/libwpcom.def
Normal file
58
cpp/JavaWinampApi/libwpcom.def
Normal file
@@ -0,0 +1,58 @@
|
||||
; dlltool --base-file C:\DOCUME~1\FRANCI~1\CONFIG~1\Temp/cca03628.base --output-exp wpcom.exp --dllname wpcom.dll --output-def libwpcom.def --no-export-all-symbols --add-stdcall-alias --exclude-symbol=DllMainCRTStartup@12 --def C:\DOCUME~1\FRANCI~1\CONFIG~1\Temp/cca03628.def --output-lib libwpcom.a
|
||||
EXPORTS
|
||||
Java_controller_JNIWinampController_appendToPlayList = Java_controller_JNIWinampController_appendToPlayList@12 @ 1
|
||||
Java_controller_JNIWinampController_appendToPlayList@12 @ 2
|
||||
Java_controller_JNIWinampController_clearPlayList = Java_controller_JNIWinampController_clearPlayList@8 @ 3
|
||||
Java_controller_JNIWinampController_clearPlayList@8 @ 4
|
||||
Java_controller_JNIWinampController_clearPlayListCache = Java_controller_JNIWinampController_clearPlayListCache@8 @ 5
|
||||
Java_controller_JNIWinampController_clearPlayListCache@8 @ 6
|
||||
Java_controller_JNIWinampController_decreaseVolume = Java_controller_JNIWinampController_decreaseVolume@8 @ 7
|
||||
Java_controller_JNIWinampController_decreaseVolume@8 @ 8
|
||||
Java_controller_JNIWinampController_decreaseVolumePercent = Java_controller_JNIWinampController_decreaseVolumePercent@12 @ 9
|
||||
Java_controller_JNIWinampController_decreaseVolumePercent@12 @ 10
|
||||
Java_controller_JNIWinampController_exit = Java_controller_JNIWinampController_exit@8 @ 11
|
||||
Java_controller_JNIWinampController_exit@8 @ 12
|
||||
Java_controller_JNIWinampController_getListPos = Java_controller_JNIWinampController_getListPos@8 @ 13
|
||||
Java_controller_JNIWinampController_getListPos@8 @ 14
|
||||
Java_controller_JNIWinampController_getPlayListLength = Java_controller_JNIWinampController_getPlayListLength@8 @ 15
|
||||
Java_controller_JNIWinampController_getPlayListLength@8 @ 16
|
||||
Java_controller_JNIWinampController_getSeconds = Java_controller_JNIWinampController_getSeconds@8 @ 17
|
||||
Java_controller_JNIWinampController_getSeconds@8 @ 18
|
||||
Java_controller_JNIWinampController_getStatus = Java_controller_JNIWinampController_getStatus@8 @ 19
|
||||
Java_controller_JNIWinampController_getStatus@8 @ 20
|
||||
Java_controller_JNIWinampController_getTitle = Java_controller_JNIWinampController_getTitle@8 @ 21
|
||||
Java_controller_JNIWinampController_getTitle@8 @ 22
|
||||
Java_controller_JNIWinampController_increaseVolume = Java_controller_JNIWinampController_increaseVolume@8 @ 23
|
||||
Java_controller_JNIWinampController_increaseVolume@8 @ 24
|
||||
Java_controller_JNIWinampController_increaseVolumePercent = Java_controller_JNIWinampController_increaseVolumePercent@12 @ 25
|
||||
Java_controller_JNIWinampController_increaseVolumePercent@12 @ 26
|
||||
Java_controller_JNIWinampController_isRepeatStatusOn = Java_controller_JNIWinampController_isRepeatStatusOn@8 @ 27
|
||||
Java_controller_JNIWinampController_isRepeatStatusOn@8 @ 28
|
||||
Java_controller_JNIWinampController_isShuffleStatusOn = Java_controller_JNIWinampController_isShuffleStatusOn@8 @ 29
|
||||
Java_controller_JNIWinampController_isShuffleStatusOn@8 @ 30
|
||||
Java_controller_JNIWinampController_nextTrack = Java_controller_JNIWinampController_nextTrack@8 @ 31
|
||||
Java_controller_JNIWinampController_nextTrack@8 @ 32
|
||||
Java_controller_JNIWinampController_pause = Java_controller_JNIWinampController_pause@8 @ 33
|
||||
Java_controller_JNIWinampController_pause@8 @ 34
|
||||
Java_controller_JNIWinampController_play = Java_controller_JNIWinampController_play@8 @ 35
|
||||
Java_controller_JNIWinampController_play@8 @ 36
|
||||
Java_controller_JNIWinampController_previousTrack = Java_controller_JNIWinampController_previousTrack@8 @ 37
|
||||
Java_controller_JNIWinampController_previousTrack@8 @ 38
|
||||
Java_controller_JNIWinampController_restart = Java_controller_JNIWinampController_restart@8 @ 39
|
||||
Java_controller_JNIWinampController_restart@8 @ 40
|
||||
Java_controller_JNIWinampController_resume = Java_controller_JNIWinampController_resume@8 @ 41
|
||||
Java_controller_JNIWinampController_resume@8 @ 42
|
||||
Java_controller_JNIWinampController_run = Java_controller_JNIWinampController_run@8 @ 43
|
||||
Java_controller_JNIWinampController_run@8 @ 44
|
||||
Java_controller_JNIWinampController_setPlaylistPosition = Java_controller_JNIWinampController_setPlaylistPosition@12 @ 45
|
||||
Java_controller_JNIWinampController_setPlaylistPosition@12 @ 46
|
||||
Java_controller_JNIWinampController_setRepeatStatusOn = Java_controller_JNIWinampController_setRepeatStatusOn@12 @ 47
|
||||
Java_controller_JNIWinampController_setRepeatStatusOn@12 @ 48
|
||||
Java_controller_JNIWinampController_setShuffleStatusOn = Java_controller_JNIWinampController_setShuffleStatusOn@12 @ 49
|
||||
Java_controller_JNIWinampController_setShuffleStatusOn@12 @ 50
|
||||
Java_controller_JNIWinampController_setVolume = Java_controller_JNIWinampController_setVolume@12 @ 51
|
||||
Java_controller_JNIWinampController_setVolume@12 @ 52
|
||||
Java_controller_JNIWinampController_stop = Java_controller_JNIWinampController_stop@8 @ 53
|
||||
Java_controller_JNIWinampController_stop@8 @ 54
|
||||
Java_controller_JNIWinampController_writePlayListToFile = Java_controller_JNIWinampController_writePlayListToFile@8 @ 55
|
||||
Java_controller_JNIWinampController_writePlayListToFile@8 @ 56
|
||||
1620
cpp/JavaWinampApi/wa_ipc.h
Normal file
1620
cpp/JavaWinampApi/wa_ipc.h
Normal file
File diff suppressed because it is too large
Load Diff
69
cpp/JavaWinampApi/wpcom.dev
Normal file
69
cpp/JavaWinampApi/wpcom.dev
Normal file
@@ -0,0 +1,69 @@
|
||||
[Project]
|
||||
FileName=wpcom.dev
|
||||
Name=wpcom
|
||||
UnitCount=2
|
||||
Type=3
|
||||
Ver=1
|
||||
ObjFiles=
|
||||
Includes="E:\Program Files\Java\jdk1.6.0_11\include";"E:\Program Files\Java\jdk1.6.0_11\include\win32"
|
||||
Libs=
|
||||
PrivateResource=
|
||||
ResourceIncludes=
|
||||
MakeIncludes=
|
||||
Compiler=-DBUILDING_DLL=1_@@_
|
||||
CppCompiler=-DBUILDING_DLL=1_@@_
|
||||
Linker=--no-export-all-symbols --add-stdcall-alias_@@_
|
||||
IsCpp=0
|
||||
Icon=
|
||||
ExeOutput=..\..\..\JavaWinampAPI
|
||||
ObjectOutput=
|
||||
OverrideOutput=1
|
||||
OverrideOutputName=wpcom.dll
|
||||
HostApplication=
|
||||
Folders=
|
||||
CommandLine=
|
||||
UseCustomMakefile=0
|
||||
CustomMakefile=
|
||||
IncludeVersionInfo=0
|
||||
SupportXPThemes=0
|
||||
CompilerSet=0
|
||||
CompilerSettings=0000000000000000000000
|
||||
|
||||
[Unit1]
|
||||
FileName=WinampController.c
|
||||
CompileCpp=0
|
||||
Folder=wacon
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=$(CC) -c WinampController.c -o WinampController.o $(CFLAGS)
|
||||
|
||||
[VersionInfo]
|
||||
Major=0
|
||||
Minor=1
|
||||
Release=1
|
||||
Build=1
|
||||
LanguageID=1033
|
||||
CharsetID=1252
|
||||
CompanyName=
|
||||
FileVersion=
|
||||
FileDescription=Developed using the Dev-C++ IDE
|
||||
InternalName=
|
||||
LegalCopyright=
|
||||
LegalTrademarks=
|
||||
OriginalFilename=
|
||||
ProductName=
|
||||
ProductVersion=
|
||||
AutoIncBuildNr=0
|
||||
|
||||
[Unit2]
|
||||
FileName=WinampController.h
|
||||
CompileCpp=0
|
||||
Folder=wacon
|
||||
Compile=1
|
||||
Link=1
|
||||
Priority=1000
|
||||
OverrideBuildCmd=0
|
||||
BuildCmd=
|
||||
|
||||
17
cpp/JavaWinampApi/wpcom.layout
Normal file
17
cpp/JavaWinampApi/wpcom.layout
Normal file
@@ -0,0 +1,17 @@
|
||||
[Editor_0]
|
||||
CursorCol=32
|
||||
CursorRow=359
|
||||
TopLine=338
|
||||
LeftChar=1
|
||||
Open=1
|
||||
Top=1
|
||||
[Editors]
|
||||
Focused=0
|
||||
Order=1,0
|
||||
[Editor_1]
|
||||
Open=1
|
||||
Top=0
|
||||
CursorCol=73
|
||||
CursorRow=143
|
||||
TopLine=127
|
||||
LeftChar=1
|
||||
47
cpp/jacob/ComThread.cpp
Normal file
47
cpp/jacob/ComThread.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include <objbase.h>
|
||||
#include "ComThread.h"
|
||||
// Win32 support for Ole Automation
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <atlbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
#include "util.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_ComThread_doCoInitialize
|
||||
(JNIEnv *env, jclass cls, jint mode)
|
||||
{
|
||||
int threadModel = mode;
|
||||
CoInitializeEx(NULL, threadModel);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_ComThread_doCoUninitialize
|
||||
(JNIEnv *env, jclass cls)
|
||||
{
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
}
|
||||
48
cpp/jacob/ComThread.h
Normal file
48
cpp/jacob/ComThread.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
/* Header for class com_jacob_com_ComThread */
|
||||
|
||||
#ifndef _Included_com_jacob_com_ComThread
|
||||
#define _Included_com_jacob_com_ComThread
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_jacob_com_ComThread
|
||||
* Method: doCoInitialize
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_ComThread_doCoInitialize
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_ComThread
|
||||
* Method: doCoUninitialize
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_ComThread_doCoUninitialize
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
582
cpp/jacob/Dispatch.cpp
Normal file
582
cpp/jacob/Dispatch.cpp
Normal file
@@ -0,0 +1,582 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include <objbase.h>
|
||||
#include "Dispatch.h"
|
||||
// Win32 support for Ole Automation
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <atlbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
#include "util.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#define DISP_FLD "m_pDispatch"
|
||||
|
||||
// extract a IDispatch from a jobject
|
||||
IDispatch *extractDispatch(JNIEnv *env, jobject arg)
|
||||
{
|
||||
jclass argClass = env->GetObjectClass(arg);
|
||||
jfieldID ajf = env->GetFieldID( argClass, DISP_FLD, "I");
|
||||
jint anum = env->GetIntField(arg, ajf);
|
||||
IDispatch *v = (IDispatch *)anum;
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method finds an interface rooted on the passed in dispatch object.
|
||||
* This creates a new Dispatch object so it is NOT reliable
|
||||
* in the event callback thread of a JWS client where the root class loader
|
||||
* does not have com.jacob.com.Dispatch in its classpath
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_QueryInterface
|
||||
(JNIEnv *env, jobject _this, jstring _iid)
|
||||
{
|
||||
// get the current IDispatch
|
||||
IDispatch *pIDispatch = extractDispatch(env, _this);
|
||||
if (!pIDispatch) return NULL;
|
||||
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||
const char *siid = env->GetStringUTFChars(_iid, NULL);
|
||||
USES_CONVERSION;
|
||||
LPOLESTR bsIID = A2W(siid);
|
||||
env->ReleaseStringUTFChars(_iid, siid);
|
||||
IID iid;
|
||||
HRESULT hr = IIDFromString(bsIID, &iid);
|
||||
if (FAILED(hr)) {
|
||||
ThrowComFail(env, "Can't get IID from String", hr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// try to call QI on the passed IID
|
||||
IDispatch *disp;
|
||||
hr = pIDispatch->QueryInterface(iid, (void **)&disp);
|
||||
if (FAILED(hr)) {
|
||||
ThrowComFail(env, "QI on IID from String Failed", hr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
jclass autoClass = env->FindClass("com/jacob/com/Dispatch");
|
||||
jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(I)V");
|
||||
// construct a Dispatch object to return
|
||||
// I am copying the pointer to java
|
||||
// jacob-msg 1817 - SF 1053871 : QueryInterface already called AddRef!!
|
||||
//if (disp) disp->AddRef();
|
||||
jobject newAuto = env->NewObject(autoClass, autoCons, disp);
|
||||
return newAuto;
|
||||
}
|
||||
|
||||
/**
|
||||
* starts up a new instance of the requested program (progId)
|
||||
* and connects to it. does special code if the progid
|
||||
* is of the alternate format (with ":")
|
||||
**/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstanceNative
|
||||
(JNIEnv *env, jobject _this, jstring _progid)
|
||||
{
|
||||
jclass clazz = env->GetObjectClass(_this);
|
||||
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
||||
|
||||
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||
CLSID clsid;
|
||||
HRESULT hr;
|
||||
IUnknown *punk = NULL;
|
||||
IDispatch *pIDispatch;
|
||||
USES_CONVERSION;
|
||||
LPOLESTR bsProgId = A2W(progid);
|
||||
if (strchr(progid,':'))
|
||||
{
|
||||
env->ReleaseStringUTFChars(_progid, progid);
|
||||
// it's a moniker
|
||||
hr = CoGetObject(bsProgId, NULL, IID_IUnknown, (LPVOID *)&punk);
|
||||
if (FAILED(hr)) {
|
||||
ThrowComFail(env, "Can't find moniker", hr);
|
||||
return;
|
||||
}
|
||||
IClassFactory *pIClass;
|
||||
// if it was a clsid moniker, I may have a class factory
|
||||
hr = punk->QueryInterface(IID_IClassFactory, (void **)&pIClass);
|
||||
if (!SUCCEEDED(hr)) goto doDisp;
|
||||
punk->Release();
|
||||
// try to create an instance
|
||||
hr = pIClass->CreateInstance(NULL, IID_IUnknown, (void **)&punk);
|
||||
if (FAILED(hr)) {
|
||||
ThrowComFail(env, "Can't create moniker class instance", hr);
|
||||
return;
|
||||
}
|
||||
pIClass->Release();
|
||||
goto doDisp;
|
||||
}
|
||||
env->ReleaseStringUTFChars(_progid, progid);
|
||||
// Now, try to find an IDispatch interface for progid
|
||||
hr = CLSIDFromProgID(bsProgId, &clsid);
|
||||
if (FAILED(hr)) {
|
||||
ThrowComFail(env, "Can't get object clsid from progid", hr);
|
||||
return;
|
||||
}
|
||||
// standard creation
|
||||
hr = CoCreateInstance(clsid,NULL,CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER,IID_IUnknown, (void **)&punk);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
ThrowComFail(env, "Can't co-create object", hr);
|
||||
return;
|
||||
}
|
||||
doDisp:
|
||||
|
||||
// now get an IDispatch pointer from the IUnknown
|
||||
hr = punk->QueryInterface(IID_IDispatch, (void **)&pIDispatch);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
ThrowComFail(env, "Can't QI object for IDispatch", hr);
|
||||
return;
|
||||
}
|
||||
// CoCreateInstance called AddRef
|
||||
punk->Release();
|
||||
env->SetIntField(_this, jf, (unsigned int)pIDispatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* attempts to connect to an running instance of the requested program
|
||||
* This exists solely for the factory method connectToActiveInstance.
|
||||
**/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstanceNative
|
||||
(JNIEnv *env, jobject _this, jstring _progid)
|
||||
{
|
||||
jclass clazz = env->GetObjectClass(_this);
|
||||
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
||||
|
||||
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||
CLSID clsid;
|
||||
HRESULT hr;
|
||||
IUnknown *punk = NULL;
|
||||
IDispatch *pIDispatch;
|
||||
USES_CONVERSION;
|
||||
LPOLESTR bsProgId = A2W(progid);
|
||||
env->ReleaseStringUTFChars(_progid, progid);
|
||||
// Now, try to find an IDispatch interface for progid
|
||||
hr = CLSIDFromProgID(bsProgId, &clsid);
|
||||
if (FAILED(hr)) {
|
||||
ThrowComFail(env, "Can't get object clsid from progid", hr);
|
||||
return;
|
||||
}
|
||||
// standard connection
|
||||
//printf("trying to connect to running %ls\n",bsProgId);
|
||||
hr = GetActiveObject(clsid,NULL, &punk);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
ThrowComFail(env, "Can't get active object", hr);
|
||||
return;
|
||||
}
|
||||
// now get an IDispatch pointer from the IUnknown
|
||||
hr = punk->QueryInterface(IID_IDispatch, (void **)&pIDispatch);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
ThrowComFail(env, "Can't QI object for IDispatch", hr);
|
||||
return;
|
||||
}
|
||||
// GetActiveObject called AddRef
|
||||
punk->Release();
|
||||
env->SetIntField(_this, jf, (unsigned int)pIDispatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* starts up a new instance of the requested program (progId).
|
||||
* This exists solely for the factory method connectToActiveInstance.
|
||||
**/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_coCreateInstanceNative
|
||||
(JNIEnv *env, jobject _this, jstring _progid)
|
||||
{
|
||||
jclass clazz = env->GetObjectClass(_this);
|
||||
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
||||
|
||||
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||
CLSID clsid;
|
||||
HRESULT hr;
|
||||
IUnknown *punk = NULL;
|
||||
IDispatch *pIDispatch;
|
||||
USES_CONVERSION;
|
||||
LPOLESTR bsProgId = A2W(progid);
|
||||
env->ReleaseStringUTFChars(_progid, progid);
|
||||
// Now, try to find an IDispatch interface for progid
|
||||
hr = CLSIDFromProgID(bsProgId, &clsid);
|
||||
if (FAILED(hr)) {
|
||||
ThrowComFail(env, "Can't get object clsid from progid", hr);
|
||||
return;
|
||||
}
|
||||
// standard creation
|
||||
hr = CoCreateInstance(clsid,NULL,CLSCTX_LOCAL_SERVER|CLSCTX_INPROC_SERVER,IID_IUnknown, (void **)&punk);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
ThrowComFail(env, "Can't co-create object", hr);
|
||||
return;
|
||||
}
|
||||
// now get an IDispatch pointer from the IUnknown
|
||||
hr = punk->QueryInterface(IID_IDispatch, (void **)&pIDispatch);
|
||||
if (!SUCCEEDED(hr)) {
|
||||
ThrowComFail(env, "Can't QI object for IDispatch", hr);
|
||||
return;
|
||||
}
|
||||
// CoCreateInstance called AddRef
|
||||
punk->Release();
|
||||
env->SetIntField(_this, jf, (unsigned int)pIDispatch);
|
||||
}
|
||||
|
||||
/**
|
||||
* release method
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_release
|
||||
(JNIEnv *env, jobject _this)
|
||||
{
|
||||
jclass clazz = env->GetObjectClass(_this);
|
||||
jfieldID jf = env->GetFieldID( clazz, DISP_FLD, "I");
|
||||
jint num = env->GetIntField(_this, jf);
|
||||
|
||||
IDispatch *disp = (IDispatch *)num;
|
||||
if (disp) {
|
||||
disp->Release();
|
||||
env->SetIntField(_this, jf, (unsigned int)0);
|
||||
}
|
||||
}
|
||||
|
||||
static HRESULT
|
||||
name2ID(IDispatch *pIDispatch, const char *prop, DISPID *dispid, long lcid)
|
||||
{
|
||||
HRESULT hresult;
|
||||
USES_CONVERSION;
|
||||
LPOLESTR propOle = A2W(prop);
|
||||
hresult = pIDispatch->GetIDsOfNames(IID_NULL,(LPOLESTR*)&propOle,1,lcid,dispid);
|
||||
return hresult;
|
||||
}
|
||||
|
||||
JNIEXPORT jintArray JNICALL Java_com_jacob_com_Dispatch_getIDsOfNames
|
||||
(JNIEnv *env, jclass clazz, jobject disp, jint lcid, jobjectArray names)
|
||||
{
|
||||
IDispatch *pIDispatch = extractDispatch(env, disp);
|
||||
if (!pIDispatch) return NULL;
|
||||
|
||||
int l = env->GetArrayLength(names);
|
||||
int i;
|
||||
LPOLESTR *lps = (LPOLESTR *)CoTaskMemAlloc(l * sizeof(LPOLESTR));
|
||||
DISPID *dispid = (DISPID *)CoTaskMemAlloc(l * sizeof(DISPID));
|
||||
for(i=0;i<l;i++)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
jstring s = (jstring)env->GetObjectArrayElement(names, i);
|
||||
// if we used env->GetStringChars() would that let us drop the conversion?
|
||||
const char *nm = env->GetStringUTFChars(s, NULL);
|
||||
LPOLESTR nmos = A2W(nm);
|
||||
env->ReleaseStringUTFChars(s, nm);
|
||||
lps[i] = nmos;
|
||||
env->DeleteLocalRef(s);
|
||||
}
|
||||
HRESULT hr = pIDispatch->GetIDsOfNames(IID_NULL,lps,l,lcid,dispid);
|
||||
if (FAILED(hr)) {
|
||||
CoTaskMemFree(lps);
|
||||
CoTaskMemFree(dispid);
|
||||
char buf[1024];
|
||||
strcpy_s(buf, "Can't map names to dispid:");
|
||||
for(i=0;i<l;i++)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
jstring s = (jstring)env->GetObjectArrayElement(names, i);
|
||||
const char *nm = env->GetStringUTFChars(s, NULL);
|
||||
strcat_s(buf, nm);
|
||||
env->ReleaseStringUTFChars(s, nm);
|
||||
env->DeleteLocalRef(s);
|
||||
}
|
||||
ThrowComFail(env, buf, hr);
|
||||
return NULL;
|
||||
}
|
||||
jintArray iarr = env->NewIntArray(l);
|
||||
// SF 1511033 -- the 2nd parameter should be 0 and not i!
|
||||
env->SetIntArrayRegion(iarr, 0, l, dispid);
|
||||
CoTaskMemFree(lps);
|
||||
CoTaskMemFree(dispid);
|
||||
return iarr;
|
||||
}
|
||||
|
||||
static char* BasicToCharString(const BSTR inBasicString)
|
||||
{
|
||||
char* charString = NULL;
|
||||
const size_t charStrSize = ::SysStringLen(inBasicString) + 1;
|
||||
if (charStrSize > 1)
|
||||
{
|
||||
charString = new char[charStrSize];
|
||||
size_t convertedSize;
|
||||
::wcstombs_s(&convertedSize, charString, charStrSize, inBasicString, charStrSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
charString = ::_strdup("");
|
||||
}
|
||||
return charString;
|
||||
}
|
||||
|
||||
static wchar_t* CreateErrorMsgFromResult(HRESULT inResult)
|
||||
{
|
||||
wchar_t* msg = NULL;
|
||||
::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM, NULL, inResult,MAKELANGID(LANG_NEUTRAL,
|
||||
SUBLANG_DEFAULT), (LPWSTR) &msg, 0, NULL);
|
||||
if (msg == NULL)
|
||||
{
|
||||
const wchar_t* message_text = L"An unknown COM error has occured.";
|
||||
size_t bufferLength = (wcslen(message_text) + 1) * sizeof(wchar_t);
|
||||
msg = (wchar_t*) ::LocalAlloc(LPTR, bufferLength);
|
||||
wcscpy_s(msg, bufferLength, message_text);
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
static wchar_t* CreateErrorMsgFromInfo(HRESULT inResult, EXCEPINFO* ioInfo,
|
||||
const char* methName)
|
||||
{
|
||||
wchar_t* msg = NULL;
|
||||
size_t methNameWSize = 0;
|
||||
|
||||
mbstowcs_s(&methNameWSize, NULL, 0, methName, _TRUNCATE);
|
||||
|
||||
wchar_t* methNameW = new wchar_t[methNameWSize];
|
||||
|
||||
mbstowcs_s(NULL, methNameW, methNameWSize, methName, _TRUNCATE);
|
||||
|
||||
// If this is a dispatch exception (triggered by an Invoke message),
|
||||
// then we have to take some additional steps to process the error
|
||||
// message.
|
||||
if (inResult == DISP_E_EXCEPTION)
|
||||
{
|
||||
// Check to see if the server deferred filling in the exception
|
||||
// information. If so, make the call to populate the structure.
|
||||
if (ioInfo->pfnDeferredFillIn != NULL)
|
||||
(*(ioInfo->pfnDeferredFillIn))(ioInfo);
|
||||
|
||||
// Build the error message from exception information content.
|
||||
int sourceLen = SysStringLen(ioInfo->bstrSource);
|
||||
int descLen = SysStringLen(ioInfo->bstrDescription);
|
||||
const size_t MSG_LEN = ::wcslen(methNameW) + sourceLen + descLen + 128;
|
||||
msg = new wchar_t[MSG_LEN];
|
||||
::wcsncpy_s(msg, MSG_LEN, L"Invoke of: ", wcslen(L"Invoke of: "));
|
||||
::wcsncat_s(msg, MSG_LEN, methNameW, wcslen(methNameW));
|
||||
::wcsncat_s(msg, MSG_LEN, L"\nSource: ", wcslen(L"\nSource: "));
|
||||
::wcsncat_s(msg, MSG_LEN, ioInfo->bstrSource, sourceLen);
|
||||
::wcsncat_s(msg, MSG_LEN, L"\nDescription: ", wcslen(L"\nDescription: "));
|
||||
::wcsncat_s(msg, MSG_LEN, ioInfo->bstrDescription, descLen);
|
||||
::wcsncat_s(msg, MSG_LEN, L"\n", wcslen(L"\n"));
|
||||
}
|
||||
else
|
||||
{
|
||||
wchar_t* msg2 = CreateErrorMsgFromResult(inResult);
|
||||
const size_t MSG_LEN = ::wcslen(methNameW) + ::wcslen(msg2) + 256;
|
||||
msg = new wchar_t[MSG_LEN];
|
||||
::wcsncpy_s(msg, MSG_LEN,
|
||||
L"A COM exception has been encountered:\nAt Invoke of: ",
|
||||
wcslen(L"A COM exception has been encountered:\nAt Invoke of: "));
|
||||
::wcsncat_s(msg, MSG_LEN, methNameW, wcslen(methNameW));
|
||||
::wcsncat_s(msg, MSG_LEN, L"\nDescription: ", wcslen(L"\nDescription: "));
|
||||
::wcsncat_s(msg, MSG_LEN, msg2, wcslen(msg2));
|
||||
// jacob-msg 1075 - SF 1053872 : Documentation says "use LocalFree"!!
|
||||
//delete msg2;
|
||||
LocalFree(msg2);
|
||||
}
|
||||
delete methNameW;
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
#define SETDISPPARAMS(dp, numArgs, pvArgs, numNamed, pNamed) \
|
||||
{\
|
||||
(dp).cArgs = numArgs; \
|
||||
(dp).rgvarg = pvArgs; \
|
||||
(dp).cNamedArgs = numNamed; \
|
||||
(dp).rgdispidNamedArgs = pNamed; \
|
||||
}
|
||||
|
||||
#define SETNOPARAMS(dp) SETDISPPARAMS(dp, 0, NULL, 0, NULL)
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
(JNIEnv *env, jclass clazz,
|
||||
jobject disp, jstring name, jint dispid,
|
||||
jint lcid, jint wFlags, jobjectArray vArg, jintArray uArgErr)
|
||||
{
|
||||
DISPPARAMS dispparams;
|
||||
EXCEPINFO excepInfo;
|
||||
// Sourceforge Bug Tracker 2935662 uninitialized data can be not NULL with bad results
|
||||
excepInfo.pfnDeferredFillIn = NULL;
|
||||
|
||||
IDispatch *pIDispatch = extractDispatch(env, disp);
|
||||
if (!pIDispatch) return NULL;
|
||||
|
||||
int dispID = dispid;
|
||||
if (name != NULL)
|
||||
{
|
||||
const char *nm = env->GetStringUTFChars(name, NULL);
|
||||
HRESULT hr;
|
||||
if (FAILED(hr = name2ID(pIDispatch, nm, (long *)&dispID, lcid))) {
|
||||
char buf[1024];
|
||||
sprintf_s(buf, 1024, "Can't map name to dispid: %s", nm);
|
||||
ThrowComFail(env, buf, -1);
|
||||
return NULL;
|
||||
}
|
||||
env->ReleaseStringUTFChars(name, nm);
|
||||
}
|
||||
|
||||
int num_args = env->GetArrayLength(vArg);
|
||||
int i, j;
|
||||
VARIANT *varr = NULL;
|
||||
if (num_args)
|
||||
{
|
||||
varr = (VARIANT *)CoTaskMemAlloc(num_args*sizeof(VARIANT));
|
||||
/* reverse args for dispatch */
|
||||
for(i=num_args-1,j=0;0<=i;i--,j++)
|
||||
{
|
||||
VariantInit(&varr[j]);
|
||||
jobject arg = env->GetObjectArrayElement(vArg, i);
|
||||
VARIANT *v = extractVariant(env, arg);
|
||||
// no escape from copy?
|
||||
VariantCopy(&varr[j], v);
|
||||
env->DeleteLocalRef(arg);
|
||||
}
|
||||
}
|
||||
// prepare a new return value
|
||||
jclass variantClass = env->FindClass("com/jacob/com/Variant");
|
||||
jmethodID variantCons =
|
||||
env->GetMethodID(variantClass, "<init>", "()V");
|
||||
// construct a variant to return
|
||||
jobject newVariant = env->NewObject(variantClass, variantCons);
|
||||
// get the VARIANT from the newVariant
|
||||
VARIANT *v = extractVariant(env, newVariant);
|
||||
DISPID dispidPropertyPut = DISPID_PROPERTYPUT;
|
||||
|
||||
// determine how to dispatch
|
||||
switch (wFlags)
|
||||
{
|
||||
case DISPATCH_PROPERTYGET: // GET
|
||||
case DISPATCH_METHOD: // METHOD
|
||||
case DISPATCH_METHOD|DISPATCH_PROPERTYGET:
|
||||
{
|
||||
SETDISPPARAMS(dispparams, num_args, varr, 0, NULL);
|
||||
break;
|
||||
}
|
||||
case DISPATCH_PROPERTYPUT:
|
||||
case DISPATCH_PROPERTYPUTREF: // jacob-msg 1075 - SF 1053872
|
||||
{
|
||||
SETDISPPARAMS(dispparams, num_args, varr, 1, &dispidPropertyPut);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
HRESULT hr = 0;
|
||||
jint count = env->GetArrayLength(uArgErr);
|
||||
if ( count != 0 )
|
||||
{
|
||||
jint *uAE = env->GetIntArrayElements(uArgErr, NULL);
|
||||
hr = pIDispatch->Invoke(dispID,IID_NULL,
|
||||
lcid,(WORD)wFlags,&dispparams,v,&excepInfo,(unsigned int *)uAE); // SF 1689061
|
||||
env->ReleaseIntArrayElements(uArgErr, uAE, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = pIDispatch->Invoke(dispID,IID_NULL,
|
||||
lcid,(WORD)wFlags,&dispparams,v,&excepInfo, NULL); // SF 1689061
|
||||
}
|
||||
if (num_args)
|
||||
{
|
||||
// to account for inouts, I need to copy the inputs back to
|
||||
// the java array after the method returns
|
||||
// this occurs, for example, in the ADO wrappers
|
||||
for(i=num_args-1,j=0;0<=i;i--,j++)
|
||||
{
|
||||
jobject arg = env->GetObjectArrayElement(vArg, i);
|
||||
VARIANT *v = extractVariant(env, arg);
|
||||
// reverse copy
|
||||
VariantCopy(v, &varr[j]);
|
||||
// clear out the temporary variant
|
||||
VariantClear(&varr[j]);
|
||||
env->DeleteLocalRef(arg);
|
||||
}
|
||||
}
|
||||
|
||||
if (varr) CoTaskMemFree(varr);
|
||||
|
||||
// check for error and display a somewhat verbose error message
|
||||
if (!SUCCEEDED(hr)) {
|
||||
// two buffers that may have to be freed later
|
||||
wchar_t *buf = NULL;
|
||||
char *dispIdAsName = NULL;
|
||||
// this method can get called with a name or a dispatch id
|
||||
// we need to handle both SF 1114159
|
||||
if (name != NULL){
|
||||
const char *nm = env->GetStringUTFChars(name, NULL);
|
||||
buf = CreateErrorMsgFromInfo(hr, &excepInfo, nm);
|
||||
env->ReleaseStringUTFChars(name, nm);
|
||||
} else {
|
||||
dispIdAsName = new char[256];
|
||||
// get the id string
|
||||
_itoa_s (dispID, dispIdAsName, 256,10);
|
||||
//continue on mostly as before
|
||||
buf = CreateErrorMsgFromInfo(hr,&excepInfo,dispIdAsName);
|
||||
}
|
||||
|
||||
// jacob-msg 3696 - SF 1053866
|
||||
if(hr == DISP_E_EXCEPTION)
|
||||
{
|
||||
if(excepInfo.scode != 0)
|
||||
{
|
||||
hr = excepInfo.scode;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = _com_error::WCodeToHRESULT(excepInfo.wCode);
|
||||
}
|
||||
}
|
||||
|
||||
ThrowComFailUnicode(env, buf, hr);
|
||||
if (buf) delete buf;
|
||||
if (dispIdAsName) delete dispIdAsName;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return newVariant;
|
||||
}
|
||||
|
||||
/*
|
||||
* Wait method added so folks could wait until a com server terminated
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Dispatch_hasExited
|
||||
(JNIEnv *env,jclass clazz, jobject disp, jint dispid, jint lcid) {
|
||||
IDispatch *pIDispatch = extractDispatch(env, disp);
|
||||
if (!pIDispatch) {
|
||||
// should we return 0?
|
||||
return NULL;
|
||||
}
|
||||
ITypeInfo *v;
|
||||
HRESULT hr = pIDispatch->GetTypeInfo(dispid, lcid, &v);
|
||||
if (hr == RPC_E_SERVERCALL_RETRYLATER || hr == RPC_E_CALL_REJECTED || hr
|
||||
== 0) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
95
cpp/jacob/Dispatch.h
Normal file
95
cpp/jacob/Dispatch.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
/* Header for class Dispatch */
|
||||
|
||||
#ifndef _Included_Dispatch
|
||||
#define _Included_Dispatch
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_jacob_com_Dispatch
|
||||
* Method: QueryInterface
|
||||
* Signature: (Ljava/lang/String;)Lcom/jacob/com/Dispatch;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_QueryInterface
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: createInstance
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_createInstanceNative
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: getActiveInstance
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_getActiveInstanceNative
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: coCreateInstance
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_coCreateInstanceNative
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: release
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_release
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: getIDsOfNames
|
||||
* Signature: (Ljava/lang/Object;I[Ljava/lang/String;)[I
|
||||
*/
|
||||
JNIEXPORT jintArray JNICALL Java_com_jacob_com_Dispatch_getIDsOfNames
|
||||
(JNIEnv *, jclass, jobject, jint, jobjectArray);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: invokev
|
||||
* Signature: (Ljava/lang/Object;Ljava/lang/String;III[LVariant;[I)LVariant;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Dispatch_invokev
|
||||
(JNIEnv *, jclass, jobject, jstring, jint, jint, jint, jobjectArray, jintArray);
|
||||
|
||||
/*
|
||||
* Class: Dispatch
|
||||
* Method: wait
|
||||
* Signature: (Ljava/lang/Object;I;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Dispatch_hasExited
|
||||
(JNIEnv *, jclass, jobject, jint, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
370
cpp/jacob/DispatchEvents.cpp
Normal file
370
cpp/jacob/DispatchEvents.cpp
Normal file
@@ -0,0 +1,370 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "DispatchEvents.h"
|
||||
#include "EventProxy.h"
|
||||
// Win32 support for Ole Automation
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <atlbase.h>
|
||||
#include <objbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#define PROXY_FLD "m_pConnPtProxy"
|
||||
|
||||
// defined below
|
||||
BOOL GetEventIID(IUnknown*, IID*, CComBSTR **, DISPID **, int *,LPOLESTR);
|
||||
BOOL GetEventIIDForTypeLib(BSTR, IID*, CComBSTR **, DISPID **, int *,LPOLESTR);
|
||||
BOOL getClassInfoFromProgId(LPOLESTR bsProgId,LPTYPEINFO *pClassInfo);
|
||||
BOOL MapEventIIDs(IID*, CComBSTR **, DISPID **, int *, LPOLESTR , LPTYPEINFO );
|
||||
|
||||
// extract a EventProxy* from a jobject
|
||||
EventProxy *extractProxy(JNIEnv *env, jobject arg)
|
||||
{
|
||||
jclass argClass = env->GetObjectClass(arg);
|
||||
jfieldID ajf = env->GetFieldID( argClass, PROXY_FLD, "I");
|
||||
jint anum = env->GetIntField(arg, ajf);
|
||||
EventProxy *v = (EventProxy *)anum;
|
||||
return v;
|
||||
}
|
||||
|
||||
/*
|
||||
* pushes the EventProxy (*ep) into tje jobject in the PROXY_FLD location
|
||||
*/
|
||||
void putProxy(JNIEnv *env, jobject arg, EventProxy *ep)
|
||||
{
|
||||
jclass argClass = env->GetObjectClass(arg);
|
||||
jfieldID ajf = env->GetFieldID( argClass, PROXY_FLD, "I");
|
||||
jint anum = env->GetIntField(arg, ajf);
|
||||
env->SetIntField(arg, ajf, (jint)ep);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_DispatchEvents
|
||||
* Method: init3
|
||||
* Signature: (Lcom/jacob/com/Dispatch;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init3
|
||||
(JNIEnv *env,
|
||||
jobject _this, jobject src,
|
||||
jobject sink,
|
||||
jstring _progid,
|
||||
jstring _typelib)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
|
||||
if (_typelib != NULL && _progid == NULL){
|
||||
// both are required if typelib exists
|
||||
ThrowComFail(env,"TypeLib was specified but no program id was",-1);
|
||||
return;
|
||||
}
|
||||
|
||||
BSTR typeLib = NULL;
|
||||
if (_typelib != NULL){
|
||||
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||
const char *typelib = env->GetStringUTFChars(_typelib, NULL);
|
||||
typeLib = A2W(typelib);
|
||||
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||
|
||||
//printf("we have a type lib %ls\n",typeLib);
|
||||
}
|
||||
|
||||
// find progid if any
|
||||
LPOLESTR bsProgId = NULL;
|
||||
if (_progid!=NULL) {
|
||||
// why is this UTF instead of unicode? Then we could probably drop the A2W
|
||||
const char *progid = env->GetStringUTFChars(_progid, NULL);
|
||||
bsProgId = A2W(progid);
|
||||
// should we call env->ReleaseStringUTFChars(,) to free the memory like we do everywhere lese?
|
||||
//printf("we have an applicaton %ls\n",bsProgId);
|
||||
}
|
||||
|
||||
// get the IDispatch for the source object
|
||||
IDispatch *pDisp = extractDispatch(env, src);
|
||||
CComQIPtr<IUnknown, &IID_IUnknown> pUnk(pDisp);
|
||||
// see if it implements connection points
|
||||
CComQIPtr<IConnectionPointContainer, &IID_IConnectionPointContainer> pCPC(pUnk);
|
||||
if (!pCPC)
|
||||
{
|
||||
// no events, throw something
|
||||
ThrowComFail(env, "Can't find IConnectionPointContainer", -1);
|
||||
return;
|
||||
}
|
||||
|
||||
IID eventIID;
|
||||
CComBSTR *mNames;
|
||||
DISPID *mIDs;
|
||||
int n_EventMethods;
|
||||
if (_typelib == NULL){
|
||||
if (!GetEventIID(pUnk, &eventIID, &mNames, &mIDs, &n_EventMethods,bsProgId)) {
|
||||
ThrowComFail(env, "Can't find event iid", -1);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!GetEventIIDForTypeLib(typeLib, &eventIID, &mNames, &mIDs, &n_EventMethods,bsProgId)) {
|
||||
ThrowComFail(env, "Can't find event iid for type lib", -1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// hook up to the default source iid
|
||||
CComPtr<IConnectionPoint> pCP;
|
||||
HRESULT hr = pCPC->FindConnectionPoint(eventIID, &pCP);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
EventProxy *ep = new EventProxy(env, sink, pCP, eventIID, mNames, mIDs, n_EventMethods);
|
||||
// need to store ep on _this, in case it gets collected
|
||||
putProxy(env, _this, ep);
|
||||
} else {
|
||||
ThrowComFail(env, "Can't FindConnectionPoint", hr);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: DispatchEvents
|
||||
* Method: release
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_release
|
||||
(JNIEnv *env, jobject _this)
|
||||
{
|
||||
EventProxy *ep = extractProxy(env, _this);
|
||||
if (ep) {
|
||||
// this is the line that blows up in IETest
|
||||
ep->Release();
|
||||
putProxy(env, _this, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* I need a reverse map from the event interface's dispids to
|
||||
* function names so that we can reflect them to java
|
||||
*/
|
||||
void
|
||||
LoadNameCache(LPTYPEINFO pTypeInfo, LPTYPEATTR pta,
|
||||
CComBSTR **mNames, DISPID **mIDs, int *nmeth)
|
||||
{
|
||||
CComBSTR *names = NULL;
|
||||
DISPID *ids = NULL;
|
||||
int m_nCount;
|
||||
|
||||
m_nCount = pta->cFuncs;
|
||||
*nmeth = m_nCount;
|
||||
names = m_nCount == 0 ? NULL : new CComBSTR[m_nCount];
|
||||
ids = m_nCount == 0 ? NULL : new DISPID[m_nCount];
|
||||
for (int i=0; i<m_nCount; i++)
|
||||
{
|
||||
FUNCDESC* pfd;
|
||||
if (SUCCEEDED(pTypeInfo->GetFuncDesc(i, &pfd)))
|
||||
{
|
||||
CComBSTR bstrName;
|
||||
if (SUCCEEDED(pTypeInfo->GetDocumentation(pfd->memid, &bstrName, NULL, NULL, NULL)))
|
||||
{
|
||||
names[i].Attach(bstrName.Detach());
|
||||
ids[i] = pfd->memid;
|
||||
/*
|
||||
USES_CONVERSION;
|
||||
printf("map:%d -> %s\n", ids[i], W2A((OLECHAR *)names[i]));
|
||||
*/
|
||||
}
|
||||
pTypeInfo->ReleaseFuncDesc(pfd);
|
||||
}
|
||||
}
|
||||
*mNames = names;
|
||||
*mIDs = ids;
|
||||
}
|
||||
|
||||
#define IMPLTYPE_MASK \
|
||||
(IMPLTYPEFLAG_FDEFAULT | IMPLTYPEFLAG_FSOURCE | IMPLTYPEFLAG_FRESTRICTED)
|
||||
|
||||
#define IMPLTYPE_DEFAULTSOURCE \
|
||||
(IMPLTYPEFLAG_FDEFAULT | IMPLTYPEFLAG_FSOURCE)
|
||||
|
||||
BOOL GetEventIID(IUnknown *m_pObject, IID* piid,
|
||||
CComBSTR **mNames, DISPID **mIDs, int *nmeth,LPOLESTR bsProgId)
|
||||
{
|
||||
*piid = GUID_NULL;
|
||||
ATLASSERT(m_pObject != NULL);
|
||||
// I Always use IProvideClassInfo rather than IProvideClassInfo2
|
||||
// since I also need to create a mapping from dispid to name
|
||||
LPPROVIDECLASSINFO pPCI = NULL;
|
||||
LPTYPEINFO pClassInfo = NULL;
|
||||
if (SUCCEEDED(m_pObject->QueryInterface(IID_IProvideClassInfo, (LPVOID*)&pPCI)))
|
||||
{
|
||||
//printf("got IProvideClassInfo\n");
|
||||
ATLASSERT(pPCI != NULL);
|
||||
HRESULT hr = pPCI->GetClassInfo(&pClassInfo);
|
||||
pPCI->Release();
|
||||
if (!SUCCEEDED(hr)) return false;
|
||||
}
|
||||
else if (getClassInfoFromProgId(bsProgId,&pClassInfo)) {
|
||||
}
|
||||
else {
|
||||
printf("GetEventIID: couldn't get IProvideClassInfo\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return MapEventIIDs(piid, mNames, mIDs, nmeth, bsProgId, pClassInfo);
|
||||
}
|
||||
|
||||
BOOL MapEventIIDs(IID* piid,
|
||||
CComBSTR **mNames, DISPID **mIDs, int *nmeth, LPOLESTR bsProgId, LPTYPEINFO pClassInfo)
|
||||
{
|
||||
ATLASSERT(pClassInfo != NULL);
|
||||
//printf("MapEventIIDs: got past ClassInfo assert\n");
|
||||
LPTYPEATTR pClassAttr;
|
||||
if (SUCCEEDED(pClassInfo->GetTypeAttr(&pClassAttr)))
|
||||
{
|
||||
//printf("MapEventIIDs: got TypeAttr\n");
|
||||
ATLASSERT(pClassAttr != NULL);
|
||||
ATLASSERT(pClassAttr->typekind == TKIND_COCLASS);
|
||||
|
||||
// Search for typeinfo of the default events interface.
|
||||
int nFlags;
|
||||
HREFTYPE hRefType;
|
||||
|
||||
//printf("MapEventIIDs: looking at %d class attribute impl types \n");
|
||||
for (unsigned int i = 0; i < pClassAttr->cImplTypes; i++)
|
||||
{
|
||||
if (SUCCEEDED(pClassInfo->GetImplTypeFlags(i, &nFlags)) &&
|
||||
((nFlags & IMPLTYPE_MASK) == IMPLTYPE_DEFAULTSOURCE))
|
||||
{
|
||||
// Found it. Now look at its attributes to get IID.
|
||||
LPTYPEINFO pEventInfo = NULL;
|
||||
if (SUCCEEDED(pClassInfo->GetRefTypeOfImplType(i,
|
||||
&hRefType)) &&
|
||||
SUCCEEDED(pClassInfo->GetRefTypeInfo(hRefType,
|
||||
&pEventInfo)))
|
||||
{
|
||||
ATLASSERT(pEventInfo != NULL);
|
||||
LPTYPEATTR pEventAttr;
|
||||
if (SUCCEEDED(pEventInfo->GetTypeAttr(&pEventAttr)))
|
||||
{
|
||||
ATLASSERT(pEventAttr != NULL);
|
||||
|
||||
// create a mapping from dispid to string
|
||||
LoadNameCache(pEventInfo, pEventAttr,
|
||||
mNames, mIDs, nmeth);
|
||||
|
||||
*piid = pEventAttr->guid;
|
||||
pEventInfo->ReleaseTypeAttr(pEventAttr);
|
||||
}
|
||||
pEventInfo->Release();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
pClassInfo->ReleaseTypeAttr(pClassAttr);
|
||||
}
|
||||
pClassInfo->Release();
|
||||
|
||||
return (!IsEqualIID(*piid, GUID_NULL));
|
||||
}
|
||||
|
||||
BOOL getClassInfoFromProgId(LPOLESTR bsProgId,LPTYPEINFO *pClassInfo)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
CLSID clsid;
|
||||
GUID libid;
|
||||
if (FAILED(CLSIDFromProgID(bsProgId, &clsid))) return false;
|
||||
if (FAILED(StringFromCLSID(clsid,&bsProgId))) return false;
|
||||
HKEY keySoftware, keyClasses, keyCLSID, keyXXXX, keyTypeLib;
|
||||
DWORD dwType, dwCountData=50;
|
||||
BYTE abData[50];
|
||||
LONG lVal;
|
||||
lVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,_T("SOFTWARE"),0,KEY_READ,&keySoftware);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keySoftware,_T("Classes"),0,KEY_READ,&keyClasses);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keyClasses,_T("CLSID"),0,KEY_READ,&keyCLSID);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
_TCHAR *tsProgId = W2T(bsProgId);
|
||||
lVal = RegOpenKeyEx(keyCLSID,tsProgId,0,KEY_READ,&keyXXXX);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegOpenKeyEx(keyXXXX,_T("TypeLib"),0,KEY_READ,&keyTypeLib);
|
||||
if (lVal==ERROR_SUCCESS) {
|
||||
lVal = RegQueryValueExA(keyTypeLib,NULL,NULL,&dwType,abData,&dwCountData);
|
||||
RegCloseKey(keyTypeLib);
|
||||
}
|
||||
RegCloseKey(keyXXXX);
|
||||
}
|
||||
RegCloseKey(keyCLSID);
|
||||
}
|
||||
RegCloseKey(keyClasses);
|
||||
}
|
||||
RegCloseKey(keySoftware);
|
||||
}
|
||||
if (lVal!=ERROR_SUCCESS) return false;
|
||||
BSTR bsLibId = A2BSTR((char*)abData);
|
||||
if (FAILED(CLSIDFromString(bsLibId,&libid))) return false;
|
||||
//Try loading from registry information.
|
||||
ITypeLib* pITypeLib;
|
||||
if (FAILED(LoadRegTypeLib(libid,1,0, LANG_NEUTRAL, &pITypeLib))) return false;
|
||||
//Find ITypeInfo for coclass.
|
||||
pITypeLib->GetTypeInfoOfGuid(clsid, pClassInfo);
|
||||
pITypeLib->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the class info from the progId using the given typeLib.
|
||||
*/
|
||||
BOOL getClassInfoFromProgIdTypeLib(BSTR typeLib, LPOLESTR bsProgId, LPTYPEINFO *pClassInfo)
|
||||
{
|
||||
USES_CONVERSION;
|
||||
CLSID clsid;
|
||||
|
||||
if (FAILED(CLSIDFromProgID(bsProgId, &clsid))) return false;
|
||||
if (FAILED(StringFromCLSID(clsid,&bsProgId))) return false;
|
||||
|
||||
ITypeLib* pITypeLib;
|
||||
if (FAILED(LoadTypeLib(typeLib, &pITypeLib))) return false;
|
||||
|
||||
//Find ITypeInfo for coclass.
|
||||
pITypeLib->GetTypeInfoOfGuid(clsid, pClassInfo);
|
||||
pITypeLib->Release();
|
||||
return true;
|
||||
}
|
||||
|
||||
BOOL GetEventIIDForTypeLib(BSTR typeLib, IID* piid,
|
||||
CComBSTR **mNames, DISPID **mIDs, int *nmeth,LPOLESTR bsProgId)
|
||||
{
|
||||
LPTYPEINFO pClassInfo = NULL;
|
||||
if(getClassInfoFromProgIdTypeLib(typeLib, bsProgId,&pClassInfo))
|
||||
{
|
||||
if (pClassInfo == NULL){
|
||||
printf("we had a successful return but pClassInfo is null\n");
|
||||
}
|
||||
return MapEventIIDs(piid, mNames, mIDs, nmeth, bsProgId, pClassInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("GetEventIIDForTypeLib: couldn't get IProvideClassInfo\n");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
50
cpp/jacob/DispatchEvents.h
Normal file
50
cpp/jacob/DispatchEvents.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
/* Header for class DispatchEvents */
|
||||
|
||||
#ifndef _Included_DispatchEvents
|
||||
#define _Included_DispatchEvents
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_DispatchEvents
|
||||
* Method: init3
|
||||
* Signature: (Lcom/jacob/com/Dispatch;Ljava/lang/Object;Ljava/lang/String;Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_init3
|
||||
(JNIEnv *, jobject, jobject, jobject, jstring, jstring);
|
||||
|
||||
/*
|
||||
* Class: DispatchEvents
|
||||
* Method: release
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchEvents_release
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
106
cpp/jacob/DispatchProxy.cpp
Normal file
106
cpp/jacob/DispatchProxy.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include <objbase.h>
|
||||
#include "ComThread.h"
|
||||
// Win32 support for Ole Automation
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <atlbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
#include "util.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
// extract a IStream from a jobject
|
||||
IStream *extractStream(JNIEnv *env, jobject arg)
|
||||
{
|
||||
jclass argClass = env->GetObjectClass(arg);
|
||||
jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "I");
|
||||
jint anum = env->GetIntField(arg, ajf);
|
||||
IStream *v = (IStream *)anum;
|
||||
return v;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchProxy_MarshalIntoStream
|
||||
(JNIEnv *env, jobject _this, jobject disp)
|
||||
{
|
||||
IDispatch *pIDispatch = extractDispatch(env, disp);
|
||||
if (!pIDispatch) return;
|
||||
IStream *ps; // this is the stream we will marshall into
|
||||
HRESULT hr = CoMarshalInterThreadInterfaceInStream(
|
||||
IID_IDispatch, pIDispatch, &ps);
|
||||
if (!SUCCEEDED(hr))
|
||||
{
|
||||
ThrowComFail(env, "Could not Marshal Dispatch into IStream", hr);
|
||||
return;
|
||||
}
|
||||
// store the stream pointer on the object
|
||||
jclass argClass = env->GetObjectClass(_this);
|
||||
jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "I");
|
||||
env->SetIntField(_this, ajf, (jint)ps);
|
||||
}
|
||||
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_DispatchProxy_MarshalFromStream
|
||||
(JNIEnv *env, jobject _this)
|
||||
{
|
||||
IStream *ps = extractStream(env, _this);
|
||||
if (!ps)
|
||||
{
|
||||
ThrowComFail(env, "Could not get IStream from DispatchProxy", -1);
|
||||
return NULL;
|
||||
}
|
||||
IDispatch *pD;
|
||||
HRESULT hr = CoGetInterfaceAndReleaseStream(ps, IID_IDispatch, (void **)&pD);
|
||||
// zero out the stream pointer on the object
|
||||
// since the stream can only be read once
|
||||
jclass argClass = env->GetObjectClass(_this);
|
||||
jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "I");
|
||||
env->SetIntField(_this, ajf, (unsigned int)0);
|
||||
|
||||
if (!SUCCEEDED(hr))
|
||||
{
|
||||
ThrowComFail(env, "Could not Marshal Dispatch from IStream", hr);
|
||||
return NULL;
|
||||
}
|
||||
jclass autoClass = env->FindClass("com/jacob/com/Dispatch");
|
||||
jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(I)V");
|
||||
// construct a Dispatch object to return
|
||||
// I am copying the pointer to java
|
||||
if (pD) pD->AddRef();
|
||||
jobject newAuto = env->NewObject(autoClass, autoCons, pD);
|
||||
return newAuto;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchProxy_release
|
||||
(JNIEnv *env, jobject _this)
|
||||
{
|
||||
IStream *ps = extractStream(env, _this);
|
||||
if (ps) {
|
||||
ps->Release();
|
||||
jclass argClass = env->GetObjectClass(_this);
|
||||
jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "I");
|
||||
env->SetIntField(_this, ajf, (unsigned int)0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
55
cpp/jacob/DispatchProxy.h
Normal file
55
cpp/jacob/DispatchProxy.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
/* Header for class com_jacob_com_DispatchProxy */
|
||||
|
||||
#ifndef _Included_com_jacob_com_DispatchProxy
|
||||
#define _Included_com_jacob_com_DispatchProxy
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_jacob_com_DispatchProxy
|
||||
* Method: MarshalIntoStream
|
||||
* Signature: (Lcom/jacob/com/Dispatch;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchProxy_MarshalIntoStream
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_DispatchProxy
|
||||
* Method: MarshalFromStream
|
||||
* Signature: ()Lcom/jacob/com/Dispatch;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_DispatchProxy_MarshalFromStream
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_DispatchProxy
|
||||
* Method: release
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchProxy_release
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
131
cpp/jacob/EnumVariant.cpp
Normal file
131
cpp/jacob/EnumVariant.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include <objbase.h>
|
||||
#include "Dispatch.h"
|
||||
// Win32 support for Ole Automation
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <atlbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
#include "util.h"
|
||||
|
||||
/**
|
||||
* An implementation of IEnumVariant based on code submitted by
|
||||
* Thomas Hallgren (mailto:Thomas.Hallgren@eoncompany.com)
|
||||
*/
|
||||
extern "C"
|
||||
{
|
||||
|
||||
// extract a IDispatch from a jobject
|
||||
IEnumVARIANT* extractEnumVariant(JNIEnv* env, jobject arg)
|
||||
{
|
||||
jfieldID FID_pIEnumVARIANT = 0;
|
||||
jclass clazz = env->GetObjectClass(arg);
|
||||
FID_pIEnumVARIANT = env->GetFieldID(clazz, "m_pIEnumVARIANT", "I");
|
||||
return (IEnumVARIANT*)env->GetIntField(arg, FID_pIEnumVARIANT);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL
|
||||
Java_com_jacob_com_EnumVariant_Next(JNIEnv* env, jobject _this, jobjectArray vars)
|
||||
{
|
||||
IEnumVARIANT* self = extractEnumVariant(env, _this);
|
||||
//printf("self=%x\n", self);
|
||||
if(self == NULL)
|
||||
return 0;
|
||||
|
||||
ULONG count = (ULONG)env->GetArrayLength(vars);
|
||||
if(count == 0)
|
||||
return 0;
|
||||
|
||||
VARIANT* sink = (VARIANT*)CoTaskMemAlloc(count * sizeof(VARIANT));
|
||||
ULONG fetchCount = 0;
|
||||
|
||||
HRESULT hr = self->Next(count, sink, &fetchCount);
|
||||
if(FAILED(hr))
|
||||
{
|
||||
CoTaskMemFree(sink);
|
||||
ThrowComFail(env, "IEnumVARIANT::Next", hr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// prepare a new return value array
|
||||
//
|
||||
jclass clazz = env->FindClass("com/jacob/com/Variant");
|
||||
jmethodID ctor = env->GetMethodID(clazz, "<init>", "()V");
|
||||
|
||||
for(ULONG idx = 0; idx < fetchCount; ++idx)
|
||||
{
|
||||
// construct a variant to return
|
||||
//
|
||||
jobject newVariant = env->NewObject(clazz, ctor);
|
||||
VARIANT* v = extractVariant(env, newVariant);
|
||||
VariantCopy(v, sink + idx);
|
||||
env->SetObjectArrayElement(vars, idx, newVariant);
|
||||
env->DeleteLocalRef(newVariant);
|
||||
//Sourceforge-1674179 fix memory leak
|
||||
// Variants received while iterating IEnumVARIANT must be cleared when no longer needed
|
||||
// The variant has been copied so no longer needed
|
||||
VariantClear(sink);
|
||||
}
|
||||
CoTaskMemFree(sink);
|
||||
return (jint)fetchCount;
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_jacob_com_EnumVariant_release(JNIEnv* env, jobject _this)
|
||||
{
|
||||
IEnumVARIANT* self = extractEnumVariant(env, _this);
|
||||
if(self != NULL)
|
||||
{
|
||||
self->Release();
|
||||
jfieldID FID_pIEnumVARIANT = 0;
|
||||
jclass clazz = env->GetObjectClass(_this);
|
||||
FID_pIEnumVARIANT = env->GetFieldID(clazz, "m_pIEnumVARIANT", "I");
|
||||
env->SetIntField(_this, FID_pIEnumVARIANT, (unsigned int)0);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_jacob_com_EnumVariant_Reset(JNIEnv* env, jobject _this)
|
||||
{
|
||||
IEnumVARIANT* self = extractEnumVariant(env, _this);
|
||||
if(self == NULL)
|
||||
return;
|
||||
|
||||
HRESULT hr = self->Reset();
|
||||
if(FAILED(hr))
|
||||
ThrowComFail(env, "IEnumVARIANT::Reset", hr);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_jacob_com_EnumVariant_Skip(JNIEnv* env, jobject _this, jint count)
|
||||
{
|
||||
IEnumVARIANT* self = extractEnumVariant(env, _this);
|
||||
if(self == NULL)
|
||||
return;
|
||||
|
||||
HRESULT hr = self->Skip((ULONG)count);
|
||||
if(FAILED(hr))
|
||||
ThrowComFail(env, "IEnumVARIANT::Skip", hr);
|
||||
}
|
||||
|
||||
}
|
||||
63
cpp/jacob/EnumVariant.h
Normal file
63
cpp/jacob/EnumVariant.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#ifndef _Included_EnumVariant
|
||||
#define _Included_EnumVariant
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_jacob_com_EnumVariant
|
||||
* Method: Next
|
||||
* Signature: ([Lcom/jacob/com/Variant;)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_EnumVariant_Next
|
||||
(JNIEnv *, jobject, jobjectArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_EnumVariant
|
||||
* Method: Release
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_EnumVariant_release
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_EnumVariant
|
||||
* Method: Reset
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_EnumVariant_Reset
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_EnumVariant
|
||||
* Method: Skip
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_EnumVariant_Skip
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
870
cpp/jacob/EventProxy.cpp
Normal file
870
cpp/jacob/EventProxy.cpp
Normal file
@@ -0,0 +1,870 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "EventProxy.h"
|
||||
#include "Variant.h"
|
||||
|
||||
// hook myself up as a listener for delegate
|
||||
EventProxy::EventProxy(JNIEnv *env,
|
||||
jobject aSinkObj,
|
||||
CComPtr<IConnectionPoint> pConn,
|
||||
IID eid,
|
||||
CComBSTR mName[],
|
||||
DISPID mID[],
|
||||
int mNum) :
|
||||
// initialize some variables
|
||||
m_cRef(0), pCP(pConn),
|
||||
eventIID(eid), MethNum(mNum), MethName(mName),
|
||||
MethID(mID)
|
||||
{
|
||||
// keep a pointer to the sink
|
||||
javaSinkObj = env->NewGlobalRef(aSinkObj);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
|
||||
// we need this to attach to the event invocation thread
|
||||
env->GetJavaVM(&jvm);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
AddRef();
|
||||
Connect(env);
|
||||
}
|
||||
|
||||
void EventProxy::Connect(JNIEnv *env) {
|
||||
HRESULT hr = pCP->Advise(this, &dwEventCookie);
|
||||
if (SUCCEEDED(hr)) {
|
||||
connected = 1;
|
||||
} else {
|
||||
connected = 0;
|
||||
ThrowComFail(env, "Advise failed", hr);
|
||||
}
|
||||
}
|
||||
|
||||
// unhook myself up as a listener and get rid of delegate
|
||||
EventProxy::~EventProxy()
|
||||
{
|
||||
JNIEnv *env;
|
||||
Disconnect();
|
||||
jint vmConnectionStatus = JNI_EVERSION ;
|
||||
jint attachReturnStatus = -1; // AttachCurrentThread return status.. negative numbers are failure return codes.
|
||||
|
||||
// attach to the current running thread -- JDK 1.4 jni.h has two param cover for 3 param call
|
||||
vmConnectionStatus = jvm->GetEnv((void **)&env, JNI_VERSION_1_2);
|
||||
if ((env != NULL)&& env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
if (vmConnectionStatus == JNI_EDETACHED){
|
||||
//printf("Unhook: Attaching to current thread using JNI Version 1.2 (%d)\n",vmConnectionStatus);
|
||||
JavaVMAttachArgs attachmentArgs;
|
||||
attachmentArgs.version = JNI_VERSION_1_2;
|
||||
attachmentArgs.name = NULL;
|
||||
attachmentArgs.group = NULL;
|
||||
attachReturnStatus = jvm->AttachCurrentThread((void **)&env, &attachmentArgs);
|
||||
if ((env != NULL) && env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
} else {
|
||||
// should really look for JNI_OK versus an error because it could have been JNI_EVERSION
|
||||
// started method with thread hooked to VM so no need to attach again
|
||||
//printf("Unhook: No need to attach because already attached %d\n",vmConnectionStatus);
|
||||
}
|
||||
|
||||
// we should always have an env by this point but lets be paranoid and check
|
||||
if (env != NULL){
|
||||
env->DeleteGlobalRef(javaSinkObj);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
}
|
||||
if (MethNum) {
|
||||
delete [] MethName;
|
||||
delete [] MethID;
|
||||
}
|
||||
// detach from thread only if we attached to it in this function
|
||||
if (attachReturnStatus == 0){
|
||||
jvm->DetachCurrentThread();
|
||||
//printf("Unhook: Detached\n");
|
||||
} else {
|
||||
//printf("Unhook: No need to detatch because attached prior to method\n");
|
||||
}
|
||||
//fflush(stdout);
|
||||
}
|
||||
|
||||
void EventProxy::Disconnect() {
|
||||
if (connected) {
|
||||
pCP->Unadvise(dwEventCookie);
|
||||
}
|
||||
}
|
||||
|
||||
// I only support the eventIID interface which was passed in
|
||||
// by the DispatchEvent wrapper who looked it up as the
|
||||
// source object's default source interface
|
||||
STDMETHODIMP EventProxy::QueryInterface(REFIID rid, void **ppv)
|
||||
{
|
||||
if (rid == IID_IUnknown || rid == eventIID || rid == IID_IDispatch)
|
||||
{
|
||||
*ppv = this;
|
||||
AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
// This should never get called - the event source fires events
|
||||
// by dispid's, not by name
|
||||
STDMETHODIMP EventProxy::GetIDsOfNames(REFIID riid,
|
||||
OLECHAR **rgszNames, UINT cNames, LCID lcid, DISPID *rgDispID)
|
||||
{
|
||||
return E_UNEXPECTED;
|
||||
}
|
||||
|
||||
// The actual callback from the connection point arrives here
|
||||
STDMETHODIMP EventProxy::Invoke(DISPID dispID, REFIID riid,
|
||||
LCID lcid, unsigned short wFlags, DISPPARAMS *pDispParams,
|
||||
VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
|
||||
{
|
||||
const char *eventMethodName = NULL; //Sourceforge report 1394001
|
||||
JNIEnv *env = NULL;
|
||||
|
||||
// map dispID to jmethodID
|
||||
for(int i=0;i<MethNum;i++)
|
||||
{
|
||||
if (MethID[i] == dispID) {
|
||||
USES_CONVERSION;
|
||||
eventMethodName = W2A((OLECHAR *)MethName[i]);
|
||||
}
|
||||
}
|
||||
// added 1.12
|
||||
if (!eventMethodName) {
|
||||
// just bail if can't find signature. no need to attach
|
||||
// printf("Invoke: didn't find method name for dispatch id %d\n",dispID);
|
||||
return S_OK;
|
||||
}
|
||||
if (DISPATCH_METHOD & wFlags)
|
||||
{
|
||||
|
||||
// attach to the current running thread
|
||||
//printf("Invoke: Attaching to current thread using JNI Version 1.2\n");
|
||||
JavaVMAttachArgs attachmentArgs;
|
||||
attachmentArgs.version = JNI_VERSION_1_2;
|
||||
attachmentArgs.name = NULL;
|
||||
attachmentArgs.group = NULL;
|
||||
jvm->AttachCurrentThread((void **)&env, &attachmentArgs);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
|
||||
if (!eventMethodName)
|
||||
{
|
||||
// could not find this signature in list
|
||||
// printf("Invoke: didn't find method name for dispatch id %d\n",dispID);
|
||||
// this probably leaves a native thread attached to the vm when we don't want it
|
||||
ThrowComFail(env, "Event method received was not defined as part of callback interface", -1);
|
||||
|
||||
// should we detatch before returning?? We probably never get here if we ThrowComFail()
|
||||
// jvm->DetachCurrentThread();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// find the class of the InvocationHandler
|
||||
jclass javaSinkClass = env->GetObjectClass(javaSinkObj);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
//printf("Invoke: Got sink class\n");
|
||||
jmethodID invokeMethod;
|
||||
invokeMethod = env->GetMethodID(javaSinkClass, "invoke", "(Ljava/lang/String;[Lcom/jacob/com/Variant;)Lcom/jacob/com/Variant;");
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
jstring eventMethodNameAsString = env->NewStringUTF(eventMethodName);
|
||||
//printf("Invoke: Got method name\n");
|
||||
// now do what we need for the variant
|
||||
jmethodID getVariantMethod = env->GetMethodID(javaSinkClass, "getVariant", "()Lcom/jacob/com/Variant;");
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
//printf("Invoke: Found way too getVariant\n");
|
||||
jobject aVariantObj = env->CallObjectMethod(javaSinkObj, getVariantMethod);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
//printf("Invoke: Made Variant\n");
|
||||
jclass variantClass = env->GetObjectClass(aVariantObj);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
|
||||
// create the variant parameter array
|
||||
// how many params
|
||||
int numVariantParams = pDispParams->cArgs;
|
||||
// make an array of them
|
||||
jobjectArray varr = env->NewObjectArray(numVariantParams, variantClass, 0);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
//printf("Invoke: Created Array\n");
|
||||
int i,j;
|
||||
for(i=numVariantParams-1,j=0;i>=0;i--,j++)
|
||||
{
|
||||
// construct a java variant holder
|
||||
jobject arg = env->CallObjectMethod(javaSinkObj, getVariantMethod);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
// get the empty variant from it
|
||||
VARIANT *va = extractVariant(env, arg);
|
||||
// copy the value
|
||||
VariantCopy(va, &pDispParams->rgvarg[i]);
|
||||
// put it in the array
|
||||
env->SetObjectArrayElement(varr, j, arg);
|
||||
env->DeleteLocalRef(arg);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
}
|
||||
//printf("Invoke: Filled Array\n");
|
||||
// Set up the return value
|
||||
jobject ret;
|
||||
|
||||
ret = env->CallObjectMethod(javaSinkObj, invokeMethod,
|
||||
eventMethodNameAsString, varr);
|
||||
//printf("Invoke: Invoked callback\n");
|
||||
if (!env->ExceptionOccurred() && ret != NULL) {
|
||||
VariantCopy(pVarResult, extractVariant(env,ret));
|
||||
}
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
// don't need the first variant we created to get the class
|
||||
// SF 1689061 change not accepted but put in as comment for later reminder
|
||||
//Java_com_jacob_com_Variant_release(env, aVariantObj);
|
||||
env->DeleteLocalRef(aVariantObj);
|
||||
if (env->ExceptionOccurred()) { env->ExceptionDescribe(); env->ExceptionClear();}
|
||||
|
||||
// Begin code from Jiffie team that copies parameters back from java to COM
|
||||
for(i=numVariantParams-1,j=0;i>=0;i--,j++)
|
||||
{
|
||||
jobject arg = env->GetObjectArrayElement(varr, j);
|
||||
VARIANT *java = extractVariant(env, arg);
|
||||
VARIANT *com = &pDispParams->rgvarg[i];
|
||||
convertJavaVariant(java, com);
|
||||
// SF 1689061 change not accepted but put in as comment for later reminder
|
||||
//Java_com_jacob_com_Variant_release(env, arg);
|
||||
zeroVariant(env, arg);
|
||||
env->DeleteLocalRef(arg);
|
||||
}
|
||||
// End code from Jiffie team that copies parameters back from java to COM
|
||||
// detach from thread
|
||||
//printf("Invoke: Detatching\n");
|
||||
jvm->DetachCurrentThread();
|
||||
//fflush(stdout);
|
||||
return S_OK;
|
||||
}
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
void EventProxy::convertJavaVariant(VARIANT *java, VARIANT *com) {
|
||||
|
||||
switch (com->vt)
|
||||
{
|
||||
case VT_DISPATCH:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_DISPATCH:
|
||||
{
|
||||
V_DISPATCH(com) = V_DISPATCH(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DISPATCH | VT_BYREF:
|
||||
{
|
||||
V_DISPATCH(com) = *V_DISPATCHREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DISPATCH | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_DISPATCH:
|
||||
{
|
||||
*V_DISPATCHREF(com) = V_DISPATCH(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DISPATCH | VT_BYREF:
|
||||
{
|
||||
*V_DISPATCHREF(com) = *V_DISPATCHREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BOOL:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_BOOL:
|
||||
{
|
||||
V_BOOL(com) = V_BOOL(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BOOL | VT_BYREF:
|
||||
{
|
||||
V_BOOL(com) = *V_BOOLREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BOOL | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_BOOL:
|
||||
{
|
||||
*V_BOOLREF(com) = V_BOOL(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BOOL | VT_BYREF:
|
||||
{
|
||||
*V_BOOLREF(com) = *V_BOOLREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI1:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UI1:
|
||||
{
|
||||
V_UI1(com) = V_UI1(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI1 | VT_BYREF:
|
||||
{
|
||||
V_UI1(com) = *V_UI1REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI1 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UI1:
|
||||
{
|
||||
*V_UI1REF(com) = V_UI1(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI1 | VT_BYREF:
|
||||
{
|
||||
*V_UI1REF(com) = *V_UI1REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
case VT_I2:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_I2:
|
||||
{
|
||||
V_I2(com) = V_I2(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I2 | VT_BYREF:
|
||||
{
|
||||
V_I2(com) = *V_I2REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I2 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_I2:
|
||||
{
|
||||
*V_I2REF(com) = V_I2(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I2 | VT_BYREF:
|
||||
{
|
||||
*V_I2REF(com) = *V_I2REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I4:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_I4:
|
||||
{
|
||||
V_I4(com) = V_I4(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I4 | VT_BYREF:
|
||||
{
|
||||
V_I4(com) = *V_I4REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I4 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_I4:
|
||||
{
|
||||
*V_I4REF(com) = V_I4(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I4 | VT_BYREF:
|
||||
{
|
||||
*V_I4REF(com) = *V_I4REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R4:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_R4:
|
||||
{
|
||||
V_R4(com) = V_R4(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R4 | VT_BYREF:
|
||||
{
|
||||
V_R4(com) = *V_R4REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R4 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_R4:
|
||||
{
|
||||
*V_R4REF(com) = V_R4(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R4 | VT_BYREF:
|
||||
{
|
||||
*V_R4REF(com) = *V_R4REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R8:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_R8:
|
||||
{
|
||||
V_R8(com) = V_R8(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R8 | VT_BYREF:
|
||||
{
|
||||
V_R8(com) = *V_R8REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R8 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_R8:
|
||||
{
|
||||
*V_R8REF(com) = V_R8(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_R8 | VT_BYREF:
|
||||
{
|
||||
*V_R8REF(com) = *V_R8REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I1:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_I1:
|
||||
{
|
||||
V_I1(com) = V_I1(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I1 | VT_BYREF:
|
||||
{
|
||||
V_I1(com) = *V_I1REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I1 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_I1:
|
||||
{
|
||||
*V_I1REF(com) = V_I1(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_I1 | VT_BYREF:
|
||||
{
|
||||
*V_I1REF(com) = *V_I1REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI2:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UI2:
|
||||
{
|
||||
V_UI2(com) = V_UI2(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI2 | VT_BYREF:
|
||||
{
|
||||
V_UI2(com) = *V_UI2REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI2 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UI2:
|
||||
{
|
||||
*V_UI2REF(com) = V_UI2(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI2 | VT_BYREF:
|
||||
{
|
||||
*V_UI2REF(com) = *V_UI2REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI4:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UI4:
|
||||
{
|
||||
V_UI4(com) = V_UI4(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI4 | VT_BYREF:
|
||||
{
|
||||
V_UI4(com) = *V_UI4REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI4 | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UI4:
|
||||
{
|
||||
*V_UI4REF(com) = V_UI4(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UI4 | VT_BYREF:
|
||||
{
|
||||
*V_UI4REF(com) = *V_UI4REF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_INT:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_INT:
|
||||
{
|
||||
V_INT(com) = V_INT(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_INT | VT_BYREF:
|
||||
{
|
||||
V_INT(com) = *V_INTREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_INT | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_INT:
|
||||
{
|
||||
*V_INTREF(com) = V_INT(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_INT | VT_BYREF:
|
||||
{
|
||||
*V_INTREF(com) = *V_INTREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UINT:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UINT:
|
||||
{
|
||||
V_UINT(com) = V_UINT(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UINT | VT_BYREF:
|
||||
{
|
||||
V_UINT(com) = *V_UINTREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UINT | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_UINT:
|
||||
{
|
||||
*V_UINTREF(com) = V_UINT(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_UINT | VT_BYREF:
|
||||
{
|
||||
*V_UINTREF(com) = *V_UINTREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_CY:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_CY:
|
||||
{
|
||||
V_CY(com) = V_CY(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_CY | VT_BYREF:
|
||||
{
|
||||
V_CY(com) = *V_CYREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_CY | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_CY:
|
||||
{
|
||||
*V_CYREF(com) = V_CY(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_CY | VT_BYREF:
|
||||
{
|
||||
*V_CYREF(com) = *V_CYREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DATE:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_DATE:
|
||||
{
|
||||
V_DATE(com) = V_DATE(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DATE | VT_BYREF:
|
||||
{
|
||||
V_DATE(com) = *V_DATEREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DATE | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_DATE:
|
||||
{
|
||||
*V_DATEREF(com) = V_DATE(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DATE | VT_BYREF:
|
||||
{
|
||||
*V_DATEREF(com) = *V_DATEREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BSTR:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_BSTR:
|
||||
{
|
||||
V_BSTR(com) = V_BSTR(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BSTR | VT_BYREF:
|
||||
{
|
||||
V_BSTR(com) = *V_BSTRREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BSTR | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_BSTR:
|
||||
{
|
||||
*V_BSTRREF(com) = V_BSTR(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_BSTR | VT_BYREF:
|
||||
{
|
||||
*V_BSTRREF(com) = *V_BSTRREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DECIMAL:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_DECIMAL:
|
||||
{
|
||||
V_DECIMAL(com) = V_DECIMAL(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DECIMAL | VT_BYREF:
|
||||
{
|
||||
V_DECIMAL(com) = *V_DECIMALREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DECIMAL | VT_BYREF:
|
||||
{
|
||||
switch (java->vt)
|
||||
{
|
||||
case VT_DECIMAL:
|
||||
{
|
||||
*V_DECIMALREF(com) = V_DECIMAL(java);
|
||||
break;
|
||||
}
|
||||
|
||||
case VT_DECIMAL | VT_BYREF:
|
||||
{
|
||||
*V_DECIMALREF(com) = *V_DECIMALREF(java);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
101
cpp/jacob/EventProxy.h
Normal file
101
cpp/jacob/EventProxy.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
#include "stdafx.h"
|
||||
#include "util.h"
|
||||
|
||||
/*
|
||||
* An instance of this class stands between a connection point
|
||||
* and a java object. When it gets invoked from the cp, it reflects
|
||||
* the call into the java object dynamically. The eventIID is passed
|
||||
* in as are the valid dispids and the corresponding names. A map
|
||||
* is created between the dispids and the java object's method in
|
||||
* the constructor. For now, all the java event methods have to have
|
||||
* the same signature: <name>(Variant[])
|
||||
*/
|
||||
class EventProxy : public IDispatch
|
||||
{
|
||||
private:
|
||||
int connected;
|
||||
LONG m_cRef; // a reference counter
|
||||
CComPtr<IConnectionPoint> pCP; // the connection point
|
||||
DWORD dwEventCookie; // connection point cookie
|
||||
jobject javaSinkObj; // the java object to delegate calls
|
||||
|
||||
IID eventIID; // the interface iid passed in
|
||||
int MethNum; // number of methods in the callback interface
|
||||
CComBSTR *MethName; // Array of method names
|
||||
DISPID *MethID; // Array of method ids, used to match invokations to method names
|
||||
JavaVM *jvm; // The java vm we are running
|
||||
void convertJavaVariant(VARIANT *java, VARIANT *com);
|
||||
void Connect(JNIEnv *env);
|
||||
void Disconnect();
|
||||
public:
|
||||
// constuct with a global JNI ref to a sink object
|
||||
// to which we will delegate event callbacks
|
||||
EventProxy(JNIEnv *jenv,
|
||||
jobject aSinkObj,
|
||||
CComPtr<IConnectionPoint> pConn,
|
||||
IID eventIID,
|
||||
CComBSTR *mName,
|
||||
DISPID *mID,
|
||||
int mNum);
|
||||
~EventProxy();
|
||||
|
||||
// IUnknown methods
|
||||
STDMETHODIMP_(ULONG) AddRef(void)
|
||||
{
|
||||
LONG res = InterlockedIncrement(&m_cRef);
|
||||
return res;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) Release(void)
|
||||
{
|
||||
LONG res = InterlockedDecrement(&m_cRef);
|
||||
if (res == 0) {
|
||||
delete this;
|
||||
}
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
STDMETHODIMP QueryInterface(REFIID rid, void **ppv);
|
||||
|
||||
// IDispatch methods
|
||||
STDMETHODIMP GetTypeInfoCount(UINT *num)
|
||||
{
|
||||
*num = 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP GetTypeInfo(UINT, LCID, ITypeInfo **pptInfo)
|
||||
{
|
||||
*pptInfo=NULL;
|
||||
return E_NOTIMPL;
|
||||
}
|
||||
|
||||
// These are the actual supported methods
|
||||
STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR **, UINT, LCID , DISPID *);
|
||||
STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD , DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
|
||||
};
|
||||
63
cpp/jacob/STA.cpp
Normal file
63
cpp/jacob/STA.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include <objbase.h>
|
||||
#include "ComThread.h"
|
||||
// Win32 support for Ole Automation
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <atlbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
#include "util.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_STA_doMessagePump
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
// store the current thread id so we can kill it
|
||||
jclass argClass = env->GetObjectClass(obj);
|
||||
jfieldID ajf = env->GetFieldID( argClass, "threadID", "I");
|
||||
jint threadID = (jint)GetCurrentThreadId();
|
||||
env->SetIntField(obj, ajf, threadID);
|
||||
|
||||
MSG msg;
|
||||
|
||||
ZeroMemory(&msg, sizeof(msg));
|
||||
msg.wParam = S_OK;
|
||||
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_STA_quitMessagePump
|
||||
(JNIEnv *env, jobject obj)
|
||||
{
|
||||
jclass argClass = env->GetObjectClass(obj);
|
||||
jfieldID ajf = env->GetFieldID( argClass, "threadID", "I");
|
||||
jint threadID = env->GetIntField(obj, ajf);
|
||||
PostThreadMessage((DWORD)threadID, WM_QUIT, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
47
cpp/jacob/STA.h
Normal file
47
cpp/jacob/STA.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
/* Header for class STA */
|
||||
|
||||
#ifndef _Included_com_jacob_com_STA
|
||||
#define _Included_com_jacob_com_STA
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_jacob_com_STA
|
||||
* Method: doMessagePump
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_STA_doMessagePump
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_STA
|
||||
* Method: quitMessagePump
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_STA_quitMessagePump
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
3177
cpp/jacob/SafeArray.cpp
Normal file
3177
cpp/jacob/SafeArray.cpp
Normal file
File diff suppressed because it is too large
Load Diff
940
cpp/jacob/SafeArray.h
Normal file
940
cpp/jacob/SafeArray.h
Normal file
@@ -0,0 +1,940 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
/* Header for class com_jacob_com_SafeArray */
|
||||
|
||||
#ifndef _Included_com_jacob_com_SafeArray
|
||||
#define _Included_com_jacob_com_SafeArray
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/* Inaccessible static: buildVersion */
|
||||
/* Inaccessible static: buildDate */
|
||||
/* Inaccessible static: DEBUG */
|
||||
/* Inaccessible static: class_00024com_00024jacob_00024com_00024JacobObject */
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: init
|
||||
* Signature: (I[I[I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_init
|
||||
(JNIEnv *, jobject, jint, jintArray, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: clone
|
||||
* Signature: ()Ljava/lang/Object;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_SafeArray_clone
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: destroy
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_destroy
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getvt
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getvt
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: reinit
|
||||
* Signature: (Lcom/jacob/com/SafeArray;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_reinit
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: reinterpretType
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_reinterpretType
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getLBound
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getLBound__
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getLBound
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getLBound__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getUBound
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getUBound__
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getUBound
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getUBound__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getNumDim
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getNumDim
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getFeatures
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getFeatures
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getElemSize
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getElemSize
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromCharArray
|
||||
* Signature: ([C)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromCharArray
|
||||
(JNIEnv *, jobject, jcharArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromIntArray
|
||||
* Signature: ([I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromIntArray
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromLongArray
|
||||
* Signature: ([L)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromLongArray
|
||||
(JNIEnv *, jobject, jlongArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromShortArray
|
||||
* Signature: ([S)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromShortArray
|
||||
(JNIEnv *, jobject, jshortArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromDoubleArray
|
||||
* Signature: ([D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromDoubleArray
|
||||
(JNIEnv *, jobject, jdoubleArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromStringArray
|
||||
* Signature: ([Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromStringArray
|
||||
(JNIEnv *, jobject, jobjectArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromByteArray
|
||||
* Signature: ([B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromByteArray
|
||||
(JNIEnv *, jobject, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromFloatArray
|
||||
* Signature: ([F)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromFloatArray
|
||||
(JNIEnv *, jobject, jfloatArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromBooleanArray
|
||||
* Signature: ([Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromBooleanArray
|
||||
(JNIEnv *, jobject, jbooleanArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: fromVariantArray
|
||||
* Signature: ([Lcom/jacob/com/Variant;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_fromVariantArray
|
||||
(JNIEnv *, jobject, jobjectArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toCharArray
|
||||
* Signature: ()[C
|
||||
*/
|
||||
JNIEXPORT jcharArray JNICALL Java_com_jacob_com_SafeArray_toCharArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toIntArray
|
||||
* Signature: ()[I
|
||||
*/
|
||||
JNIEXPORT jintArray JNICALL Java_com_jacob_com_SafeArray_toIntArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toLongArray
|
||||
* Signature: ()[L
|
||||
*/
|
||||
JNIEXPORT jlongArray JNICALL Java_com_jacob_com_SafeArray_toLongArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toShortArray
|
||||
* Signature: ()[S
|
||||
*/
|
||||
JNIEXPORT jshortArray JNICALL Java_com_jacob_com_SafeArray_toShortArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toDoubleArray
|
||||
* Signature: ()[D
|
||||
*/
|
||||
JNIEXPORT jdoubleArray JNICALL Java_com_jacob_com_SafeArray_toDoubleArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toStringArray
|
||||
* Signature: ()[Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_com_jacob_com_SafeArray_toStringArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toByteArray
|
||||
* Signature: ()[B
|
||||
*/
|
||||
JNIEXPORT jbyteArray JNICALL Java_com_jacob_com_SafeArray_toByteArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toFloatArray
|
||||
* Signature: ()[F
|
||||
*/
|
||||
JNIEXPORT jfloatArray JNICALL Java_com_jacob_com_SafeArray_toFloatArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toBooleanArray
|
||||
* Signature: ()[Z
|
||||
*/
|
||||
JNIEXPORT jbooleanArray JNICALL Java_com_jacob_com_SafeArray_toBooleanArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: toVariantArray
|
||||
* Signature: ()[Lcom/jacob/com/Variant;
|
||||
*/
|
||||
JNIEXPORT jobjectArray JNICALL Java_com_jacob_com_SafeArray_toVariantArray
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getChar
|
||||
* Signature: (I)C
|
||||
*/
|
||||
JNIEXPORT jchar JNICALL Java_com_jacob_com_SafeArray_getChar__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getChar
|
||||
* Signature: (II)C
|
||||
*/
|
||||
JNIEXPORT jchar JNICALL Java_com_jacob_com_SafeArray_getChar__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setChar
|
||||
* Signature: (IC)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setChar__IC
|
||||
(JNIEnv *, jobject, jint, jchar);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setChar
|
||||
* Signature: (IIC)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setChar__IIC
|
||||
(JNIEnv *, jobject, jint, jint, jchar);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getChars
|
||||
* Signature: (II[CI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getChars
|
||||
(JNIEnv *, jobject, jint, jint, jcharArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setChars
|
||||
* Signature: (II[CI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setChars
|
||||
(JNIEnv *, jobject, jint, jint, jcharArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getInt
|
||||
* Signature: (I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getInt__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getInt
|
||||
* Signature: (II)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getInt__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setInt
|
||||
* Signature: (II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setInt__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setInt
|
||||
* Signature: (III)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setInt__III
|
||||
(JNIEnv *, jobject, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getInts
|
||||
* Signature: (II[II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getInts
|
||||
(JNIEnv *, jobject, jint, jint, jintArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setInts
|
||||
* Signature: (II[II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setInts
|
||||
(JNIEnv *, jobject, jint, jint, jintArray, jint);
|
||||
|
||||
/*
|
||||
* Class: SafeArray
|
||||
* Method: getLong
|
||||
* Signature: (I)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_jacob_com_SafeArray_getLong__I
|
||||
(JNIEnv *env, jobject _this, jint idx);
|
||||
|
||||
/*
|
||||
* Class: SafeArray
|
||||
* Method: getLong
|
||||
* Signature: (II)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_jacob_com_SafeArray_getLong__II
|
||||
(JNIEnv *env, jobject _this, jint i, jint j);
|
||||
|
||||
/*
|
||||
* Class: SafeArray
|
||||
* Method: setLong
|
||||
* Signature: (IJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setLong__IJ
|
||||
(JNIEnv *env, jobject _this, jint idx, jlong c);
|
||||
|
||||
/*
|
||||
* Class: SafeArray
|
||||
* Method: setLong
|
||||
* Signature: (IIJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setLong__IIJ
|
||||
(JNIEnv *env, jobject _this, jint i, jint j, jlong c);
|
||||
|
||||
/*
|
||||
* Class: SafeArray
|
||||
* Method: getLongs
|
||||
* Signature: (II[JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getLongs
|
||||
(JNIEnv *env, jobject _this, jint idx, jint nelem, jlongArray ja, jint ja_start);
|
||||
|
||||
/*
|
||||
* Class: SafeArray
|
||||
* Method: setLongs
|
||||
* Signature: (II[JI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setLongs
|
||||
(JNIEnv *env, jobject _this, jint idx, jint nelem, jlongArray ja, jint ja_start);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getShort
|
||||
* Signature: (I)S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_com_jacob_com_SafeArray_getShort__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getShort
|
||||
* Signature: (II)S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_com_jacob_com_SafeArray_getShort__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setShort
|
||||
* Signature: (IS)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setShort__IS
|
||||
(JNIEnv *, jobject, jint, jshort);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setShort
|
||||
* Signature: (IIS)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setShort__IIS
|
||||
(JNIEnv *, jobject, jint, jint, jshort);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getShorts
|
||||
* Signature: (II[SI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getShorts
|
||||
(JNIEnv *, jobject, jint, jint, jshortArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setShorts
|
||||
* Signature: (II[SI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setShorts
|
||||
(JNIEnv *, jobject, jint, jint, jshortArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getDouble
|
||||
* Signature: (I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_com_jacob_com_SafeArray_getDouble__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getDouble
|
||||
* Signature: (II)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_com_jacob_com_SafeArray_getDouble__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setDouble
|
||||
* Signature: (ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setDouble__ID
|
||||
(JNIEnv *, jobject, jint, jdouble);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setDouble
|
||||
* Signature: (IID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setDouble__IID
|
||||
(JNIEnv *, jobject, jint, jint, jdouble);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getDoubles
|
||||
* Signature: (II[DI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getDoubles
|
||||
(JNIEnv *, jobject, jint, jint, jdoubleArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setDoubles
|
||||
* Signature: (II[DI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setDoubles
|
||||
(JNIEnv *, jobject, jint, jint, jdoubleArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getString
|
||||
* Signature: (I)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_jacob_com_SafeArray_getString__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getString
|
||||
* Signature: (II)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_jacob_com_SafeArray_getString__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setString
|
||||
* Signature: (ILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setString__ILjava_lang_String_2
|
||||
(JNIEnv *, jobject, jint, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setString
|
||||
* Signature: (IILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setString__IILjava_lang_String_2
|
||||
(JNIEnv *, jobject, jint, jint, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getStrings
|
||||
* Signature: (II[Ljava/lang/String;I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getStrings
|
||||
(JNIEnv *, jobject, jint, jint, jobjectArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setStrings
|
||||
* Signature: (II[Ljava/lang/String;I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setStrings
|
||||
(JNIEnv *, jobject, jint, jint, jobjectArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getByte
|
||||
* Signature: (I)B
|
||||
*/
|
||||
JNIEXPORT jbyte JNICALL Java_com_jacob_com_SafeArray_getByte__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getByte
|
||||
* Signature: (II)B
|
||||
*/
|
||||
JNIEXPORT jbyte JNICALL Java_com_jacob_com_SafeArray_getByte__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setByte
|
||||
* Signature: (IB)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setByte__IB
|
||||
(JNIEnv *, jobject, jint, jbyte);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setByte
|
||||
* Signature: (IIB)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setByte__IIB
|
||||
(JNIEnv *, jobject, jint, jint, jbyte);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getBytes
|
||||
* Signature: (II[BI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getBytes
|
||||
(JNIEnv *, jobject, jint, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setBytes
|
||||
* Signature: (II[BI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setBytes
|
||||
(JNIEnv *, jobject, jint, jint, jbyteArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getFloat
|
||||
* Signature: (I)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_com_jacob_com_SafeArray_getFloat__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getFloat
|
||||
* Signature: (II)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_com_jacob_com_SafeArray_getFloat__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setFloat
|
||||
* Signature: (IF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setFloat__IF
|
||||
(JNIEnv *, jobject, jint, jfloat);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setFloat
|
||||
* Signature: (IIF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setFloat__IIF
|
||||
(JNIEnv *, jobject, jint, jint, jfloat);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getFloats
|
||||
* Signature: (II[FI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getFloats
|
||||
(JNIEnv *, jobject, jint, jint, jfloatArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setFloats
|
||||
* Signature: (II[FI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setFloats
|
||||
(JNIEnv *, jobject, jint, jint, jfloatArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getBoolean
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_SafeArray_getBoolean__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getBoolean
|
||||
* Signature: (II)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_SafeArray_getBoolean__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setBoolean
|
||||
* Signature: (IZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setBoolean__IZ
|
||||
(JNIEnv *, jobject, jint, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setBoolean
|
||||
* Signature: (IIZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setBoolean__IIZ
|
||||
(JNIEnv *, jobject, jint, jint, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getBooleans
|
||||
* Signature: (II[ZI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getBooleans
|
||||
(JNIEnv *, jobject, jint, jint, jbooleanArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setBooleans
|
||||
* Signature: (II[ZI)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setBooleans
|
||||
(JNIEnv *, jobject, jint, jint, jbooleanArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getVariant
|
||||
* Signature: (I)Lcom/jacob/com/Variant;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_SafeArray_getVariant__I
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getVariant
|
||||
* Signature: (II)Lcom/jacob/com/Variant;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_SafeArray_getVariant__II
|
||||
(JNIEnv *, jobject, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setVariant
|
||||
* Signature: (ILcom/jacob/com/Variant;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setVariant__ILcom_jacob_com_Variant_2
|
||||
(JNIEnv *, jobject, jint, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setVariant
|
||||
* Signature: (IILcom/jacob/com/Variant;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setVariant__IILcom_jacob_com_Variant_2
|
||||
(JNIEnv *, jobject, jint, jint, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getVariants
|
||||
* Signature: (II[Lcom/jacob/com/Variant;I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_getVariants
|
||||
(JNIEnv *, jobject, jint, jint, jobjectArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setVariants
|
||||
* Signature: (II[Lcom/jacob/com/Variant;I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setVariants
|
||||
(JNIEnv *, jobject, jint, jint, jobjectArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getVariant
|
||||
* Signature: ([I)Lcom/jacob/com/Variant;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_SafeArray_getVariant___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setVariant
|
||||
* Signature: ([ILcom/jacob/com/Variant;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setVariant___3ILcom_jacob_com_Variant_2
|
||||
(JNIEnv *, jobject, jintArray, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getChar
|
||||
* Signature: ([I)C
|
||||
*/
|
||||
JNIEXPORT jchar JNICALL Java_com_jacob_com_SafeArray_getChar___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setChar
|
||||
* Signature: ([IC)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setChar___3IC
|
||||
(JNIEnv *, jobject, jintArray, jchar);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getInt
|
||||
* Signature: ([I)I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_SafeArray_getInt___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setInt
|
||||
* Signature: ([II)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setInt___3II
|
||||
(JNIEnv *, jobject, jintArray, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getLong
|
||||
* Signature: ([I)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_jacob_com_SafeArray_getLong___3I
|
||||
(JNIEnv *env, jobject _this, jintArray indices);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setLong
|
||||
* Signature: ([IJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setLong___3IJ
|
||||
(JNIEnv *env, jobject _this, jintArray indices, jlong c);
|
||||
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getShort
|
||||
* Signature: ([I)S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_com_jacob_com_SafeArray_getShort___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setShort
|
||||
* Signature: ([IS)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setShort___3IS
|
||||
(JNIEnv *, jobject, jintArray, jshort);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getDouble
|
||||
* Signature: ([I)D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_com_jacob_com_SafeArray_getDouble___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setDouble
|
||||
* Signature: ([ID)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setDouble___3ID
|
||||
(JNIEnv *, jobject, jintArray, jdouble);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getString
|
||||
* Signature: ([I)Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_jacob_com_SafeArray_getString___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setString
|
||||
* Signature: ([ILjava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setString___3ILjava_lang_String_2
|
||||
(JNIEnv *, jobject, jintArray, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getByte
|
||||
* Signature: ([I)B
|
||||
*/
|
||||
JNIEXPORT jbyte JNICALL Java_com_jacob_com_SafeArray_getByte___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setByte
|
||||
* Signature: ([IB)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setByte___3IB
|
||||
(JNIEnv *, jobject, jintArray, jbyte);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getFloat
|
||||
* Signature: ([I)F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_com_jacob_com_SafeArray_getFloat___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setFloat
|
||||
* Signature: ([IF)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setFloat___3IF
|
||||
(JNIEnv *, jobject, jintArray, jfloat);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: getBoolean
|
||||
* Signature: ([I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_SafeArray_getBoolean___3I
|
||||
(JNIEnv *, jobject, jintArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_SafeArray
|
||||
* Method: setBoolean
|
||||
* Signature: ([IZ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_setBoolean___3IZ
|
||||
(JNIEnv *, jobject, jintArray, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
51
cpp/jacob/StdAfx.h
Normal file
51
cpp/jacob/StdAfx.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently,
|
||||
// but are changed infrequently
|
||||
|
||||
#if !defined(AFX_STDAFX_H__9988E984_6789_11D3_A646_000000000000__INCLUDED_)
|
||||
#define AFX_STDAFX_H__9988E984_6789_11D3_A646_000000000000__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
#ifndef STRICT
|
||||
#define STRICT
|
||||
#endif
|
||||
#ifndef _WIN32_WINNT
|
||||
#define _WIN32_WINNT 0x0400
|
||||
#endif
|
||||
//#define _ATL_APARTMENT_THREADED
|
||||
#include <windows.h>
|
||||
#include <comdef.h>
|
||||
#include <comutil.h>
|
||||
#include <atlbase.h>
|
||||
//You may derive a class from CComModule and use it if you want to override
|
||||
//something, but do not change the name of _Module
|
||||
extern CComModule _Module;
|
||||
//#include <atlcom.h>
|
||||
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_STDAFX_H__9988E984_6789_11D3_A646_000000000000__INCLUDED)
|
||||
1274
cpp/jacob/Variant.cpp
Normal file
1274
cpp/jacob/Variant.cpp
Normal file
File diff suppressed because it is too large
Load Diff
605
cpp/jacob/Variant.h
Normal file
605
cpp/jacob/Variant.h
Normal file
@@ -0,0 +1,605 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <jni.h>
|
||||
/* Header for class com_jacob_com_Variant */
|
||||
|
||||
#ifndef _Included_com_jacob_com_Variant
|
||||
#define _Included_com_jacob_com_Variant
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: toEnumVariant
|
||||
* Signature: ()Lcom/jacob/com/EnumVariant;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toEnumVariant
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantNull
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNull
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: cloneIndirect
|
||||
* Signature: ()Lcom_jacob_com_Variant;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_cloneIndirect
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantShortRef
|
||||
* Signature: (S)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantShortRef
|
||||
(JNIEnv *, jobject, jshort);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantIntRef
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantIntRef
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantDoubleRef
|
||||
* Signature: (D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDoubleRef
|
||||
(JNIEnv *, jobject, jdouble);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantDateRef
|
||||
* Signature: (D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDateRef
|
||||
(JNIEnv *, jobject, jdouble);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantStringRef
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantStringRef
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantShortRef
|
||||
* Signature: ()S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantShortRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantIntRef
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantIntRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantShort
|
||||
* Signature: (S)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantShort
|
||||
(JNIEnv *, jobject, jshort);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantShort
|
||||
* Signature: ()S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantShort
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantDoubleRef
|
||||
* Signature: ()D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDoubleRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantDateRef
|
||||
* Signature: ()D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDateRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getStringRef
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getVariantStringRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: com_jacob_com_VariantClear
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_VariantClear
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: toDispatch
|
||||
* Signature: ()LDispatch;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toVariantDispatch
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: clone
|
||||
* Signature: ()Ljava/lang/Object;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_clone
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantInt
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantInt
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantDate
|
||||
* Signature: ()D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDate
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantInt
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantInt
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantDate
|
||||
* Signature: (D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDate
|
||||
(JNIEnv *, jobject, jdouble);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantBoolean
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getVariantBoolean
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantByte
|
||||
* Signature: ()B
|
||||
*/
|
||||
JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getVariantByte
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantBoolean
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantBoolean
|
||||
(JNIEnv *, jobject, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantByte
|
||||
* Signature: (B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantByte
|
||||
(JNIEnv *, jobject, jbyte);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantEmpty
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantEmpty
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantNothing
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNothing
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantError
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantError
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantError
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantError
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantDouble
|
||||
* Signature: ()D
|
||||
*/
|
||||
JNIEXPORT jdouble JNICALL Java_com_jacob_com_Variant_getVariantDouble
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantCurrency
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantCurrency
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantLong
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantLong
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantDispatch
|
||||
* Signature: (Ljava/lang/Object;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDispatch
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantDouble
|
||||
* Signature: (D)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDouble
|
||||
(JNIEnv *, jobject, jdouble);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantCurrency
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantCurrency
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantLong
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantLong
|
||||
(JNIEnv *, jobject);
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantFloatRef
|
||||
* Signature: (F)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantFloatRef
|
||||
(JNIEnv *, jobject, jfloat);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantCurrencyRef
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantCurrencyRef
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantLongRef
|
||||
* Signature: (J)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantLongRef
|
||||
(JNIEnv *, jobject, jlong);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantErrorRef
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantErrorRef
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantBooleanRef
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantBooleanRef
|
||||
(JNIEnv *, jobject, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putObjectRef
|
||||
* Signature: (Ljava/lang/Object;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putObjectRef
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantByteRef
|
||||
* Signature: (B)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantByteRef
|
||||
(JNIEnv *, jobject, jbyte);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getString
|
||||
* Signature: ()Ljava/lang/String;
|
||||
*/
|
||||
JNIEXPORT jstring JNICALL Java_com_jacob_com_Variant_getVariantString
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantString
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantString
|
||||
(JNIEnv *, jobject, jstring);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantFloatRef
|
||||
* Signature: ()F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getVariantFloatRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantCurrencyRef
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantCurrencyRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantLongRef
|
||||
* Signature: ()J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_com_jacob_com_Variant_getVariantLongRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantErrorRef
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantErrorRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantBooleanRef
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_getVariantBooleanRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantByteRef
|
||||
* Signature: ()B
|
||||
*/
|
||||
JNIEXPORT jbyte JNICALL Java_com_jacob_com_Variant_getVariantByteRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: toVariantSafeArray
|
||||
* Signature: (Z)Lcom/jacob/com/SafeArray;
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_toVariantSafeArray
|
||||
(JNIEnv *, jobject, jboolean);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantSafeArrayRef
|
||||
* Signature: (LSafeArray;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantSafeArrayRef
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantSafeArray
|
||||
* Signature: (LSafeArray;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantSafeArray
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantNoParam
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantNoParam
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantFloat
|
||||
* Signature: ()F
|
||||
*/
|
||||
JNIEXPORT jfloat JNICALL Java_com_jacob_com_Variant_getVariantFloat
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantFloat
|
||||
* Signature: (F)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantFloat
|
||||
(JNIEnv *, jobject, jfloat);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: changeVariantType
|
||||
* Signature: (S)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_changeVariantType
|
||||
(JNIEnv *, jobject, jshort);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantType
|
||||
* Signature: ()S
|
||||
*/
|
||||
JNIEXPORT jshort JNICALL Java_com_jacob_com_Variant_getVariantType
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: release
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_release
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: init
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_init
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
JNIEXPORT jbyteArray JNICALL Java_com_jacob_com_Variant_SerializationWriteToBytes
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_SerializationReadFromBytes
|
||||
(JNIEnv *, jobject, jbyteArray);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantVariant
|
||||
* Signature: (Lcom/jacob/com/Variant;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantVariant
|
||||
(JNIEnv *, jobject, jobject);
|
||||
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantVariant
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantDecRef
|
||||
* Signature: (Ljava.math.BigDecimal;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDecRef
|
||||
(JNIEnv *env, jobject _this, jint signum, jbyte scale, jint lo, jint mid, jint hi);
|
||||
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: putVariantDec
|
||||
* Signature: (Ljava.math.BigDecimal;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDec
|
||||
(JNIEnv *env, jobject _this, jint signum, jbyte scale, jint lo, jint mid, jint hi);
|
||||
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantDecRef
|
||||
* Signature: ()Ljava.math.BigDecimal
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantDecRef
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: getVariantDec
|
||||
* Signature: ()Ljava.math.BigDecimal
|
||||
*/
|
||||
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantDec
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: isVariantConsideredNull
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_jacob_com_Variant_isVariantConsideredNull
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_jacob_com_Variant
|
||||
* Method: zeroVariant
|
||||
* Signature: ()V
|
||||
*
|
||||
* This should only be used on variant objects created by the
|
||||
* com layer as part of a call through EventProxy.
|
||||
* This zeros out the variant pointer in the Variant object
|
||||
* so that the calling COM program can free the memory.
|
||||
* instead of both the COM program and the Java GC doing it.
|
||||
*/
|
||||
void zeroVariant (JNIEnv *, jobject);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
764
cpp/jacob/include/atlalloc.h
Normal file
764
cpp/jacob/include/atlalloc.h
Normal file
@@ -0,0 +1,764 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#pragma once
|
||||
#ifndef __ATLALLOC_H__
|
||||
#define __ATLALLOC_H__
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <ole2.h>
|
||||
|
||||
#pragma pack(push,_ATL_PACKING)
|
||||
namespace ATL
|
||||
{
|
||||
|
||||
/*
|
||||
This is more than a little unsatisfying. /Wp64 warns when we convert a size_t to an int
|
||||
because it knows such a conversion won't port.
|
||||
But, when we have overloaded templates, there may well exist both conversions and we need
|
||||
to fool the warning into not firing on 32 bit builds
|
||||
*/
|
||||
#if !defined(_ATL_W64)
|
||||
#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86))
|
||||
#define _ATL_W64 __w64
|
||||
#else
|
||||
#define _ATL_W64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Can't use ::std::numeric_limits<T> here because we don't want to introduce a new
|
||||
deprendency of this code on SCL
|
||||
*/
|
||||
|
||||
template<typename T>
|
||||
class AtlLimits;
|
||||
|
||||
template<>
|
||||
class AtlLimits<int _ATL_W64>
|
||||
{
|
||||
public:
|
||||
static const int _Min=INT_MIN;
|
||||
static const int _Max=INT_MAX;
|
||||
};
|
||||
|
||||
template<>
|
||||
class AtlLimits<unsigned int _ATL_W64>
|
||||
{
|
||||
public:
|
||||
static const unsigned int _Min=0;
|
||||
static const unsigned int _Max=UINT_MAX;
|
||||
};
|
||||
|
||||
template<>
|
||||
class AtlLimits<long _ATL_W64>
|
||||
{
|
||||
public:
|
||||
static const long _Min=LONG_MIN;
|
||||
static const long _Max=LONG_MAX;
|
||||
};
|
||||
|
||||
template<>
|
||||
class AtlLimits<unsigned long _ATL_W64>
|
||||
{
|
||||
public:
|
||||
static const unsigned long _Min=0;
|
||||
static const unsigned long _Max=ULONG_MAX;
|
||||
};
|
||||
|
||||
template<>
|
||||
class AtlLimits<long long>
|
||||
{
|
||||
public:
|
||||
static const long long _Min=LLONG_MIN;
|
||||
static const long long _Max=LLONG_MAX;
|
||||
};
|
||||
|
||||
template<>
|
||||
class AtlLimits<unsigned long long>
|
||||
{
|
||||
public:
|
||||
static const unsigned long long _Min=0;
|
||||
static const unsigned long long _Max=ULLONG_MAX;
|
||||
};
|
||||
|
||||
/* generic version */
|
||||
template<typename T>
|
||||
inline HRESULT AtlAdd(T* ptResult, T tLeft, T tRight)
|
||||
{
|
||||
if(::ATL::AtlLimits<T>::_Max-tLeft < tRight)
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
*ptResult= tLeft + tRight;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
/* generic but compariatively slow version */
|
||||
template<typename T>
|
||||
inline HRESULT AtlMultiply(T* ptResult, T tLeft, T tRight)
|
||||
{
|
||||
/* avoid divide 0 */
|
||||
if(tLeft==0)
|
||||
{
|
||||
*ptResult=0;
|
||||
return S_OK;
|
||||
}
|
||||
if(::ATL::AtlLimits<T>::_Max/tLeft < tRight)
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
*ptResult= tLeft * tRight;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
/* fast version for 32 bit integers */
|
||||
template<>
|
||||
inline HRESULT AtlMultiply(int _ATL_W64 *piResult, int _ATL_W64 iLeft, int _ATL_W64 iRight)
|
||||
{
|
||||
__int64 i64Result=static_cast<__int64>(iLeft) * static_cast<__int64>(iRight);
|
||||
if(i64Result>INT_MAX || i64Result < INT_MIN)
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
*piResult=static_cast<int _ATL_W64>(i64Result);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline HRESULT AtlMultiply(unsigned int _ATL_W64 *piResult, unsigned int _ATL_W64 iLeft, unsigned int _ATL_W64 iRight)
|
||||
{
|
||||
unsigned __int64 i64Result=static_cast<unsigned __int64>(iLeft) * static_cast<unsigned __int64>(iRight);
|
||||
if(i64Result>UINT_MAX)
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
*piResult=static_cast<unsigned int _ATL_W64>(i64Result);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline HRESULT AtlMultiply(long _ATL_W64 *piResult, long _ATL_W64 iLeft, long _ATL_W64 iRight)
|
||||
{
|
||||
__int64 i64Result=static_cast<__int64>(iLeft) * static_cast<__int64>(iRight);
|
||||
if(i64Result>LONG_MAX || i64Result < LONG_MIN)
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
*piResult=static_cast<long _ATL_W64>(i64Result);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
template<>
|
||||
inline HRESULT AtlMultiply(unsigned long _ATL_W64 *piResult, unsigned long _ATL_W64 iLeft, unsigned long _ATL_W64 iRight)
|
||||
{
|
||||
unsigned __int64 i64Result=static_cast<unsigned __int64>(iLeft) * static_cast<unsigned __int64>(iRight);
|
||||
if(i64Result>ULONG_MAX)
|
||||
{
|
||||
return E_INVALIDARG;
|
||||
}
|
||||
*piResult=static_cast<unsigned long _ATL_W64>(i64Result);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T AtlMultiplyThrow(T tLeft, T tRight)
|
||||
{
|
||||
T tResult;
|
||||
HRESULT hr=AtlMultiply(&tResult, tLeft, tRight);
|
||||
if(FAILED(hr))
|
||||
{
|
||||
AtlThrow(hr);
|
||||
}
|
||||
return tResult;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T AtlAddThrow(T tLeft, T tRight)
|
||||
{
|
||||
T tResult;
|
||||
HRESULT hr=AtlAdd(&tResult, tLeft, tRight);
|
||||
if(FAILED(hr))
|
||||
{
|
||||
AtlThrow(hr);
|
||||
}
|
||||
return tResult;
|
||||
}
|
||||
|
||||
inline LPVOID AtlCoTaskMemCAlloc(ULONG nCount, ULONG nSize)
|
||||
{
|
||||
HRESULT hr;
|
||||
ULONG nBytes=0;
|
||||
if( FAILED(hr=::ATL::AtlMultiply(&nBytes, nCount, nSize)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return ::CoTaskMemAlloc(nBytes);
|
||||
}
|
||||
|
||||
inline LPVOID AtlCoTaskMemRecalloc(void *pvMemory, ULONG nCount, ULONG nSize)
|
||||
{
|
||||
HRESULT hr;
|
||||
ULONG nBytes=0;
|
||||
if( FAILED(hr=::ATL::AtlMultiply(&nBytes, nCount, nSize)))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return ::CoTaskMemRealloc(pvMemory, nBytes);
|
||||
}
|
||||
|
||||
} // namespace ATL
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma pack(push,8)
|
||||
namespace ATL
|
||||
{
|
||||
// forward declaration of Checked::memcpy_s
|
||||
|
||||
namespace Checked
|
||||
{
|
||||
void __cdecl memcpy_s(__out_bcount_part(s1max,n) void *s1, __in size_t s1max, __in_bcount(n) const void *s2, __in size_t n);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Allocation helpers
|
||||
|
||||
class CCRTAllocator
|
||||
{
|
||||
public:
|
||||
static void* Reallocate(void* p, size_t nBytes) throw()
|
||||
{
|
||||
return realloc(p, nBytes);
|
||||
}
|
||||
|
||||
static void* Allocate(size_t nBytes) throw()
|
||||
{
|
||||
return malloc(nBytes);
|
||||
}
|
||||
|
||||
static void Free(void* p) throw()
|
||||
{
|
||||
free(p);
|
||||
}
|
||||
};
|
||||
|
||||
class CLocalAllocator
|
||||
{
|
||||
public:
|
||||
static void* Allocate(size_t nBytes) throw()
|
||||
{
|
||||
return ::LocalAlloc(LMEM_FIXED, nBytes);
|
||||
}
|
||||
static void* Reallocate(void* p, size_t nBytes) throw()
|
||||
{
|
||||
if (p==NULL){
|
||||
return ( Allocate(nBytes) );
|
||||
|
||||
}
|
||||
if (nBytes==0){
|
||||
Free(p);
|
||||
return NULL;
|
||||
}
|
||||
return ::LocalReAlloc(p, nBytes, 0);
|
||||
|
||||
}
|
||||
static void Free(void* p) throw()
|
||||
{
|
||||
::LocalFree(p);
|
||||
}
|
||||
};
|
||||
|
||||
class CGlobalAllocator
|
||||
{
|
||||
public:
|
||||
static void* Allocate(size_t nBytes) throw()
|
||||
{
|
||||
return ::GlobalAlloc(GMEM_FIXED, nBytes);
|
||||
}
|
||||
static void* Reallocate(void* p, size_t nBytes) throw()
|
||||
{
|
||||
if (p==NULL){
|
||||
return ( Allocate(nBytes) );
|
||||
|
||||
}
|
||||
if (nBytes==0){
|
||||
Free(p);
|
||||
return NULL;
|
||||
}
|
||||
return ( ::GlobalReAlloc(p, nBytes, 0) );
|
||||
}
|
||||
static void Free(void* p) throw()
|
||||
{
|
||||
::GlobalFree(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class Allocator = CCRTAllocator>
|
||||
class CHeapPtrBase
|
||||
{
|
||||
protected:
|
||||
CHeapPtrBase() throw() :
|
||||
m_pData(NULL)
|
||||
{
|
||||
}
|
||||
CHeapPtrBase(CHeapPtrBase<T, Allocator>& p) throw()
|
||||
{
|
||||
m_pData = p.Detach(); // Transfer ownership
|
||||
}
|
||||
explicit CHeapPtrBase(T* pData) throw() :
|
||||
m_pData(pData)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
~CHeapPtrBase() throw()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
protected:
|
||||
CHeapPtrBase<T, Allocator>& operator=(CHeapPtrBase<T, Allocator>& p) throw()
|
||||
{
|
||||
if(m_pData != p.m_pData)
|
||||
Attach(p.Detach()); // Transfer ownership
|
||||
return *this;
|
||||
}
|
||||
|
||||
public:
|
||||
operator T*() const throw()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
T* operator->() const throw()
|
||||
{
|
||||
ATLASSERT(m_pData != NULL);
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
T** operator&() throw()
|
||||
{
|
||||
#if defined(ATLASSUME)
|
||||
ATLASSUME(m_pData == NULL);
|
||||
#endif
|
||||
return &m_pData;
|
||||
}
|
||||
|
||||
// Allocate a buffer with the given number of bytes
|
||||
bool AllocateBytes(size_t nBytes) throw()
|
||||
{
|
||||
ATLASSERT(m_pData == NULL);
|
||||
m_pData = static_cast<T*>(Allocator::Allocate(nBytes));
|
||||
if (m_pData == NULL)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Attach to an existing pointer (takes ownership)
|
||||
void Attach(T* pData) throw()
|
||||
{
|
||||
Allocator::Free(m_pData);
|
||||
m_pData = pData;
|
||||
}
|
||||
|
||||
// Detach the pointer (releases ownership)
|
||||
T* Detach() throw()
|
||||
{
|
||||
T* pTemp = m_pData;
|
||||
m_pData = NULL;
|
||||
return pTemp;
|
||||
}
|
||||
|
||||
// Free the memory pointed to, and set the pointer to NULL
|
||||
void Free() throw()
|
||||
{
|
||||
Allocator::Free(m_pData);
|
||||
m_pData = NULL;
|
||||
}
|
||||
|
||||
// Reallocate the buffer to hold a given number of bytes
|
||||
bool ReallocateBytes(size_t nBytes) throw()
|
||||
{
|
||||
T* pNew;
|
||||
|
||||
pNew = static_cast<T*>(Allocator::Reallocate(m_pData, nBytes));
|
||||
if (pNew == NULL)
|
||||
return false;
|
||||
m_pData = pNew;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public:
|
||||
T* m_pData;
|
||||
};
|
||||
|
||||
template <typename T, class Allocator = CCRTAllocator>
|
||||
class CHeapPtr :
|
||||
public CHeapPtrBase<T, Allocator>
|
||||
{
|
||||
public:
|
||||
CHeapPtr() throw()
|
||||
{
|
||||
}
|
||||
CHeapPtr(CHeapPtr<T, Allocator>& p) throw() :
|
||||
CHeapPtrBase<T, Allocator>(p)
|
||||
{
|
||||
}
|
||||
explicit CHeapPtr(T* p) throw() :
|
||||
CHeapPtrBase<T, Allocator>(p)
|
||||
{
|
||||
}
|
||||
|
||||
CHeapPtr<T, Allocator>& operator=(CHeapPtr<T, Allocator>& p) throw()
|
||||
{
|
||||
CHeapPtrBase<T, Allocator>::operator=(p);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Allocate a buffer with the given number of elements
|
||||
bool Allocate(size_t nElements = 1) throw()
|
||||
{
|
||||
size_t nBytes=0;
|
||||
if(FAILED(::ATL::AtlMultiply(&nBytes, nElements, sizeof(T))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return AllocateBytes(nBytes);
|
||||
}
|
||||
|
||||
// Reallocate the buffer to hold a given number of elements
|
||||
bool Reallocate(size_t nElements) throw()
|
||||
{
|
||||
size_t nBytes=0;
|
||||
if(FAILED(::ATL::AtlMultiply(&nBytes, nElements, sizeof(T))))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ReallocateBytes(nBytes);
|
||||
}
|
||||
};
|
||||
|
||||
template< typename T, int t_nFixedBytes = 128, class Allocator = CCRTAllocator >
|
||||
class CTempBuffer
|
||||
{
|
||||
public:
|
||||
CTempBuffer() throw() :
|
||||
m_p( NULL )
|
||||
{
|
||||
}
|
||||
CTempBuffer( size_t nElements ) throw( ... ) :
|
||||
m_p( NULL )
|
||||
{
|
||||
Allocate( nElements );
|
||||
}
|
||||
|
||||
~CTempBuffer() throw()
|
||||
{
|
||||
if( m_p != reinterpret_cast< T* >( m_abFixedBuffer ) )
|
||||
{
|
||||
FreeHeap();
|
||||
}
|
||||
}
|
||||
|
||||
operator T*() const throw()
|
||||
{
|
||||
return( m_p );
|
||||
}
|
||||
T* operator->() const throw()
|
||||
{
|
||||
ATLASSERT( m_p != NULL );
|
||||
return( m_p );
|
||||
}
|
||||
|
||||
T* Allocate( size_t nElements ) throw( ... )
|
||||
{
|
||||
return( AllocateBytes( ::ATL::AtlMultiplyThrow(nElements,sizeof( T )) ) );
|
||||
}
|
||||
|
||||
T* Reallocate( size_t nElements ) throw( ... )
|
||||
{
|
||||
ATLENSURE(nElements < size_t(-1)/sizeof(T) );
|
||||
size_t nNewSize = nElements*sizeof( T ) ;
|
||||
|
||||
if (m_p == NULL)
|
||||
return AllocateBytes(nNewSize);
|
||||
|
||||
if (nNewSize > t_nFixedBytes)
|
||||
{
|
||||
if( m_p == reinterpret_cast< T* >( m_abFixedBuffer ) )
|
||||
{
|
||||
// We have to allocate from the heap and copy the contents into the new buffer
|
||||
AllocateHeap(nNewSize);
|
||||
Checked::memcpy_s(m_p, nNewSize, m_abFixedBuffer, t_nFixedBytes);
|
||||
}
|
||||
else
|
||||
{
|
||||
ReAllocateHeap( nNewSize );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_p = reinterpret_cast< T* >( m_abFixedBuffer );
|
||||
}
|
||||
|
||||
return m_p;
|
||||
}
|
||||
|
||||
T* AllocateBytes( size_t nBytes )
|
||||
{
|
||||
ATLASSERT( m_p == NULL );
|
||||
if( nBytes > t_nFixedBytes )
|
||||
{
|
||||
AllocateHeap( nBytes );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_p = reinterpret_cast< T* >( m_abFixedBuffer );
|
||||
}
|
||||
|
||||
return( m_p );
|
||||
}
|
||||
|
||||
private:
|
||||
ATL_NOINLINE void AllocateHeap( size_t nBytes )
|
||||
{
|
||||
T* p = static_cast< T* >( Allocator::Allocate( nBytes ) );
|
||||
if( p == NULL )
|
||||
{
|
||||
AtlThrow( E_OUTOFMEMORY );
|
||||
}
|
||||
m_p = p;
|
||||
}
|
||||
|
||||
ATL_NOINLINE void ReAllocateHeap( size_t nNewSize)
|
||||
{
|
||||
T* p = static_cast< T* >( Allocator::Reallocate(m_p, nNewSize) );
|
||||
if ( p == NULL )
|
||||
{
|
||||
AtlThrow( E_OUTOFMEMORY );
|
||||
}
|
||||
m_p = p;
|
||||
}
|
||||
|
||||
ATL_NOINLINE void FreeHeap() throw()
|
||||
{
|
||||
Allocator::Free( m_p );
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_p;
|
||||
BYTE m_abFixedBuffer[t_nFixedBytes];
|
||||
};
|
||||
|
||||
|
||||
// Allocating memory on the stack without causing stack overflow.
|
||||
// Only use these through the _ATL_SAFE_ALLOCA_* macros
|
||||
namespace _ATL_SAFE_ALLOCA_IMPL
|
||||
{
|
||||
|
||||
#ifndef _ATL_STACK_MARGIN
|
||||
#if defined(_M_IX86)
|
||||
#define _ATL_STACK_MARGIN 0x2000 // Minimum stack available after call to _ATL_SAFE_ALLOCA
|
||||
#else //_M_AMD64 _M_IA64
|
||||
#define _ATL_STACK_MARGIN 0x4000
|
||||
#endif
|
||||
#endif //_ATL_STACK_MARGIN
|
||||
|
||||
//Verifies if sufficient space is available on the stack.
|
||||
//Note: This function should never be inlined, because the stack allocation
|
||||
//may not be freed until the end of the calling function (instead of the end of _AtlVerifyStackAvailable).
|
||||
//The use of __try/__except preverts inlining in this case.
|
||||
#if (_ATL_VER > 0x0301)
|
||||
inline bool _AtlVerifyStackAvailable(SIZE_T Size)
|
||||
{
|
||||
bool bStackAvailable = true;
|
||||
|
||||
__try
|
||||
{
|
||||
SIZE_T size=0;
|
||||
HRESULT hrAdd=::ATL::AtlAdd(&size, Size, static_cast<SIZE_T>(_ATL_STACK_MARGIN));
|
||||
if(FAILED(hrAdd))
|
||||
{
|
||||
ATLASSERT(FALSE);
|
||||
bStackAvailable = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PVOID p = _alloca(size);
|
||||
if (p)
|
||||
{
|
||||
(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
__except ((EXCEPTION_STACK_OVERFLOW == GetExceptionCode()) ?
|
||||
EXCEPTION_EXECUTE_HANDLER :
|
||||
EXCEPTION_CONTINUE_SEARCH)
|
||||
{
|
||||
bStackAvailable = false;
|
||||
_resetstkoflw();
|
||||
}
|
||||
return bStackAvailable;
|
||||
}
|
||||
|
||||
|
||||
// Helper Classes to manage heap buffers for _ATL_SAFE_ALLOCA
|
||||
template < class Allocator>
|
||||
class CAtlSafeAllocBufferManager
|
||||
{
|
||||
private :
|
||||
struct CAtlSafeAllocBufferNode
|
||||
{
|
||||
CAtlSafeAllocBufferNode* m_pNext;
|
||||
#if defined(_M_IX86)
|
||||
BYTE _pad[4];
|
||||
#elif defined(_M_IA64)
|
||||
BYTE _pad[8];
|
||||
#elif defined(_M_AMD64)
|
||||
BYTE _pad[8];
|
||||
#else
|
||||
#error Only supported for X86, AMD64 and IA64
|
||||
#endif
|
||||
void* GetData()
|
||||
{
|
||||
return (this + 1);
|
||||
}
|
||||
};
|
||||
|
||||
CAtlSafeAllocBufferNode* m_pHead;
|
||||
public :
|
||||
|
||||
CAtlSafeAllocBufferManager() : m_pHead(NULL) {};
|
||||
void* Allocate(SIZE_T nRequestedSize)
|
||||
{
|
||||
CAtlSafeAllocBufferNode *p = (CAtlSafeAllocBufferNode*)Allocator::Allocate(::ATL::AtlAddThrow(nRequestedSize, static_cast<SIZE_T>(sizeof(CAtlSafeAllocBufferNode))));
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
// Add buffer to the list
|
||||
p->m_pNext = m_pHead;
|
||||
m_pHead = p;
|
||||
|
||||
return p->GetData();
|
||||
}
|
||||
~CAtlSafeAllocBufferManager()
|
||||
{
|
||||
// Walk the list and free the buffers
|
||||
while (m_pHead != NULL)
|
||||
{
|
||||
CAtlSafeAllocBufferNode* p = m_pHead;
|
||||
m_pHead = m_pHead->m_pNext;
|
||||
Allocator::Free(p);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
} // namespace _ATL_SAFE_ALLOCA_IMPL
|
||||
|
||||
} // namespace ATL
|
||||
#pragma pack(pop)
|
||||
|
||||
// Use one of the following macros before using _ATL_SAFE_ALLOCA
|
||||
// EX version allows specifying a different heap allocator
|
||||
#define USES_ATL_SAFE_ALLOCA_EX(x) ATL::_ATL_SAFE_ALLOCA_IMPL::CAtlSafeAllocBufferManager<x> _AtlSafeAllocaManager
|
||||
|
||||
#ifndef USES_ATL_SAFE_ALLOCA
|
||||
#define USES_ATL_SAFE_ALLOCA USES_ATL_SAFE_ALLOCA_EX(ATL::CCRTAllocator)
|
||||
#endif
|
||||
|
||||
// nRequestedSize - requested size in bytes
|
||||
// nThreshold - size in bytes beyond which memory is allocated from the heap.
|
||||
|
||||
#if (_ATL_VER > 0x0301)
|
||||
|
||||
// Defining _ATL_SAFE_ALLOCA_ALWAYS_ALLOCATE_THRESHOLD_SIZE always allocates the size specified
|
||||
// for threshold if the stack space is available irrespective of requested size.
|
||||
// This available for testing purposes. It will help determine the max stack usage due to _alloca's
|
||||
// Disable _alloca not within try-except prefast warning since we verify stack space is available before.
|
||||
#ifdef _ATL_SAFE_ALLOCA_ALWAYS_ALLOCATE_THRESHOLD_SIZE
|
||||
#define _ATL_SAFE_ALLOCA(nRequestedSize, nThreshold) \
|
||||
__pragma(warning(push))\
|
||||
__pragma(warning(disable:4616))\
|
||||
__pragma(warning(disable:6255))\
|
||||
((nRequestedSize <= nThreshold && ATL::_ATL_SAFE_ALLOCA_IMPL::_AtlVerifyStackAvailable(nThreshold) ) ? \
|
||||
_alloca(nThreshold) : \
|
||||
((ATL::_ATL_SAFE_ALLOCA_IMPL::_AtlVerifyStackAvailable(nThreshold)) ? _alloca(nThreshold) : 0), \
|
||||
_AtlSafeAllocaManager.Allocate(nRequestedSize))\
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
#define _ATL_SAFE_ALLOCA(nRequestedSize, nThreshold) \
|
||||
__pragma(warning(push))\
|
||||
__pragma(warning(disable:4616))\
|
||||
__pragma(warning(disable:6255))\
|
||||
((nRequestedSize <= nThreshold && ATL::_ATL_SAFE_ALLOCA_IMPL::_AtlVerifyStackAvailable(nRequestedSize) ) ? \
|
||||
_alloca(nRequestedSize) : \
|
||||
_AtlSafeAllocaManager.Allocate(nRequestedSize))\
|
||||
__pragma(warning(pop))
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
// Use 1024 bytes as the default threshold in ATL
|
||||
#ifndef _ATL_SAFE_ALLOCA_DEF_THRESHOLD
|
||||
#define _ATL_SAFE_ALLOCA_DEF_THRESHOLD 1024
|
||||
#endif
|
||||
|
||||
#if (_ATL_VER <= 0x0301) // from atlbase.h
|
||||
|
||||
class CComAllocator
|
||||
{
|
||||
public:
|
||||
static void* Reallocate(void* p, size_t nBytes) throw()
|
||||
{
|
||||
#ifdef _WIN64
|
||||
if( nBytes > INT_MAX )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
#endif
|
||||
return ::CoTaskMemRealloc(p, ULONG(nBytes));
|
||||
}
|
||||
static void* Allocate(size_t nBytes) throw()
|
||||
{
|
||||
#ifdef _WIN64
|
||||
if( nBytes > INT_MAX )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
#endif
|
||||
return ::CoTaskMemAlloc(ULONG(nBytes));
|
||||
}
|
||||
static void Free(void* p) throw()
|
||||
{
|
||||
::CoTaskMemFree(p);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class CComHeapPtr :
|
||||
public CHeapPtr<T, CComAllocator>
|
||||
{
|
||||
public:
|
||||
CComHeapPtr() throw()
|
||||
{
|
||||
}
|
||||
|
||||
explicit CComHeapPtr(T* pData) throw() :
|
||||
CHeapPtr<T, CComAllocator>(pData)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
7410
cpp/jacob/include/atlbase.h
Normal file
7410
cpp/jacob/include/atlbase.h
Normal file
File diff suppressed because it is too large
Load Diff
428
cpp/jacob/include/atlbase.inl
Normal file
428
cpp/jacob/include/atlbase.inl
Normal file
@@ -0,0 +1,428 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#ifndef __ATLBASE_INL__
|
||||
#define __ATLBASE_INL__
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __ATLBASE_H__
|
||||
#error atlbase.inl requires atlbase.h to be included first
|
||||
#endif
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4571) //catch(...) blocks compiled with /EHs do NOT catch or re-throw Structured Exceptions
|
||||
namespace ATL
|
||||
{
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Connection Point Helpers
|
||||
|
||||
ATLINLINE ATLAPI AtlAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid, LPDWORD pdw)
|
||||
{
|
||||
if(pUnkCP == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
CComPtr<IConnectionPointContainer> pCPC;
|
||||
CComPtr<IConnectionPoint> pCP;
|
||||
HRESULT hRes = pUnkCP->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC);
|
||||
if (SUCCEEDED(hRes))
|
||||
hRes = pCPC->FindConnectionPoint(iid, &pCP);
|
||||
if (SUCCEEDED(hRes))
|
||||
hRes = pCP->Advise(pUnk, pdw);
|
||||
return hRes;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI AtlUnadvise(IUnknown* pUnkCP, const IID& iid, DWORD dw)
|
||||
{
|
||||
if(pUnkCP == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
CComPtr<IConnectionPointContainer> pCPC;
|
||||
CComPtr<IConnectionPoint> pCP;
|
||||
HRESULT hRes = pUnkCP->QueryInterface(__uuidof(IConnectionPointContainer), (void**)&pCPC);
|
||||
if (SUCCEEDED(hRes))
|
||||
hRes = pCPC->FindConnectionPoint(iid, &pCP);
|
||||
if (SUCCEEDED(hRes))
|
||||
hRes = pCP->Unadvise(dw);
|
||||
return hRes;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Inproc Marshaling helpers
|
||||
|
||||
//This API should be called from the same thread that called
|
||||
//AtlMarshalPtrInProc
|
||||
ATLINLINE ATLAPI AtlFreeMarshalStream(IStream* pStream)
|
||||
{
|
||||
HRESULT hRes=S_OK;
|
||||
if (pStream != NULL)
|
||||
{
|
||||
LARGE_INTEGER l;
|
||||
l.QuadPart = 0;
|
||||
pStream->Seek(l, STREAM_SEEK_SET, NULL);
|
||||
hRes=CoReleaseMarshalData(pStream);
|
||||
pStream->Release();
|
||||
}
|
||||
return hRes;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI AtlMarshalPtrInProc(IUnknown* pUnk, const IID& iid, IStream** ppStream)
|
||||
{
|
||||
ATLASSERT(ppStream != NULL);
|
||||
if (ppStream == NULL)
|
||||
return E_POINTER;
|
||||
|
||||
HRESULT hRes = CreateStreamOnHGlobal(NULL, TRUE, ppStream);
|
||||
if (SUCCEEDED(hRes))
|
||||
{
|
||||
hRes = CoMarshalInterface(*ppStream, iid,
|
||||
pUnk, MSHCTX_INPROC, NULL, MSHLFLAGS_TABLESTRONG);
|
||||
if (FAILED(hRes))
|
||||
{
|
||||
(*ppStream)->Release();
|
||||
*ppStream = NULL;
|
||||
}
|
||||
}
|
||||
return hRes;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI AtlUnmarshalPtr(IStream* pStream, const IID& iid, IUnknown** ppUnk)
|
||||
{
|
||||
ATLASSERT(ppUnk != NULL);
|
||||
if (ppUnk == NULL)
|
||||
return E_POINTER;
|
||||
|
||||
*ppUnk = NULL;
|
||||
HRESULT hRes = E_INVALIDARG;
|
||||
if (pStream != NULL)
|
||||
{
|
||||
LARGE_INTEGER l;
|
||||
l.QuadPart = 0;
|
||||
pStream->Seek(l, STREAM_SEEK_SET, NULL);
|
||||
hRes = CoUnmarshalInterface(pStream, iid, (void**)ppUnk);
|
||||
}
|
||||
return hRes;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Module
|
||||
|
||||
ATLINLINE ATLAPI AtlComModuleGetClassObject(_ATL_COM_MODULE* pComModule, REFCLSID rclsid, REFIID riid, LPVOID* ppv)
|
||||
{
|
||||
ATLASSERT(pComModule != NULL);
|
||||
if (pComModule == NULL)
|
||||
return E_INVALIDARG;
|
||||
if (pComModule->cbSize == 0) // Module hasn't been initialized
|
||||
return E_UNEXPECTED;
|
||||
|
||||
if (ppv == NULL)
|
||||
return E_POINTER;
|
||||
*ppv = NULL;
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast; ppEntry++)
|
||||
{
|
||||
if (*ppEntry != NULL)
|
||||
{
|
||||
_ATL_OBJMAP_ENTRY* pEntry = *ppEntry;
|
||||
if ((pEntry->pfnGetClassObject != NULL) && InlineIsEqualGUID(rclsid, *pEntry->pclsid))
|
||||
{
|
||||
if (pEntry->pCF == NULL)
|
||||
{
|
||||
CComCritSecLock<CComCriticalSection> lock(pComModule->m_csObjMap, false);
|
||||
hr = lock.Lock();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ATLTRACE(atlTraceCOM, 0, _T("ERROR : Unable to lock critical section in AtlComModuleGetClassObject\n"));
|
||||
ATLASSERT(0);
|
||||
break;
|
||||
}
|
||||
if (pEntry->pCF == NULL)
|
||||
hr = pEntry->pfnGetClassObject(pEntry->pfnCreateInstance, __uuidof(IUnknown), (LPVOID*)&pEntry->pCF);
|
||||
}
|
||||
if (pEntry->pCF != NULL)
|
||||
hr = pEntry->pCF->QueryInterface(riid, ppv);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (*ppv == NULL && hr == S_OK)
|
||||
hr = CLASS_E_CLASSNOTAVAILABLE;
|
||||
return hr;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI AtlComModuleRegisterClassObjects(_ATL_COM_MODULE* pComModule, DWORD dwClsContext, DWORD dwFlags)
|
||||
{
|
||||
ATLASSERT(pComModule != NULL);
|
||||
if (pComModule == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
HRESULT hr = S_FALSE;
|
||||
for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast && SUCCEEDED(hr); ppEntry++)
|
||||
{
|
||||
if (*ppEntry != NULL)
|
||||
hr = (*ppEntry)->RegisterClassObject(dwClsContext, dwFlags);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI AtlComModuleRevokeClassObjects(_ATL_COM_MODULE* pComModule)
|
||||
{
|
||||
ATLASSERT(pComModule != NULL);
|
||||
if (pComModule == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
for (_ATL_OBJMAP_ENTRY** ppEntry = pComModule->m_ppAutoObjMapFirst; ppEntry < pComModule->m_ppAutoObjMapLast && hr == S_OK; ppEntry++)
|
||||
{
|
||||
if (*ppEntry != NULL)
|
||||
hr = (*ppEntry)->RevokeClassObject();
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI_(BOOL) AtlWaitWithMessageLoop(HANDLE hEvent)
|
||||
{
|
||||
DWORD dwRet;
|
||||
MSG msg;
|
||||
|
||||
while(1)
|
||||
{
|
||||
dwRet = MsgWaitForMultipleObjects(1, &hEvent, FALSE, INFINITE, QS_ALLINPUT);
|
||||
|
||||
if (dwRet == WAIT_OBJECT_0)
|
||||
return TRUE; // The event was signaled
|
||||
|
||||
if (dwRet != WAIT_OBJECT_0 + 1)
|
||||
break; // Something else happened
|
||||
|
||||
// There is one or more window message available. Dispatch them
|
||||
while(PeekMessage(&msg,0,0,0,PM_NOREMOVE))
|
||||
{
|
||||
// check for unicode window so we call the appropriate functions
|
||||
BOOL bUnicode = ::IsWindowUnicode(msg.hwnd);
|
||||
BOOL bRet;
|
||||
|
||||
if (bUnicode)
|
||||
bRet = ::GetMessageW(&msg, NULL, 0, 0);
|
||||
else
|
||||
bRet = ::GetMessageA(&msg, NULL, 0, 0);
|
||||
|
||||
if (bRet > 0)
|
||||
{
|
||||
::TranslateMessage(&msg);
|
||||
|
||||
if (bUnicode)
|
||||
::DispatchMessageW(&msg);
|
||||
else
|
||||
::DispatchMessageA(&msg);
|
||||
}
|
||||
|
||||
if (WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0)
|
||||
return TRUE; // Event is now signaled.
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// QI support
|
||||
|
||||
ATLINLINE ATLAPI AtlInternalQueryInterface(void* pThis,
|
||||
const _ATL_INTMAP_ENTRY* pEntries, REFIID iid, void** ppvObject)
|
||||
{
|
||||
ATLASSERT(pThis != NULL);
|
||||
ATLASSERT(pEntries!= NULL);
|
||||
|
||||
if(pThis == NULL || pEntries == NULL)
|
||||
return E_INVALIDARG ;
|
||||
|
||||
// First entry in the com map should be a simple map entry
|
||||
ATLASSERT(pEntries->pFunc == _ATL_SIMPLEMAPENTRY);
|
||||
if (ppvObject == NULL)
|
||||
return E_POINTER;
|
||||
*ppvObject = NULL;
|
||||
if (InlineIsEqualUnknown(iid)) // use first interface
|
||||
{
|
||||
IUnknown* pUnk = (IUnknown*)((INT_PTR)pThis+pEntries->dw);
|
||||
pUnk->AddRef();
|
||||
*ppvObject = pUnk;
|
||||
return S_OK;
|
||||
}
|
||||
while (pEntries->pFunc != NULL)
|
||||
{
|
||||
BOOL bBlind = (pEntries->piid == NULL);
|
||||
if (bBlind || InlineIsEqualGUID(*(pEntries->piid), iid))
|
||||
{
|
||||
if (pEntries->pFunc == _ATL_SIMPLEMAPENTRY) //offset
|
||||
{
|
||||
ATLASSERT(!bBlind);
|
||||
IUnknown* pUnk = (IUnknown*)((INT_PTR)pThis+pEntries->dw);
|
||||
pUnk->AddRef();
|
||||
*ppvObject = pUnk;
|
||||
return S_OK;
|
||||
}
|
||||
else //actual function call
|
||||
{
|
||||
HRESULT hRes = pEntries->pFunc(pThis,
|
||||
iid, ppvObject, pEntries->dw);
|
||||
if (hRes == S_OK || (!bBlind && FAILED(hRes)))
|
||||
return hRes;
|
||||
}
|
||||
}
|
||||
pEntries++;
|
||||
}
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI_(DWORD) AtlGetVersion(void* /* pReserved */)
|
||||
{
|
||||
return _ATL_VER;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Windowing
|
||||
|
||||
ATLINLINE ATLAPI_(void) AtlWinModuleAddCreateWndData(_ATL_WIN_MODULE* pWinModule, _AtlCreateWndData* pData, void* pObject)
|
||||
{
|
||||
if (pWinModule == NULL)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ACCESS_VIOLATION);
|
||||
|
||||
ATLASSERT(pData != NULL && pObject != NULL);
|
||||
if(pData == NULL || pObject == NULL)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ACCESS_VIOLATION);
|
||||
|
||||
pData->m_pThis = pObject;
|
||||
pData->m_dwThreadID = ::GetCurrentThreadId();
|
||||
CComCritSecLock<CComCriticalSection> lock(pWinModule->m_csWindowCreate, false);
|
||||
if (FAILED(lock.Lock()))
|
||||
{
|
||||
ATLTRACE(atlTraceWindowing, 0, _T("ERROR : Unable to lock critical section in AtlWinModuleAddCreateWndData\n"));
|
||||
ATLASSERT(0);
|
||||
return;
|
||||
}
|
||||
pData->m_pNext = pWinModule->m_pCreateWndList;
|
||||
pWinModule->m_pCreateWndList = pData;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI_(void*) AtlWinModuleExtractCreateWndData(_ATL_WIN_MODULE* pWinModule)
|
||||
{
|
||||
if (pWinModule == NULL)
|
||||
return NULL;
|
||||
|
||||
void* pv = NULL;
|
||||
CComCritSecLock<CComCriticalSection> lock(pWinModule->m_csWindowCreate, false);
|
||||
if (FAILED(lock.Lock()))
|
||||
{
|
||||
ATLTRACE(atlTraceWindowing, 0, _T("ERROR : Unable to lock critical section in AtlWinModuleExtractCreateWndData\n"));
|
||||
ATLASSERT(0);
|
||||
return pv;
|
||||
}
|
||||
_AtlCreateWndData* pEntry = pWinModule->m_pCreateWndList;
|
||||
if(pEntry != NULL)
|
||||
{
|
||||
DWORD dwThreadID = ::GetCurrentThreadId();
|
||||
_AtlCreateWndData* pPrev = NULL;
|
||||
while(pEntry != NULL)
|
||||
{
|
||||
if(pEntry->m_dwThreadID == dwThreadID)
|
||||
{
|
||||
if(pPrev == NULL)
|
||||
pWinModule->m_pCreateWndList = pEntry->m_pNext;
|
||||
else
|
||||
pPrev->m_pNext = pEntry->m_pNext;
|
||||
pv = pEntry->m_pThis;
|
||||
break;
|
||||
}
|
||||
pPrev = pEntry;
|
||||
pEntry = pEntry->m_pNext;
|
||||
}
|
||||
}
|
||||
return pv;
|
||||
}
|
||||
|
||||
|
||||
ATLINLINE ATLAPI AtlWinModuleInit(_ATL_WIN_MODULE* pWinModule)
|
||||
{
|
||||
if (pWinModule == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
// check only in the DLL
|
||||
if (pWinModule->cbSize != sizeof(_ATL_WIN_MODULE))
|
||||
return E_INVALIDARG;
|
||||
|
||||
pWinModule->m_pCreateWndList = NULL;
|
||||
|
||||
HRESULT hr = pWinModule->m_csWindowCreate.Init();
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ATLTRACE(atlTraceWindowing, 0, _T("ERROR : Unable to initialize critical section in AtlWinModuleInit\n"));
|
||||
ATLASSERT(0);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Module
|
||||
|
||||
ATLINLINE ATLAPI AtlModuleAddTermFunc(_ATL_MODULE* pModule, _ATL_TERMFUNC* pFunc, DWORD_PTR dw)
|
||||
{
|
||||
if (pModule == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
HRESULT hr = S_OK;
|
||||
_ATL_TERMFUNC_ELEM* pNew = NULL;
|
||||
ATLTRY(pNew = new _ATL_TERMFUNC_ELEM);
|
||||
if (pNew == NULL)
|
||||
hr = E_OUTOFMEMORY;
|
||||
else
|
||||
{
|
||||
pNew->pFunc = pFunc;
|
||||
pNew->dw = dw;
|
||||
CComCritSecLock<CComCriticalSection> lock(pModule->m_csStaticDataInitAndTypeInfo, false);
|
||||
hr = lock.Lock();
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
pNew->pNext = pModule->m_pTermFuncs;
|
||||
pModule->m_pTermFuncs = pNew;
|
||||
}
|
||||
else
|
||||
{
|
||||
delete pNew;
|
||||
ATLTRACE(atlTraceGeneral, 0, _T("ERROR : Unable to lock critical section in AtlModuleAddTermFunc\n"));
|
||||
ATLASSERT(0);
|
||||
}
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
ATLINLINE ATLAPI_(void) AtlCallTermFunc(_ATL_MODULE* pModule)
|
||||
{
|
||||
if (pModule == NULL)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ACCESS_VIOLATION);
|
||||
|
||||
_ATL_TERMFUNC_ELEM* pElem = pModule->m_pTermFuncs;
|
||||
_ATL_TERMFUNC_ELEM* pNext = NULL;
|
||||
while (pElem != NULL)
|
||||
{
|
||||
pElem->pFunc(pElem->dw);
|
||||
pNext = pElem->pNext;
|
||||
delete pElem;
|
||||
pElem = pNext;
|
||||
}
|
||||
pModule->m_pTermFuncs = NULL;
|
||||
}
|
||||
|
||||
} // namespace ATL
|
||||
#pragma warning(pop)
|
||||
#endif // __ATLBASE_INL__
|
||||
|
||||
605
cpp/jacob/include/atlchecked.h
Normal file
605
cpp/jacob/include/atlchecked.h
Normal file
@@ -0,0 +1,605 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#ifndef __ATLCHECKED_H__
|
||||
#define __ATLCHECKED_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atldef.h>
|
||||
#include <atlexcept.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <mbstring.h>
|
||||
#include <wchar.h>
|
||||
#include <tchar.h>
|
||||
#include <stdlib.h>
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4127)
|
||||
|
||||
#pragma pack(push,_ATL_PACKING)
|
||||
namespace ATL
|
||||
{
|
||||
|
||||
inline errno_t AtlCrtErrorCheck(errno_t nError)
|
||||
{
|
||||
switch(nError)
|
||||
{
|
||||
case ENOMEM:
|
||||
AtlThrow(E_OUTOFMEMORY);
|
||||
break;
|
||||
case EINVAL:
|
||||
case ERANGE:
|
||||
AtlThrow(E_INVALIDARG);
|
||||
break;
|
||||
case 0:
|
||||
case STRUNCATE:
|
||||
break;
|
||||
default:
|
||||
AtlThrow(E_FAIL);
|
||||
break;
|
||||
}
|
||||
return nError;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Secure (Checked) CRT functions
|
||||
|
||||
namespace Checked
|
||||
{
|
||||
|
||||
#if _SECURE_ATL
|
||||
|
||||
#ifdef _AFX
|
||||
#define ATLMFC_CRT_ERRORCHECK(expr) AFX_CRT_ERRORCHECK(expr)
|
||||
#else
|
||||
#define ATLMFC_CRT_ERRORCHECK(expr) ATL_CRT_ERRORCHECK(expr)
|
||||
#endif
|
||||
|
||||
inline void __cdecl memcpy_s(__out_bcount_part(_S1max,_N) void *_S1, __in size_t _S1max, __in_bcount(_N) const void *_S2, __in size_t _N)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::memcpy_s(_S1, _S1max, _S2, _N));
|
||||
}
|
||||
|
||||
inline void __cdecl wmemcpy_s(__out_ecount_part(_N1,_N) wchar_t *_S1, __in size_t _N1, __in_ecount(_N) const wchar_t *_S2, __in size_t _N)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::wmemcpy_s(_S1, _N1, _S2, _N));
|
||||
}
|
||||
|
||||
inline void __cdecl memmove_s(__out_bcount_part(_S1max,_N) void *_S1, __in size_t _S1max, __in_bcount(_N) const void *_S2, size_t _N)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::memmove_s(_S1, _S1max, _S2, _N));
|
||||
}
|
||||
|
||||
inline void __cdecl strcpy_s(__out_ecount(_S1max) char *_S1, __in size_t _S1max, __in_z const char *_S2)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::strcpy_s(_S1, _S1max, _S2));
|
||||
}
|
||||
|
||||
inline void __cdecl wcscpy_s(__out_ecount(_S1max) wchar_t *_S1, __in size_t _S1max, __in_z const wchar_t *_S2)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscpy_s(_S1, _S1max, _S2));
|
||||
}
|
||||
|
||||
inline void __cdecl tcscpy_s(__out_ecount(_SizeInChars) TCHAR * _Dst, __in size_t _SizeInChars, __in_z const TCHAR * _Src)
|
||||
{
|
||||
#ifndef _ATL_MIN_CRT
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcscpy_s(_Dst, _SizeInChars, _Src));
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscpy_s(_Dst, _SizeInChars, _Src));
|
||||
#else
|
||||
ATLMFC_CRT_ERRORCHECK(::strcpy_s(_Dst, _SizeInChars, _Src));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline errno_t __cdecl strncpy_s(__out_ecount(_SizeInChars) char *_Dest, __in size_t _SizeInChars, __in_z const char *_Source, __in size_t _Count)
|
||||
{
|
||||
return ATLMFC_CRT_ERRORCHECK(::strncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
}
|
||||
|
||||
inline errno_t __cdecl wcsncpy_s(__out_ecount(_SizeInChars) wchar_t *_Dest, __in size_t _SizeInChars, __in_z const wchar_t *_Source, __in size_t _Count)
|
||||
{
|
||||
return ATLMFC_CRT_ERRORCHECK(::wcsncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
}
|
||||
|
||||
inline errno_t __cdecl tcsncpy_s(__out_ecount(_SizeInChars) TCHAR *_Dest, __in size_t _SizeInChars, __in_z const TCHAR *_Source, __in size_t _Count)
|
||||
{
|
||||
#ifndef _ATL_MIN_CRT
|
||||
return ATLMFC_CRT_ERRORCHECK(::_tcsncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
return ATLMFC_CRT_ERRORCHECK(::wcsncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
#else
|
||||
return ATLMFC_CRT_ERRORCHECK(::strncpy_s(_Dest, _SizeInChars, _Source,_Count));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void __cdecl strcat_s(__inout_ecount_z(_SizeInChars) char * _Dst, __in size_t _SizeInChars, __in_z const char * _Src)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::strcat_s(_Dst, _SizeInChars, _Src));
|
||||
}
|
||||
|
||||
inline void __cdecl wcscat_s(__inout_ecount_z(_SizeInChars) wchar_t * _Dst, __in size_t _SizeInChars, __in_z const wchar_t * _Src)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscat_s(_Dst, _SizeInChars, _Src));
|
||||
}
|
||||
|
||||
inline void __cdecl tcscat_s(__inout_ecount_z(_SizeInChars) TCHAR * _Dst, __in size_t _SizeInChars, __in_z const TCHAR * _Src)
|
||||
{
|
||||
#ifndef _ATL_MIN_CRT
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcscat_s(_Dst, _SizeInChars, _Src));
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
ATLMFC_CRT_ERRORCHECK(::wcscat_s(_Dst, _SizeInChars, _Src));
|
||||
#else
|
||||
ATLMFC_CRT_ERRORCHECK(::strcat_s(_Dst, _SizeInChars, _Src));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void __cdecl strlwr_s(__inout_ecount_z(_SizeInChars) char * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_strlwr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl wcslwr_s(__inout_ecount_z(_SizeInChars) wchar_t * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_wcslwr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
#if !defined(_MANAGED)
|
||||
inline void __cdecl mbslwr_s(__inout_bcount_z(_SizeInChars) unsigned char * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_mbslwr_s(_Str, _SizeInChars));
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void __cdecl tcslwr_s(__inout_ecount_z(_SizeInChars) TCHAR * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
#ifndef _ATL_MIN_CRT
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcslwr_s(_Str, _SizeInChars));
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
ATLMFC_CRT_ERRORCHECK(::_wcslwr_s(_Str, _SizeInChars));
|
||||
#else
|
||||
ATLMFC_CRT_ERRORCHECK(::_strlwr_s(_Str, _SizeInChars));
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void __cdecl strupr_s(__inout_ecount_z(_SizeInChars) char * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_strupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl wcsupr_s(__inout_ecount_z(_SizeInChars) wchar_t * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_wcsupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
#if !defined(_MANAGED)
|
||||
inline void __cdecl mbsupr_s(__inout_bcount_z(_SizeInChars) unsigned char * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_mbsupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void __cdecl tcsupr_s(__inout_ecount_z(_SizeInChars) TCHAR * _Str, __in size_t _SizeInChars)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tcsupr_s(_Str, _SizeInChars));
|
||||
}
|
||||
|
||||
inline void __cdecl itoa_s(__in int _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_itoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl itot_s(__in int _Val, __out_ecount_z(_SizeInChars) TCHAR *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_itot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ltoa_s(__in long _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ltoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ltot_s(__in long _Val, __out_ecount_z(_SizeInChars) TCHAR *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ltot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ultoa_s(__in unsigned long _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultoa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ultow_s(__in unsigned long _Val, __out_ecount_z(_SizeInChars) wchar_t *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ultot_s(__in unsigned long _Val, __out_ecount_z(_SizeInChars) TCHAR *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ultot_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl i64toa_s(__in __int64 _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_i64toa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl i64tow_s(__in __int64 _Val, __out_ecount_z(_SizeInChars) wchar_t *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_i64tow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ui64toa_s(__in unsigned __int64 _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ui64toa_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl ui64tow_s(__in unsigned __int64 _Val, __out_ecount_z(_SizeInChars) wchar_t *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_ui64tow_s(_Val, _Buf, _SizeInChars, _Radix));
|
||||
}
|
||||
|
||||
inline void __cdecl gcvt_s(__out_ecount_z(_SizeInChars) char *_Buffer, __in size_t _SizeInChars, __in double _Value, __in int _Ndec)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_gcvt_s(_Buffer, _SizeInChars, _Value, _Ndec));
|
||||
}
|
||||
|
||||
inline void __cdecl tsplitpath_s(__in_z const TCHAR *_Path, __out_ecount_z_opt(_Drive_len) TCHAR *_Drive, __in size_t _Drive_len,
|
||||
__out_ecount_z_opt(_Dir_len) TCHAR *_Dir, __in size_t _Dir_len,
|
||||
__out_ecount_z_opt(_Fname_len) TCHAR *_Fname, __in size_t _Fname_len,
|
||||
__out_ecount_z_opt(_Ext_len) TCHAR *_Ext, __in size_t _Ext_len)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tsplitpath_s(_Path, _Drive, _Drive_len, _Dir, _Dir_len, _Fname, _Fname_len, _Ext, _Ext_len));
|
||||
}
|
||||
|
||||
inline void __cdecl tmakepath_s(__out_ecount_z(_SizeInChars) TCHAR *_Path, __in size_t _SizeInChars, __in_z const TCHAR *_Drive,
|
||||
__in_z const TCHAR *_Dir, __in_z const TCHAR *_Fname, __in_z const TCHAR *_Ext)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_tmakepath_s(_Path, _SizeInChars, _Drive, _Dir, _Fname, _Ext));
|
||||
}
|
||||
|
||||
inline size_t __cdecl strnlen(__in_ecount(_Maxsize) const char *_Str, __in size_t _Maxsize)
|
||||
{
|
||||
return ::strnlen(_Str, _Maxsize);
|
||||
}
|
||||
|
||||
inline size_t __cdecl wcsnlen(__in_ecount(_Maxsize) const wchar_t *_Wcs, __in size_t _Maxsize)
|
||||
{
|
||||
return ::wcsnlen(_Wcs, _Maxsize);
|
||||
}
|
||||
|
||||
inline size_t __cdecl tcsnlen(__in_ecount(_Maxsize) const TCHAR *_Str, __in size_t _Maxsize)
|
||||
{
|
||||
return ::_tcsnlen(_Str, _Maxsize);
|
||||
}
|
||||
|
||||
inline int get_errno()
|
||||
{
|
||||
int nErrNo;
|
||||
ATLMFC_CRT_ERRORCHECK(::_get_errno(&nErrNo));
|
||||
return nErrNo;
|
||||
}
|
||||
|
||||
inline void set_errno(__in int _Value)
|
||||
{
|
||||
ATLMFC_CRT_ERRORCHECK(::_set_errno(_Value));
|
||||
}
|
||||
|
||||
#else // !_SECURE_ATL
|
||||
|
||||
#define ATLMFC_CRT_ERRORCHECK(expr) do { expr; } while (0)
|
||||
|
||||
inline void __cdecl memcpy_s(__out_bcount(_S1max) void *_S1, __in size_t _S1max, __in_bcount(_N) const void *_S2, size_t _N)
|
||||
{
|
||||
(_S1max);
|
||||
memcpy(_S1, _S2, _N);
|
||||
}
|
||||
|
||||
inline void __cdecl wmemcpy_s(__out_ecount(_N1) wchar_t *_S1, __in size_t _N1, __in_ecount(_N) const wchar_t *_S2, __in size_t _N)
|
||||
{
|
||||
(_N1);
|
||||
::wmemcpy(_S1, _S2, _N);
|
||||
}
|
||||
|
||||
inline void __cdecl memmove_s(__out_bcount(_S1max) void *_S1, __in size_t _S1max, __in_bcount(_N) const void *_S2, __in size_t _N)
|
||||
{
|
||||
(_S1max);
|
||||
memmove(_S1, _S2, _N);
|
||||
}
|
||||
|
||||
inline void __cdecl strcpy_s(__out_ecount_z(_S1max) char *_S1, __in size_t _S1max, __in_z const char *_S2)
|
||||
{
|
||||
(_S1max);
|
||||
::strcpy(_S1, _S2);
|
||||
}
|
||||
|
||||
inline void __cdecl wcscpy_s(__out_ecount_z(_S1max) wchar_t *_S1, __in size_t _S1max, __in_z const wchar_t *_S2)
|
||||
{
|
||||
(_S1max);
|
||||
::wcscpy(_S1, _S2);
|
||||
}
|
||||
|
||||
inline void __cdecl tcscpy_s(__out_ecount_z(_SizeInChars) TCHAR * _Dst, __in size_t _SizeInChars, __in_z const TCHAR * _Src)
|
||||
{
|
||||
(_SizeInChars);
|
||||
#ifndef _ATL_MIN_CRT
|
||||
::_tcscpy(_Dst, _Src);
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
::wcscpy(_Dst, _Src);
|
||||
#else
|
||||
::strcpy(_Dst, _Src);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ensure that strncpy_s null-terminate the dest string */
|
||||
inline errno_t __cdecl strncpy_s(__out_ecount_z(_SizeInChars) char *_Dest, __in size_t _SizeInChars, __in_z const char *_Source,__in size_t _Count)
|
||||
{
|
||||
if (_Count == _TRUNCATE)
|
||||
{
|
||||
_Count = _SizeInChars - 1;
|
||||
}
|
||||
while (_Count > 0 && *_Source != 0)
|
||||
{
|
||||
*_Dest++ = *_Source++;
|
||||
--_Count;
|
||||
}
|
||||
*_Dest = 0;
|
||||
|
||||
return (*_Source!=0) ? STRUNCATE : 0;
|
||||
}
|
||||
|
||||
inline errno_t __cdecl wcsncpy_s(__out_ecount_z(_SizeInChars) wchar_t *_Dest, __in size_t _SizeInChars, __in_z const wchar_t *_Source, __in size_t _Count)
|
||||
{
|
||||
if (_Count == _TRUNCATE)
|
||||
{
|
||||
_Count = _SizeInChars - 1;
|
||||
}
|
||||
while (_Count > 0 && *_Source != 0)
|
||||
{
|
||||
*_Dest++ = *_Source++;
|
||||
--_Count;
|
||||
}
|
||||
*_Dest = 0;
|
||||
|
||||
return (*_Source!=0) ? STRUNCATE : 0;
|
||||
}
|
||||
|
||||
inline errno_t __cdecl tcsncpy_s(__out_ecount_z(_SizeInChars) TCHAR *_Dest, __in size_t _SizeInChars, __in_z const TCHAR *_Source,__in size_t _Count)
|
||||
{
|
||||
if (_Count == _TRUNCATE)
|
||||
{
|
||||
if(_SizeInChars>0)
|
||||
{
|
||||
_Count = _SizeInChars - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Count =0;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _ATL_MIN_CRT
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 6535)
|
||||
::_tcsncpy(_Dest,_Source,_Count);
|
||||
#pragma warning(pop)
|
||||
if(_SizeInChars>0)
|
||||
{
|
||||
size_t nulCount = __min(_SizeInChars-1, _Count);
|
||||
_Dest[nulCount] = 0;
|
||||
}
|
||||
#else
|
||||
while (_Count > 0 && *_Source != 0)
|
||||
{
|
||||
*_Dest++ = *_Source++;
|
||||
--_Count;
|
||||
}
|
||||
*_Dest = 0;
|
||||
#endif
|
||||
|
||||
return (*_Source!=0) ? STRUNCATE : 0;
|
||||
}
|
||||
|
||||
inline void __cdecl strcat_s(__inout_ecount_z(_SizeInChars) char * _Dst, __in size_t _SizeInChars, __in_z const char * _Src)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::strcat(_Dst, _Src);
|
||||
}
|
||||
|
||||
inline void __cdecl wcscat_s(__inout_ecount_z(_SizeInChars) wchar_t * _Dst, __in size_t _SizeInChars, __in_z const wchar_t * _Src)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::wcscat(_Dst, _Src);
|
||||
}
|
||||
|
||||
inline void __cdecl tcscat_s(__inout_ecount_z(_SizeInChars) TCHAR * _Dst, __in size_t _SizeInChars, __in_z const TCHAR * _Src)
|
||||
{
|
||||
(_SizeInChars);
|
||||
#ifndef _ATL_MIN_CRT
|
||||
::_tcscat(_Dst, _Src);
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
::wcscat(_Dst, _Src);
|
||||
#else
|
||||
::strcat(_Dst, _Src);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void __cdecl strlwr_s(__inout_ecount_z(_SizeInChars) char * _Str, size_t _SizeInChars)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_strlwr(_Str);
|
||||
}
|
||||
|
||||
inline void __cdecl wcslwr_s(__inout_ecount_z(_SizeInChars) wchar_t * _Str, size_t _SizeInChars)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_wcslwr(_Str);
|
||||
}
|
||||
|
||||
inline void __cdecl mbslwr_s(__inout_bcount_z(_SizeInChars) unsigned char * _Str, size_t _SizeInChars)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_mbslwr(_Str);
|
||||
}
|
||||
|
||||
inline void __cdecl tcslwr_s(__inout_ecount_z(_SizeInChars) TCHAR * _Str, size_t _SizeInChars)
|
||||
{
|
||||
(_SizeInChars);
|
||||
#ifndef _ATL_MIN_CRT
|
||||
::_tcslwr(_Str);
|
||||
#else
|
||||
#ifdef UNICODE
|
||||
::_wcslwr(_Str);
|
||||
#else
|
||||
::_strlwr(_Str);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void __cdecl itoa_s(__in int _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_itoa_s(_Val, _Buf, _SizeInChars, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl itot_s(__in int _Val, __out_ecount_z(_SizeInChars) TCHAR *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_itot(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl ltoa_s(__in long _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_ltoa(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl ltot_s(__in long _Val, __out_ecount_z(_SizeInChars) TCHAR *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_ltot(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl ultoa_s(__in unsigned long _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_ultoa(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl ultow_s(__in unsigned long _Val, __out_ecount_z(_SizeInChars) wchar_t *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_ultow(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl ultot_s(__in unsigned long _Val, __out_ecount_z(_SizeInChars) TCHAR *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_ultot(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl i64toa_s(__in __int64 _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_i64toa(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl i64tow_s(__in __int64 _Val, __out_ecount_z(_SizeInChars) wchar_t *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_i64tow(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl ui64toa_s(__in unsigned __int64 _Val, __out_ecount_z(_SizeInChars) char *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_ui64toa(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl ui64tow_s(__in unsigned __int64 _Val, __out_ecount_z(_SizeInChars) wchar_t *_Buf, __in size_t _SizeInChars, __in int _Radix)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_ui64tow(_Val, _Buf, _Radix);
|
||||
}
|
||||
|
||||
inline void __cdecl gcvt_s(__out_ecount_z(_SizeInChars) char *_Buffer, __in size_t _SizeInChars, __in double _Value, __in int _Ndec)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_gcvt(_Value, _Ndec, _Buffer);
|
||||
}
|
||||
|
||||
inline void __cdecl tsplitpath_s(__in_z const TCHAR *_Path, __out_ecount_z_opt(_Drive_len) TCHAR *_Drive, __in size_t _Drive_len,
|
||||
__out_ecount_z_opt(_Dir_len) TCHAR *_Dir, __in size_t _Dir_len,
|
||||
__out_ecount_z_opt(_Fname_ext) TCHAR *_Fname, __in size_t _Fname_len,
|
||||
__out_ecount_z_opt(_Ext_len) TCHAR *_Ext, __in size_t _Ext_len)
|
||||
{
|
||||
(_Drive_len, _Dir_len, _Fname_len, _Ext_len);
|
||||
::_tsplitpath(_Path, _Drive, _Dir, _Fname, _Ext);
|
||||
}
|
||||
|
||||
inline void __cdecl tmakepath_s(__out_ecount_z(_SizeInChars) TCHAR *_Path, __in size_t _SizeInChars, __in_z const TCHAR *_Drive,
|
||||
__in_z const TCHAR *_Dir, __in_z const TCHAR *_Fname, __in_z const TCHAR *_Ext)
|
||||
{
|
||||
(_SizeInChars);
|
||||
::_tmakepath(_Path, _Drive, _Dir, _Fname, _Ext);
|
||||
}
|
||||
|
||||
inline size_t __cdecl strnlen(__in_ecount(_Maxsize) const char *_Str, __in size_t _Maxsize)
|
||||
{
|
||||
(_Maxsize);
|
||||
return ::strlen(_Str);
|
||||
}
|
||||
|
||||
inline size_t __cdecl wcsnlen(__in_ecount(_Maxsize) const wchar_t *_Wcs, __in size_t _Maxsize)
|
||||
{
|
||||
(_Maxsize);
|
||||
return ::wcslen(_Wcs);
|
||||
}
|
||||
|
||||
inline size_t __cdecl tcsnlen(__in_ecount(_Maxsize) const TCHAR *_Str, __in size_t _Maxsize)
|
||||
{
|
||||
(_Maxsize);
|
||||
return ::_tcslen(_Str);
|
||||
}
|
||||
|
||||
inline int get_errno()
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
inline void set_errno(__in int _Value)
|
||||
{
|
||||
errno = _Value;
|
||||
}
|
||||
|
||||
#endif // _SECURE_ATL
|
||||
|
||||
} // namespace Checked
|
||||
|
||||
} // namespace ATL
|
||||
#pragma warning(pop)
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif // __ATLCHECKED_H__
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
2874
cpp/jacob/include/atlcomcli.h
Normal file
2874
cpp/jacob/include/atlcomcli.h
Normal file
File diff suppressed because it is too large
Load Diff
1302
cpp/jacob/include/atlconv.h
Normal file
1302
cpp/jacob/include/atlconv.h
Normal file
File diff suppressed because it is too large
Load Diff
554
cpp/jacob/include/atlcore.h
Normal file
554
cpp/jacob/include/atlcore.h
Normal file
@@ -0,0 +1,554 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#ifndef __ATLCORE_H__
|
||||
#define __ATLCORE_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef _ATL_ALL_WARNINGS
|
||||
#pragma warning( push )
|
||||
#endif
|
||||
|
||||
#pragma warning(disable: 4786) // identifier was truncated in the debug information
|
||||
#pragma warning(disable: 4127) // constant expression
|
||||
|
||||
#include <atldef.h>
|
||||
#include <windows.h>
|
||||
#include <ole2.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <tchar.h>
|
||||
#include <mbstring.h>
|
||||
|
||||
#include <atlchecked.h>
|
||||
#include <atlsimpcoll.h>
|
||||
|
||||
#pragma pack(push,_ATL_PACKING)
|
||||
namespace ATL
|
||||
{
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Verify that a null-terminated string points to valid memory
|
||||
inline BOOL AtlIsValidString(LPCWSTR psz, size_t nMaxLength = INT_MAX)
|
||||
{
|
||||
(nMaxLength);
|
||||
return (psz != NULL);
|
||||
}
|
||||
|
||||
// Verify that a null-terminated string points to valid memory
|
||||
inline BOOL AtlIsValidString(LPCSTR psz, size_t nMaxLength = UINT_MAX)
|
||||
{
|
||||
(nMaxLength);
|
||||
return (psz != NULL);
|
||||
}
|
||||
|
||||
// Verify that a pointer points to valid memory
|
||||
inline BOOL AtlIsValidAddress(const void* p, size_t nBytes,
|
||||
BOOL bReadWrite = TRUE)
|
||||
{
|
||||
(bReadWrite);
|
||||
(nBytes);
|
||||
return (p != NULL);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline void AtlAssertValidObject(const T *pOb)
|
||||
{
|
||||
ATLASSERT(pOb);
|
||||
ATLASSERT(AtlIsValidAddress(pOb, sizeof(T)));
|
||||
if(pOb)
|
||||
pOb->AssertValid();
|
||||
}
|
||||
#ifdef _DEBUG
|
||||
#define ATLASSERT_VALID(x) ATL::AtlAssertValidObject(x)
|
||||
#else
|
||||
#define ATLASSERT_VALID(x) __noop;
|
||||
#endif
|
||||
|
||||
// COM Sync Classes
|
||||
class CComCriticalSection
|
||||
{
|
||||
public:
|
||||
CComCriticalSection() throw()
|
||||
{
|
||||
memset(&m_sec, 0, sizeof(CRITICAL_SECTION));
|
||||
}
|
||||
~CComCriticalSection()
|
||||
{
|
||||
}
|
||||
HRESULT Lock() throw()
|
||||
{
|
||||
EnterCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Unlock() throw()
|
||||
{
|
||||
LeaveCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
HRESULT hRes = E_FAIL;
|
||||
__try
|
||||
{
|
||||
InitializeCriticalSection(&m_sec);
|
||||
hRes = S_OK;
|
||||
}
|
||||
// structured exception may be raised in low memory situations
|
||||
__except(STATUS_NO_MEMORY == GetExceptionCode())
|
||||
{
|
||||
hRes = E_OUTOFMEMORY;
|
||||
}
|
||||
return hRes;
|
||||
}
|
||||
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
DeleteCriticalSection(&m_sec);
|
||||
return S_OK;
|
||||
}
|
||||
CRITICAL_SECTION m_sec;
|
||||
};
|
||||
|
||||
class CComAutoCriticalSection : public CComCriticalSection
|
||||
{
|
||||
public:
|
||||
CComAutoCriticalSection()
|
||||
{
|
||||
HRESULT hr = CComCriticalSection::Init();
|
||||
if (FAILED(hr))
|
||||
AtlThrow(hr);
|
||||
}
|
||||
~CComAutoCriticalSection() throw()
|
||||
{
|
||||
CComCriticalSection::Term();
|
||||
}
|
||||
private :
|
||||
HRESULT Init(); // Not implemented. CComAutoCriticalSection::Init should never be called
|
||||
HRESULT Term(); // Not implemented. CComAutoCriticalSection::Term should never be called
|
||||
};
|
||||
|
||||
class CComSafeDeleteCriticalSection : public CComCriticalSection
|
||||
{
|
||||
public:
|
||||
CComSafeDeleteCriticalSection(): m_bInitialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
~CComSafeDeleteCriticalSection() throw()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
m_bInitialized = false;
|
||||
CComCriticalSection::Term();
|
||||
}
|
||||
|
||||
HRESULT Init() throw()
|
||||
{
|
||||
ATLASSERT( !m_bInitialized );
|
||||
HRESULT hr = CComCriticalSection::Init();
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
m_bInitialized = true;
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
HRESULT Term() throw()
|
||||
{
|
||||
if (!m_bInitialized)
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
m_bInitialized = false;
|
||||
return CComCriticalSection::Term();
|
||||
}
|
||||
|
||||
HRESULT Lock()
|
||||
{
|
||||
// CComSafeDeleteCriticalSection::Init or CComAutoDeleteCriticalSection::Init
|
||||
// not called or failed.
|
||||
// m_critsec member of CComObjectRootEx is now of type
|
||||
// CComAutoDeleteCriticalSection. It has to be initialized
|
||||
// by calling CComObjectRootEx::_AtlInitialConstruct
|
||||
ATLASSUME(m_bInitialized);
|
||||
return CComCriticalSection::Lock();
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_bInitialized;
|
||||
};
|
||||
|
||||
class CComAutoDeleteCriticalSection : public CComSafeDeleteCriticalSection
|
||||
{
|
||||
private:
|
||||
// CComAutoDeleteCriticalSection::Term should never be called
|
||||
HRESULT Term() throw();
|
||||
};
|
||||
|
||||
class CComFakeCriticalSection
|
||||
{
|
||||
public:
|
||||
HRESULT Lock() throw() { return S_OK; }
|
||||
HRESULT Unlock() throw() { return S_OK; }
|
||||
HRESULT Init() throw() { return S_OK; }
|
||||
HRESULT Term() throw() { return S_OK; }
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Module
|
||||
|
||||
// Used by any project that uses ATL
|
||||
struct _ATL_BASE_MODULE70
|
||||
{
|
||||
UINT cbSize;
|
||||
HINSTANCE m_hInst;
|
||||
HINSTANCE m_hInstResource;
|
||||
bool m_bNT5orWin98;
|
||||
DWORD dwAtlBuildVer;
|
||||
const GUID* pguidVer;
|
||||
CComCriticalSection m_csResource;
|
||||
CSimpleArray<HINSTANCE> m_rgResourceInstance;
|
||||
};
|
||||
typedef _ATL_BASE_MODULE70 _ATL_BASE_MODULE;
|
||||
|
||||
class CAtlBaseModule : public _ATL_BASE_MODULE
|
||||
{
|
||||
public :
|
||||
static bool m_bInitFailed;
|
||||
CAtlBaseModule() throw();
|
||||
~CAtlBaseModule() throw ();
|
||||
|
||||
HINSTANCE GetModuleInstance() throw()
|
||||
{
|
||||
return m_hInst;
|
||||
}
|
||||
HINSTANCE GetResourceInstance() throw()
|
||||
{
|
||||
return m_hInstResource;
|
||||
}
|
||||
HINSTANCE SetResourceInstance(HINSTANCE hInst) throw()
|
||||
{
|
||||
return static_cast< HINSTANCE >(InterlockedExchangePointer((void**)&m_hInstResource, hInst));
|
||||
}
|
||||
|
||||
bool AddResourceInstance(HINSTANCE hInst) throw();
|
||||
bool RemoveResourceInstance(HINSTANCE hInst) throw();
|
||||
HINSTANCE GetHInstanceAt(int i) throw();
|
||||
};
|
||||
|
||||
__declspec(selectany) bool CAtlBaseModule::m_bInitFailed = false;
|
||||
extern CAtlBaseModule _AtlBaseModule;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// String resource helpers
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4200)
|
||||
struct ATLSTRINGRESOURCEIMAGE
|
||||
{
|
||||
WORD nLength;
|
||||
__field_ecount(nLength) WCHAR achString[];
|
||||
};
|
||||
#pragma warning(pop) // C4200
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* _AtlGetStringResourceImage( HINSTANCE hInstance, HRSRC hResource, UINT id ) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* pImage;
|
||||
const ATLSTRINGRESOURCEIMAGE* pImageEnd;
|
||||
ULONG nResourceSize;
|
||||
HGLOBAL hGlobal;
|
||||
UINT iIndex;
|
||||
|
||||
hGlobal = ::LoadResource( hInstance, hResource );
|
||||
if( hGlobal == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
pImage = (const ATLSTRINGRESOURCEIMAGE*)::LockResource( hGlobal );
|
||||
if( pImage == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
nResourceSize = ::SizeofResource( hInstance, hResource );
|
||||
pImageEnd = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+nResourceSize);
|
||||
iIndex = id&0x000f;
|
||||
|
||||
while( (iIndex > 0) && (pImage < pImageEnd) )
|
||||
{
|
||||
pImage = (const ATLSTRINGRESOURCEIMAGE*)(LPBYTE( pImage )+(sizeof( ATLSTRINGRESOURCEIMAGE )+(pImage->nLength*sizeof( WCHAR ))));
|
||||
iIndex--;
|
||||
}
|
||||
if( pImage >= pImageEnd )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
if( pImage->nLength == 0 )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return( pImage );
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage( HINSTANCE hInstance, UINT id ) throw()
|
||||
{
|
||||
HRSRC hResource;
|
||||
|
||||
hResource = ::FindResource( hInstance, MAKEINTRESOURCE( ((id>>4)+1) ), RT_STRING );
|
||||
if( hResource == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return _AtlGetStringResourceImage( hInstance, hResource, id );
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage( HINSTANCE hInstance, UINT id, WORD wLanguage ) throw()
|
||||
{
|
||||
HRSRC hResource;
|
||||
|
||||
hResource = ::FindResourceEx( hInstance, RT_STRING, MAKEINTRESOURCE( ((id>>4)+1) ), wLanguage );
|
||||
if( hResource == NULL )
|
||||
{
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
return _AtlGetStringResourceImage( hInstance, hResource, id );
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage( UINT id ) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, id);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline const ATLSTRINGRESOURCEIMAGE* AtlGetStringResourceImage( UINT id, WORD wLanguage ) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, id, wLanguage);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
inline int AtlLoadString(__in UINT nID, __out_ecount_part_z(nBufferMax, return + 1) LPTSTR lpBuffer, __in int nBufferMax) throw()
|
||||
{
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
int nRet = 0;
|
||||
|
||||
for (int i = 1; hInst != NULL && nRet == 0; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
nRet = LoadString(hInst, nID, lpBuffer, nBufferMax);
|
||||
}
|
||||
return nRet;
|
||||
}
|
||||
|
||||
inline HINSTANCE AtlFindResourceInstance(LPCTSTR lpName, LPCTSTR lpType, WORD wLanguage = 0) throw()
|
||||
{
|
||||
ATLASSERT(lpType != RT_STRING); // Call AtlFindStringResourceInstance to find the string
|
||||
if (lpType == RT_STRING)
|
||||
return NULL;
|
||||
|
||||
if (ATL_IS_INTRESOURCE(lpType))
|
||||
{
|
||||
/* Prefast false warnings caused by bad-shaped definition of MAKEINTRESOURCE macro from PSDK */
|
||||
if (lpType == ATL_RT_ICON)
|
||||
{
|
||||
lpType = ATL_RT_GROUP_ICON;
|
||||
}
|
||||
else if (lpType == ATL_RT_CURSOR)
|
||||
{
|
||||
lpType = ATL_RT_GROUP_CURSOR;
|
||||
}
|
||||
}
|
||||
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
HRSRC hResource = NULL;
|
||||
|
||||
for (int i = 1; hInst != NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
hResource = ::FindResourceEx(hInst, lpType, lpName, wLanguage);
|
||||
if (hResource != NULL)
|
||||
{
|
||||
return hInst;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline HINSTANCE AtlFindResourceInstance(UINT nID, LPCTSTR lpType, WORD wLanguage = 0) throw()
|
||||
{
|
||||
return AtlFindResourceInstance(MAKEINTRESOURCE(nID), lpType, wLanguage);
|
||||
}
|
||||
|
||||
inline HINSTANCE AtlFindStringResourceInstance(UINT nID, WORD wLanguage = 0) throw()
|
||||
{
|
||||
const ATLSTRINGRESOURCEIMAGE* p = NULL;
|
||||
HINSTANCE hInst = _AtlBaseModule.GetHInstanceAt(0);
|
||||
|
||||
for (int i = 1; hInst != NULL && p == NULL; hInst = _AtlBaseModule.GetHInstanceAt(i++))
|
||||
{
|
||||
p = AtlGetStringResourceImage(hInst, nID, wLanguage);
|
||||
if (p != NULL)
|
||||
return hInst;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
Needed by both atlcomcli and atlsafe, so needs to be in here
|
||||
*/
|
||||
inline HRESULT AtlSafeArrayGetActualVartype
|
||||
(
|
||||
SAFEARRAY *psaArray,
|
||||
VARTYPE *pvtType
|
||||
)
|
||||
{
|
||||
HRESULT hrSystem=::SafeArrayGetVartype(psaArray, pvtType);
|
||||
|
||||
if(FAILED(hrSystem))
|
||||
{
|
||||
return hrSystem;
|
||||
}
|
||||
|
||||
/*
|
||||
When Windows has a SAFEARRAY of type VT_DISPATCH with FADF_HAVEIID,
|
||||
it returns VT_UNKNOWN instead of VT_DISPATCH. We patch the value to be correct
|
||||
*/
|
||||
if(pvtType && *pvtType==VT_UNKNOWN)
|
||||
{
|
||||
if(psaArray && ((psaArray->fFeatures & FADF_HAVEIID)!=0))
|
||||
{
|
||||
if(psaArray->fFeatures & FADF_DISPATCH)
|
||||
{
|
||||
*pvtType=VT_DISPATCH;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return hrSystem;
|
||||
}
|
||||
template <typename _CharType>
|
||||
inline _CharType* AtlCharNext(const _CharType* p) throw()
|
||||
{
|
||||
ATLASSUME(p != NULL); // Too expensive to check separately here
|
||||
if (*p == '\0') // ::CharNextA won't increment if we're at a \0 already
|
||||
return const_cast<_CharType*>(p+1);
|
||||
else
|
||||
return ::CharNextA(p);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline wchar_t* AtlCharNext<wchar_t>(const wchar_t* p) throw()
|
||||
{
|
||||
return const_cast< wchar_t* >( p+1 );
|
||||
}
|
||||
template<typename CharType>
|
||||
inline const CharType* AtlstrchrT(const CharType* p, CharType ch) throw()
|
||||
{
|
||||
ATLASSERT(p != NULL);
|
||||
if(p==NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
while( *p != 0 )
|
||||
{
|
||||
if (*p == ch)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
p = AtlCharNext(p);
|
||||
}
|
||||
//strchr for '\0' should succeed - the while loop terminates
|
||||
//*p == 0, but ch also == 0, so NULL terminator address is returned
|
||||
return (*p == ch) ? p : NULL;
|
||||
}
|
||||
//Ansi and Unicode versions of printf, used with templated CharType trait classes.
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
template<typename CharType>
|
||||
inline int AtlprintfT(const CharType* pszFormat,... ) throw()
|
||||
{
|
||||
int retval=0;
|
||||
va_list argList;
|
||||
va_start( argList, pszFormat );
|
||||
retval=vprintf(pszFormat,argList);
|
||||
va_end( argList );
|
||||
return retval;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
template<>
|
||||
inline int AtlprintfT(const wchar_t* pszFormat,... ) throw()
|
||||
{
|
||||
int retval=0;
|
||||
va_list argList;
|
||||
va_start( argList, pszFormat );
|
||||
retval=vwprintf(pszFormat, argList);
|
||||
va_end( argList );
|
||||
return retval;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4068 28110)
|
||||
|
||||
inline BOOL AtlConvertSystemTimeToVariantTime(const SYSTEMTIME& systimeSrc,double* pVarDtTm)
|
||||
{
|
||||
ATLENSURE(pVarDtTm!=NULL);
|
||||
//Convert using ::SystemTimeToVariantTime and store the result in pVarDtTm then
|
||||
//convert variant time back to system time and compare to original system time.
|
||||
|
||||
BOOL ok = ::SystemTimeToVariantTime(const_cast<SYSTEMTIME*>(&systimeSrc), pVarDtTm);
|
||||
|
||||
SYSTEMTIME sysTime;
|
||||
::ZeroMemory(&sysTime, sizeof(SYSTEMTIME));
|
||||
|
||||
ok = ok && ::VariantTimeToSystemTime(*pVarDtTm, &sysTime);
|
||||
ok = ok && (systimeSrc.wYear == sysTime.wYear &&
|
||||
systimeSrc.wMonth == sysTime.wMonth &&
|
||||
systimeSrc.wDay == sysTime.wDay &&
|
||||
systimeSrc.wHour == sysTime.wHour &&
|
||||
systimeSrc.wMinute == sysTime.wMinute &&
|
||||
systimeSrc.wSecond == sysTime.wSecond);
|
||||
|
||||
return ok;
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace ATL
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef _ATL_ALL_WARNINGS
|
||||
#pragma warning( pop )
|
||||
#endif
|
||||
|
||||
#endif // __ATLCORE_H__
|
||||
|
||||
668
cpp/jacob/include/atldef.h
Normal file
668
cpp/jacob/include/atldef.h
Normal file
@@ -0,0 +1,668 @@
|
||||
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#ifndef __ATLDEF_H__
|
||||
#define __ATLDEF_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#pragma warning(disable : 4619) // there is no warning number
|
||||
|
||||
#include <atlrc.h>
|
||||
#include <errno.h>
|
||||
#include <sal.h>
|
||||
|
||||
#ifndef RC_INVOKED
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error ATL requires C++ compilation (use a .cpp suffix)
|
||||
#endif
|
||||
|
||||
#ifdef UNDER_CE
|
||||
#error This version of ATL is not currently supported for CE. Look for the CE specific version.
|
||||
#endif
|
||||
|
||||
// If you are mixing compilation units that are built as
|
||||
// native code with those that are built /clr, you must define
|
||||
// the symbol '_ATL_MIXED'. _ATL_MIXED must be defined for all
|
||||
// compilation units in an executable or it must be defined for none of them.
|
||||
#if !defined(_ATL_MIXED)
|
||||
namespace Inconsistent_definition_of_symbol__ATL_MIXED
|
||||
{
|
||||
struct _Please_define_it_the_same_throughout_your_project { };
|
||||
}
|
||||
#else
|
||||
namespace Inconsistent_definition_of_symbol__ATL_MIXED
|
||||
{
|
||||
#ifdef _M_IX86
|
||||
#pragma comment(linker, "/include:??3@YAXPAX@Z")
|
||||
#else
|
||||
#pragma comment(linker, "/include:??3@YAXPEAX@Z")
|
||||
#endif
|
||||
struct _Please_define_it_the_same_throughout_your_project { virtual void one(){} };
|
||||
}
|
||||
#endif
|
||||
namespace Inconsistent_definition_of_symbol__ATL_MIXED
|
||||
{
|
||||
__declspec(selectany) _Please_define_it_the_same_throughout_your_project clash = _Please_define_it_the_same_throughout_your_project ();
|
||||
}
|
||||
|
||||
#if !defined(_ATL_MIXED)
|
||||
namespace Define_the_symbol__ATL_MIXED
|
||||
{
|
||||
#if defined(_M_CEE)
|
||||
struct Thank_you { };
|
||||
#else
|
||||
#ifdef _M_IX86
|
||||
#pragma comment(linker, "/include:??3@YAXPAX@Z")
|
||||
#else
|
||||
#pragma comment(linker, "/include:??3@YAXPEAX@Z")
|
||||
#endif
|
||||
struct Thank_you { virtual void one(){} };
|
||||
#endif
|
||||
__declspec(selectany) Thank_you clash = Thank_you();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(_ATL_MIXED)
|
||||
#define _ATL_NATIVE_INITIALIZATION
|
||||
#endif
|
||||
|
||||
#if !defined(_M_CEE)
|
||||
#define _ATL_NATIVE_INITIALIZATION
|
||||
#endif
|
||||
|
||||
#ifdef _UNICODE
|
||||
#ifndef UNICODE
|
||||
#define UNICODE // UNICODE is used by Windows headers
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef UNICODE
|
||||
#ifndef _UNICODE
|
||||
#define _UNICODE // _UNICODE is used by C-runtime/MFC headers
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifndef DEBUG
|
||||
#define DEBUG
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
#define _ATL_SUPPORT_VT_I8 // Always support VT_I8 on Win64.
|
||||
#endif
|
||||
|
||||
#if !defined(UNALIGNED)
|
||||
#if defined(_M_IA64) || defined(_M_AMD64)
|
||||
#define UNALIGNED __unaligned
|
||||
#else
|
||||
#define UNALIGNED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(_countof)
|
||||
#if !defined(__cplusplus)
|
||||
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
|
||||
#else
|
||||
extern "C++"
|
||||
{
|
||||
template <typename _CountofType, size_t _SizeOfArray>
|
||||
char (*__countof_helper(UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
|
||||
#define _countof(_Array) sizeof(*__countof_helper(_Array))
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef AtlThrow
|
||||
#ifndef _ATL_CUSTOM_THROW
|
||||
#define AtlThrow ATL::AtlThrowImpl
|
||||
#endif
|
||||
#endif // AtlThrow
|
||||
|
||||
#ifndef ATLASSERT
|
||||
#define ATLASSERT(expr) _ASSERTE(expr)
|
||||
#endif // ATLASSERT
|
||||
|
||||
/*
|
||||
Why does ATLASSUME exist?
|
||||
|
||||
ATL 8 has two existing validation models
|
||||
|
||||
ATLASSERT/ATLVERIFY - These are used to make sure a debug build reports a problem with the expression/invariant
|
||||
ATLENSURE - Debug is the same as ATLVERIFY, retail throws a C++ exception
|
||||
|
||||
We added ATLENSURE because there were too many unreported error paths in ATL and we wanted to bail out of more
|
||||
error conditions rather than just trying to continue in retail.
|
||||
|
||||
There might be a case for changing 'lots' of ATLASSERT to ATLENSURE, but we chose an incremental approach and only
|
||||
changed over where we saw a problem with code reported from a customer or test case. This reduces code churn in our
|
||||
code for this version.
|
||||
|
||||
In general, our approach is to try to make sure that when something goes wrong
|
||||
- the client does not continue to run, because we report an error condition
|
||||
- debug builds see an assertion about the problem
|
||||
|
||||
Sometimes we have code like
|
||||
|
||||
HRESULT ComMethod(void)
|
||||
{
|
||||
ATLASSUME(m_pFoo);
|
||||
return m_pFoo->Method();
|
||||
}
|
||||
|
||||
We could add
|
||||
if(!m_pFoo) return E_POINTER;
|
||||
|
||||
But this is very unlikely to help, since it removes the ability of the developer to debug this problem if it's seen in a retail
|
||||
build of the application.
|
||||
|
||||
We could try something more severe
|
||||
|
||||
if(!m_pFoo) terminate(); // or your favourite shutdown function
|
||||
|
||||
This would ensure good reporting (because VC8 terminate generates a Windows Error Report and crash dump), but hardly seems a big win
|
||||
over the previous crash.
|
||||
|
||||
ATLENSURE might seem slightly better. It is debuggable and consistent with ATL in general. In fact, many parts of ATL do just this.
|
||||
But in this specific context, it doesn't look like a great choice. COM methods should not in general be emitting native C++ exceptions
|
||||
as an error reporting strategy.
|
||||
|
||||
So we find ourselves in a quandry. For these kinds of methods, the traditional code (ATLASSERT followed by a crash), seems be the most
|
||||
debuggable thing to do in this situation. At least for VS8, we have decided to stick with this shape.
|
||||
|
||||
---
|
||||
|
||||
Now consider the impact of cl /analyze. We want cl /analyze to not warn about our potential dereferences when they refer to member variables
|
||||
whose state was previously validated by another method. But we do want to see the impact of function contracts on the parameters of the
|
||||
function.
|
||||
|
||||
So we've done a broad replace of all the member-related ATLASSERT to ATLASSUME.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef ATLASSUME
|
||||
#define ATLASSUME(expr) do { ATLASSERT(expr); __analysis_assume(!!(expr)); } while(0)
|
||||
#endif // ATLASSERT
|
||||
|
||||
#ifndef ATLVERIFY
|
||||
#ifdef _DEBUG
|
||||
#define ATLVERIFY(expr) ATLASSERT(expr)
|
||||
#else
|
||||
#define ATLVERIFY(expr) (expr)
|
||||
#endif // DEBUG
|
||||
#endif // ATLVERIFY
|
||||
|
||||
#ifndef ATLENSURE_THROW
|
||||
#define ATLENSURE_THROW(expr, hr) \
|
||||
do { \
|
||||
int __atl_condVal=!!(expr); \
|
||||
ATLASSERT(__atl_condVal); \
|
||||
if(!(__atl_condVal)) AtlThrow(hr); \
|
||||
} while (0)
|
||||
#endif // ATLENSURE
|
||||
|
||||
#ifndef ATLENSURE
|
||||
#define ATLENSURE(expr) ATLENSURE_THROW(expr, E_FAIL)
|
||||
#endif // ATLENSURE
|
||||
|
||||
#ifndef ATLENSURE_SUCCEEDED
|
||||
#define ATLENSURE_SUCCEEDED(hr) ATLENSURE_THROW(SUCCEEDED(hr), hr)
|
||||
#endif // ATLENSURE
|
||||
|
||||
/* Used inside COM methods that do not want to throw */
|
||||
#ifndef ATLENSURE_RETURN_HR
|
||||
#define ATLENSURE_RETURN_HR(expr, hr) \
|
||||
do { \
|
||||
int __atl_condVal=!!(expr); \
|
||||
ATLASSERT(__atl_condVal); \
|
||||
if(!(__atl_condVal)) return hr; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/* Used inside COM methods that do not want to throw */
|
||||
#ifndef ATLENSURE_RETURN
|
||||
#define ATLENSURE_RETURN(expr) ATLENSURE_RETURN_HR(expr, E_FAIL)
|
||||
#endif
|
||||
|
||||
/* generic version that returns 2nd expr if 1st is false; no implication of HRESULT */
|
||||
#ifndef ATLENSURE_RETURN_VAL
|
||||
#define ATLENSURE_RETURN_VAL ATLENSURE_RETURN_HR
|
||||
#endif
|
||||
|
||||
#if defined(_SECURE_ATL)
|
||||
#error Do not define _SECURE_ATL.
|
||||
#undef _SECURE_ATL
|
||||
#endif
|
||||
#define _SECURE_ATL 1
|
||||
|
||||
#if _SECURE_ATL
|
||||
|
||||
#ifndef ATL_CRT_ERRORCHECK
|
||||
#define ATL_CRT_ERRORCHECK(expr) AtlCrtErrorCheck(expr)
|
||||
#endif // ATL_CRT_ERRORCHECK
|
||||
|
||||
#ifndef ATL_CRT_ERRORCHECK_SPRINTF
|
||||
#define ATL_CRT_ERRORCHECK_SPRINTF(expr) \
|
||||
do { \
|
||||
errno_t _saveErrno = errno; \
|
||||
errno = 0; \
|
||||
(expr); \
|
||||
if(0 != errno) \
|
||||
{ \
|
||||
AtlCrtErrorCheck(errno); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
errno = _saveErrno; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif // ATL_CRT_ERRORCHECK_SPRINTF
|
||||
|
||||
#else // !_SECURE_ATL
|
||||
|
||||
#define ATL_CRT_ERRORCHECK(expr) do { expr; } while (0)
|
||||
#define ATL_CRT_ERRORCHECK_SPRINTF(expr) do { expr; } while (0)
|
||||
|
||||
#endif // _SECURE_ATL
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// __declspec(novtable) is used on a class declaration to prevent the vtable
|
||||
// pointer from being initialized in the constructor and destructor for the
|
||||
// class. This has many benefits because the linker can now eliminate the
|
||||
// vtable and all the functions pointed to by the vtable. Also, the actual
|
||||
// constructor and destructor code are now smaller.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// This should only be used on a class that is not directly createable but is
|
||||
// rather only used as a base class. Additionally, the constructor and
|
||||
// destructor (if provided by the user) should not call anything that may cause
|
||||
// a virtual function call to occur back on the object.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// By default, the wizards will generate new ATL object classes with this
|
||||
// attribute (through the ATL_NO_VTABLE macro). This is normally safe as long
|
||||
// the restriction mentioned above is followed. It is always safe to remove
|
||||
// this macro from your class, so if in doubt, remove it.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef _ATL_DISABLE_NO_VTABLE
|
||||
#define ATL_NO_VTABLE
|
||||
#else
|
||||
#define ATL_NO_VTABLE __declspec(novtable)
|
||||
#endif
|
||||
|
||||
#ifdef _ATL_DISABLE_NOTHROW
|
||||
#define ATL_NOTHROW
|
||||
#else
|
||||
#define ATL_NOTHROW __declspec(nothrow)
|
||||
#endif
|
||||
|
||||
#ifdef _ATL_DISABLE_FORCEINLINE
|
||||
#define ATL_FORCEINLINE
|
||||
#else
|
||||
#define ATL_FORCEINLINE __forceinline
|
||||
#endif
|
||||
|
||||
#ifdef _ATL_DISABLE_NOINLINE
|
||||
#define ATL_NOINLINE
|
||||
#else
|
||||
#define ATL_NOINLINE __declspec( noinline )
|
||||
#endif
|
||||
|
||||
#if defined(_ATL_DISABLE_DEPRECATED) || (defined(_PREFAST_) && (_MSC_VER < 1400))
|
||||
#define ATL_DEPRECATED(_Message)
|
||||
#else
|
||||
#define ATL_DEPRECATED(_Message) __declspec( deprecated(_Message) )
|
||||
#endif
|
||||
|
||||
// If ATL80.DLL is being used then _ATL_STATIC_REGISTRY doesn't really make sense
|
||||
#ifdef _ATL_DLL
|
||||
#undef _ATL_STATIC_REGISTRY
|
||||
#else
|
||||
// If not linking to ATL80.DLL, use the static registrar and not building atl.dll
|
||||
#ifndef _ATL_DLL_IMPL
|
||||
#ifndef _ATL_STATIC_REGISTRY
|
||||
#define _ATL_STATIC_REGISTRY
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _ATL_DEBUG_REFCOUNT
|
||||
#ifndef _ATL_DEBUG_INTERFACES
|
||||
#define _ATL_DEBUG_INTERFACES
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#ifndef _ATL_DEBUG
|
||||
#define _ATL_DEBUG
|
||||
#endif // _ATL_DEBUG
|
||||
#endif // _DEBUG
|
||||
|
||||
#ifdef _ATL_DEBUG_INTERFACES
|
||||
#ifndef _ATL_DEBUG
|
||||
#define _ATL_DEBUG
|
||||
#endif // _ATL_DEBUG
|
||||
#endif // _ATL_DEBUG_INTERFACES
|
||||
|
||||
#ifndef _ATL_HEAPFLAGS
|
||||
#ifdef _MALLOC_ZEROINIT
|
||||
#define _ATL_HEAPFLAGS HEAP_ZERO_MEMORY
|
||||
#else
|
||||
#define _ATL_HEAPFLAGS 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _ATL_PACKING
|
||||
#define _ATL_PACKING 8
|
||||
#endif
|
||||
|
||||
#if defined(_ATL_DLL)
|
||||
#define ATLAPI extern "C" HRESULT __declspec(dllimport) __stdcall
|
||||
#define ATLAPI_(x) extern "C" __declspec(dllimport) x __stdcall
|
||||
#define ATLINLINE
|
||||
#define ATLAPIINL extern "C" inline HRESULT __stdcall
|
||||
#define ATLAPIINL_(x) extern "C" inline x __stdcall
|
||||
#elif defined(_ATL_DLL_IMPL)
|
||||
#define ATLAPI extern "C" inline HRESULT __stdcall
|
||||
#define ATLAPI_(x) extern "C" inline x __stdcall
|
||||
#define ATLAPIINL ATLAPI
|
||||
#define ATLAPIINL_(x) ATLAPI_(x)
|
||||
#define ATLINLINE
|
||||
#else
|
||||
#define ATLAPI __declspec(nothrow) HRESULT __stdcall
|
||||
#define ATLAPI_(x) __declspec(nothrow) x __stdcall
|
||||
#define ATLAPIINL ATLAPI
|
||||
#define ATLAPIINL_(x) ATLAPI_(x)
|
||||
#define ATLINLINE inline
|
||||
#endif
|
||||
|
||||
#ifdef _ATL_NO_EXCEPTIONS
|
||||
#ifdef _AFX
|
||||
#error MFC projects cannot define _ATL_NO_EXCEPTIONS
|
||||
#endif
|
||||
#else
|
||||
#ifndef _CPPUNWIND
|
||||
#define _ATL_NO_EXCEPTIONS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _CPPUNWIND
|
||||
|
||||
#ifndef ATLTRYALLOC
|
||||
|
||||
#ifdef _AFX
|
||||
#define ATLTRYALLOC(x) try{x;} catch(CException* e){e->Delete();}
|
||||
#else
|
||||
/* prefast noise VSW 489981 */
|
||||
#define ATLTRYALLOC(x) __pragma(warning(push)) __pragma(warning(disable: 4571)) try{x;} catch(...) {} __pragma(warning(pop))
|
||||
#endif //__AFX
|
||||
|
||||
#endif //ATLTRYALLOC
|
||||
|
||||
// If you define _ATLTRY before including this file, then
|
||||
// you should define _ATLCATCH and _ATLRETHROW as well.
|
||||
#ifndef _ATLTRY
|
||||
#define _ATLTRY try
|
||||
#ifdef _AFX
|
||||
#define _ATLCATCH( e ) catch( CException* e )
|
||||
#else
|
||||
#define _ATLCATCH( e ) catch( CAtlException e )
|
||||
#endif
|
||||
|
||||
#define _ATLCATCHALL() __pragma(warning(push)) __pragma(warning(disable: 4571)) catch( ... ) __pragma(warning(pop))
|
||||
|
||||
#ifdef _AFX
|
||||
#define _ATLDELETEEXCEPTION(e) e->Delete();
|
||||
#else
|
||||
#define _ATLDELETEEXCEPTION(e) e;
|
||||
#endif
|
||||
|
||||
#define _ATLRETHROW throw
|
||||
#endif // _ATLTRY
|
||||
|
||||
/*
|
||||
COM functions should not throw. Which means we should protect their callers from C++ exceptions leaking out. These macros
|
||||
can help with that, though they have not yet been applied to the whole of ATL, which uses a variety of patterns to achieve
|
||||
this end
|
||||
*/
|
||||
|
||||
#ifndef _ATL_COM_BEGIN
|
||||
#define _ATL_COM_BEGIN \
|
||||
HRESULT __hrAtlComMethod=S_OK; \
|
||||
try \
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef _AFX
|
||||
/* Nice to do something more complex here in future to translate an MFC exception to a better HR */
|
||||
#define _AFX_COM_END_PART \
|
||||
catch(CException *e) \
|
||||
{ \
|
||||
if(e) \
|
||||
{ \
|
||||
e->Delete(); \
|
||||
} \
|
||||
__hrAtlComMethod=E_FAIL; \
|
||||
}
|
||||
#else
|
||||
#define _AFX_COM_END_PART \
|
||||
catch(CAtlException e) \
|
||||
{ \
|
||||
__hrAtlComMethod=e.m_hr; \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _ATL_COM_END
|
||||
#define _ATL_COM_END \
|
||||
_AFX_COM_END_PART \
|
||||
catch(...) \
|
||||
{ \
|
||||
__hrAtlComMethod=E_FAIL; \
|
||||
} \
|
||||
return hr;
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#else //_CPPUNWIND
|
||||
|
||||
#ifndef ATLTRYALLOC
|
||||
#define ATLTRYALLOC(x) x;
|
||||
#endif //ATLTRYALLOC
|
||||
|
||||
// if _ATLTRY is defined before including this file then
|
||||
// _ATLCATCH and _ATLRETHROW should be defined as well.
|
||||
#ifndef _ATLTRY
|
||||
#define _ATLTRY
|
||||
#define _ATLCATCH( e ) __pragma(warning(push)) __pragma(warning(disable: 4127)) if( false ) __pragma(warning(pop))
|
||||
#define _ATLCATCHALL() __pragma(warning(push)) __pragma(warning(disable: 4127)) if( false ) __pragma(warning(pop))
|
||||
#define _ATLDELETEEXCEPTION(e)
|
||||
#define _ATLRETHROW
|
||||
#endif // _ATLTRY
|
||||
|
||||
#endif //_CPPUNWIND
|
||||
|
||||
#ifndef ATLTRY
|
||||
#define ATLTRY(x) ATLTRYALLOC(x)
|
||||
#endif //ATLTRY
|
||||
|
||||
#define offsetofclass(base, derived) ((DWORD_PTR)(static_cast<base*>((derived*)_ATL_PACKING))-_ATL_PACKING)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Master version numbers
|
||||
|
||||
#define _ATL 1 // Active Template Library
|
||||
#define _ATL_VER 0x0800 // Active Template Library version 8.00
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Threading
|
||||
|
||||
#ifndef _ATL_SINGLE_THREADED
|
||||
#ifndef _ATL_APARTMENT_THREADED
|
||||
#ifndef _ATL_FREE_THREADED
|
||||
#define _ATL_FREE_THREADED
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// UUIDOF
|
||||
#ifndef _ATL_NO_UUIDOF
|
||||
#define _ATL_IIDOF(x) __uuidof(x)
|
||||
#else
|
||||
#define _ATL_IIDOF(x) IID_##x
|
||||
#endif
|
||||
|
||||
// Lean and mean
|
||||
#ifndef ATL_NO_LEAN_AND_MEAN
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#ifndef NOMCX
|
||||
#define NOMCX
|
||||
#endif
|
||||
#endif // ATL_NO_LEAN_AND_MEAN
|
||||
|
||||
#ifdef NOSERVICE
|
||||
#ifndef _ATL_NO_SERVICE
|
||||
#define _ATL_NO_SERVICE
|
||||
#endif // _ATL_NO_SERVICE
|
||||
#else
|
||||
#ifdef _ATL_NO_SERVICE
|
||||
#ifndef NOSERVICE
|
||||
#define NOSERVICE
|
||||
#endif // NOSERVICE
|
||||
#endif // _ATL_NO_SERVICE
|
||||
#endif // NOSERVICE
|
||||
|
||||
#include <malloc.h>
|
||||
#ifdef _DEBUG
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
#ifndef _ATL_NO_DEBUG_CRT
|
||||
// Warning: if you define the above symbol, you will have
|
||||
// to provide your own definition of the ATLASSERT(x) macro
|
||||
// in order to compile ATL
|
||||
#include <crtdbg.h>
|
||||
#endif
|
||||
|
||||
#endif // RC_INVOKED
|
||||
|
||||
#define ATLAXWIN_CLASS "AtlAxWin80"
|
||||
#define ATLAXWINLIC_CLASS "AtlAxWinLic80"
|
||||
|
||||
// _ATL_INSECURE_DEPRECATE define
|
||||
#ifndef _ATL_INSECURE_DEPRECATE
|
||||
#if defined(_ATL_SECURE_NO_DEPRECATE) || (defined(_PREFAST_) && (_MSC_VER < 1400))
|
||||
#define _ATL_INSECURE_DEPRECATE(_Message)
|
||||
#else
|
||||
#define _ATL_INSECURE_DEPRECATE(_Message) __declspec(deprecated(_Message))
|
||||
#endif // _ATL_SECURE_NO_DEPRECATE
|
||||
#endif // _ATL_INSECURE_DEPRECATE
|
||||
|
||||
/*
|
||||
This is called when something really bad happens -- so bad
|
||||
that we consider it dangerous to even throw an exception
|
||||
*/
|
||||
#ifndef _ATL_FATAL_SHUTDOWN
|
||||
#define _ATL_FATAL_SHUTDOWN do { ::TerminateProcess(::GetCurrentProcess(), 0); } while(0);
|
||||
#endif
|
||||
|
||||
//ATL/MFC code should use standard pointer to member standard syntax &MyClass::MyMethod, instead
|
||||
//of the legacy non-standard syntax - MyMethod.
|
||||
#ifdef _ATL_ENABLE_PTM_WARNING
|
||||
#define PTM_WARNING_DISABLE
|
||||
#define PTM_WARNING_RESTORE
|
||||
#else
|
||||
#define PTM_WARNING_DISABLE \
|
||||
__pragma(warning( push )) \
|
||||
__pragma(warning( disable : 4867 ))
|
||||
#define PTM_WARNING_RESTORE \
|
||||
__pragma(warning( pop ))
|
||||
#endif //_ATL_ENABLE_PTM_WARNING
|
||||
|
||||
/* we have to define our own versions of MAKEINTRESOURCE and IS_INTRESOURCE to
|
||||
* fix warning 6268. At least until those macros are not cleanend in PSDK.
|
||||
Same comes true for those definitions of constants which use the above macros
|
||||
*/
|
||||
#define ATL_MAKEINTRESOURCEA(i) ((LPSTR)((ULONG_PTR)((WORD)(i))))
|
||||
#define ATL_MAKEINTRESOURCEW(i) ((LPWSTR)((ULONG_PTR)((WORD)(i))))
|
||||
#ifdef UNICODE
|
||||
#define ATL_MAKEINTRESOURCE ATL_MAKEINTRESOURCEW
|
||||
#else
|
||||
#define ATL_MAKEINTRESOURCE ATL_MAKEINTRESOURCEA
|
||||
#endif // !UNICODE
|
||||
#define ATL_IS_INTRESOURCE(_r) ((((ULONG_PTR)(_r)) >> 16) == 0)
|
||||
|
||||
/*
|
||||
* Predefined Resource Types
|
||||
*/
|
||||
#define ATL_RT_CURSOR ATL_MAKEINTRESOURCE(1)
|
||||
#define ATL_RT_BITMAP ATL_MAKEINTRESOURCE(2)
|
||||
#define ATL_RT_ICON ATL_MAKEINTRESOURCE(3)
|
||||
#define ATL_RT_MENU ATL_MAKEINTRESOURCE(4)
|
||||
#define ATL_RT_DIALOG ATL_MAKEINTRESOURCE(5)
|
||||
#define ATL_RT_STRING ATL_MAKEINTRESOURCE(6)
|
||||
#define ATL_RT_FONTDIR ATL_MAKEINTRESOURCE(7)
|
||||
#define ATL_RT_FONT ATL_MAKEINTRESOURCE(8)
|
||||
#define ATL_RT_ACCELERATOR ATL_MAKEINTRESOURCE(9)
|
||||
#define ATL_RT_RCDATA ATL_MAKEINTRESOURCE(10)
|
||||
#define ATL_RT_MESSAGETABLE ATL_MAKEINTRESOURCE(11)
|
||||
|
||||
#define ATL_DIFFERENCE 11
|
||||
#define ATL_RT_GROUP_CURSOR ATL_MAKEINTRESOURCE((ULONG_PTR)ATL_RT_CURSOR + ATL_DIFFERENCE)
|
||||
#define ATL_RT_GROUP_ICON ATL_MAKEINTRESOURCE((ULONG_PTR)ATL_RT_ICON + ATL_DIFFERENCE)
|
||||
#define ATL_RT_VERSION ATL_MAKEINTRESOURCE(16)
|
||||
#define ATL_RT_DLGINCLUDE ATL_MAKEINTRESOURCE(17)
|
||||
#if(WINVER >= 0x0400)
|
||||
#define ATL_RT_PLUGPLAY ATL_MAKEINTRESOURCE(19)
|
||||
#define ATL_RT_VXD ATL_MAKEINTRESOURCE(20)
|
||||
#define ATL_RT_ANICURSOR ATL_MAKEINTRESOURCE(21)
|
||||
#define ATL_RT_ANIICON ATL_MAKEINTRESOURCE(22)
|
||||
#endif /* WINVER >= 0x0400 */
|
||||
#define ATL_RT_HTML ATL_MAKEINTRESOURCE(23)
|
||||
#ifdef RC_INVOKED
|
||||
#define ATL_RT_MANIFEST 24
|
||||
#define ATL_CREATEPROCESS_MANIFEST_RESOURCE_ID 1
|
||||
#define ATL_ISOLATIONAWARE_MANIFEST_RESOURCE_ID 2
|
||||
#define ATL_ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID 3
|
||||
#define ATL_MINIMUM_RESERVED_MANIFEST_RESOURCE_ID 1 /* inclusive */
|
||||
#define ATL_MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID 16 /* inclusive */
|
||||
#else /* RC_INVOKED */
|
||||
#define ATL_RT_MANIFEST ATL_MAKEINTRESOURCE(24)
|
||||
#define ATL_CREATEPROCESS_MANIFEST_RESOURCE_ID ATL_MAKEINTRESOURCE( 1)
|
||||
#define ATL_ISOLATIONAWARE_MANIFEST_RESOURCE_ID ATL_MAKEINTRESOURCE(2)
|
||||
#define ATL_ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID ATL_MAKEINTRESOURCE(3)
|
||||
#define ATL_MINIMUM_RESERVED_MANIFEST_RESOURCE_ID ATL_MAKEINTRESOURCE( 1 /*inclusive*/)
|
||||
#define ATL_MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID ATL_MAKEINTRESOURCE(16 /*inclusive*/)
|
||||
#endif /* RC_INVOKED */
|
||||
|
||||
/* sal.h stuff that is not in the current LKG */
|
||||
#ifndef __out_ecount_part_z
|
||||
#define __out_ecount_part_z(size,length) __out_ecount_part(size,length) __post __nullterminated
|
||||
#endif
|
||||
|
||||
#ifndef __out_ecount_part_z_opt
|
||||
#define __out_ecount_part_z_opt(size,length) __out_ecount_part_opt(size,length) __post __nullterminated
|
||||
#endif
|
||||
|
||||
#ifndef __deref_opt_out_z
|
||||
#define __deref_opt_out_z __deref_opt_out __post __deref __nullterminated
|
||||
#endif
|
||||
|
||||
#ifndef __out_bcount_part_z
|
||||
#define __out_bcount_part_z(size,length) __out_bcount_part(size,length) __post __nullterminated
|
||||
#endif
|
||||
|
||||
#endif // __ATLDEF_H__
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
123
cpp/jacob/include/atlexcept.h
Normal file
123
cpp/jacob/include/atlexcept.h
Normal file
@@ -0,0 +1,123 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#ifndef __ATLEXCEPT_H__
|
||||
#define __ATLEXCEPT_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atldef.h>
|
||||
#include <atltrace.h>
|
||||
|
||||
|
||||
#pragma pack(push,_ATL_PACKING)
|
||||
namespace ATL
|
||||
{
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Exception raise (for functions that cannot return an error code)
|
||||
|
||||
inline void __declspec(noreturn) _AtlRaiseException( DWORD dwExceptionCode, DWORD dwExceptionFlags = EXCEPTION_NONCONTINUABLE )
|
||||
{
|
||||
RaiseException( dwExceptionCode, dwExceptionFlags, 0, NULL );
|
||||
}
|
||||
|
||||
class CAtlException
|
||||
{
|
||||
public:
|
||||
CAtlException() throw() :
|
||||
m_hr( E_FAIL )
|
||||
{
|
||||
}
|
||||
|
||||
CAtlException( HRESULT hr ) throw() :
|
||||
m_hr( hr )
|
||||
{
|
||||
}
|
||||
|
||||
operator HRESULT() const throw()
|
||||
{
|
||||
return( m_hr );
|
||||
}
|
||||
|
||||
public:
|
||||
HRESULT m_hr;
|
||||
};
|
||||
|
||||
#ifndef _ATL_NO_EXCEPTIONS
|
||||
|
||||
// Throw a CAtlException with the given HRESULT
|
||||
#if defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow to throw a custom exception.
|
||||
#ifdef _AFX
|
||||
#error MFC projects must use default implementation of AtlThrow()
|
||||
#endif
|
||||
#else
|
||||
ATL_NOINLINE __declspec(noreturn) inline void WINAPI AtlThrowImpl( HRESULT hr )
|
||||
{
|
||||
ATLTRACE(atlTraceException, 0, _T("AtlThrow: hr = 0x%x\n"), hr );
|
||||
#ifdef _AFX
|
||||
if( hr == E_OUTOFMEMORY )
|
||||
{
|
||||
AfxThrowMemoryException();
|
||||
}
|
||||
else
|
||||
{
|
||||
AfxThrowOleException( hr );
|
||||
}
|
||||
#else
|
||||
throw CAtlException( hr );
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
// Throw a CAtlException corresponding to the result of ::GetLastError
|
||||
ATL_NOINLINE __declspec(noreturn) inline void WINAPI AtlThrowLastWin32()
|
||||
{
|
||||
DWORD dwError = ::GetLastError();
|
||||
AtlThrow( HRESULT_FROM_WIN32( dwError ) );
|
||||
}
|
||||
|
||||
#else // no exception handling
|
||||
|
||||
// Throw a CAtlException with the given HRESULT
|
||||
#if !defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow
|
||||
|
||||
ATL_NOINLINE inline void WINAPI AtlThrowImpl( HRESULT hr )
|
||||
{
|
||||
ATLTRACE(atlTraceException, 0, _T("AtlThrow: hr = 0x%x\n"), hr );
|
||||
ATLASSERT( false );
|
||||
DWORD dwExceptionCode;
|
||||
switch(hr)
|
||||
{
|
||||
case E_OUTOFMEMORY:
|
||||
dwExceptionCode = DWORD(STATUS_NO_MEMORY);
|
||||
break;
|
||||
default:
|
||||
dwExceptionCode = DWORD(EXCEPTION_ILLEGAL_INSTRUCTION);
|
||||
break;
|
||||
}
|
||||
_AtlRaiseException(dwExceptionCode);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Throw a CAtlException corresponding to the result of ::GetLastError
|
||||
ATL_NOINLINE inline void WINAPI AtlThrowLastWin32()
|
||||
{
|
||||
DWORD dwError = ::GetLastError();
|
||||
AtlThrow( HRESULT_FROM_WIN32( dwError ) );
|
||||
}
|
||||
|
||||
#endif // no exception handling
|
||||
|
||||
}; // namespace ATL
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif // __ATLEXCEPT_H__
|
||||
|
||||
2956
cpp/jacob/include/atliface.h
Normal file
2956
cpp/jacob/include/atliface.h
Normal file
File diff suppressed because it is too large
Load Diff
28
cpp/jacob/include/atlrc.h
Normal file
28
cpp/jacob/include/atlrc.h
Normal file
@@ -0,0 +1,28 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __ATLRC_H__
|
||||
|
||||
#define ATL_RESID_BASE 0xD800
|
||||
#define ATL_STRING_BASE ATL_RESID_BASE
|
||||
|
||||
#define ATL_IDS_DATETIME_INVALID (ATL_STRING_BASE + 0)
|
||||
#define ATL_IDS_DATETIMESPAN_INVALID (ATL_STRING_BASE + 1)
|
||||
|
||||
#define ATL_SERVICE_MANAGER_OPEN_ERROR (ATL_STRING_BASE + 10)
|
||||
#define ATL_SERVICE_START_ERROR (ATL_STRING_BASE + 11)
|
||||
#define ATL_SERVICE_OPEN_ERROR (ATL_STRING_BASE + 12)
|
||||
#define ATL_SERVICE_DELETE_ERROR (ATL_STRING_BASE + 13)
|
||||
#define ATL_SERVICE_STOP_ERROR (ATL_STRING_BASE + 14)
|
||||
|
||||
#endif // __ATLRC_H__
|
||||
|
||||
489
cpp/jacob/include/atlsimpcoll.h
Normal file
489
cpp/jacob/include/atlsimpcoll.h
Normal file
@@ -0,0 +1,489 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#ifndef __ATLSIMPCOLL_H__
|
||||
#define __ATLSIMPCOLL_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atldef.h>
|
||||
#include <atlchecked.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#pragma push_macro("malloc")
|
||||
#undef malloc
|
||||
#pragma push_macro("calloc")
|
||||
#undef calloc
|
||||
#pragma push_macro("realloc")
|
||||
#undef realloc
|
||||
#pragma push_macro("_recalloc")
|
||||
#undef _recalloc
|
||||
#pragma push_macro("free")
|
||||
#undef free
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable: 4800) // forcing 'int' value to bool
|
||||
|
||||
|
||||
#pragma pack(push,_ATL_PACKING)
|
||||
namespace ATL
|
||||
{
|
||||
|
||||
#pragma push_macro("new")
|
||||
#undef new
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Collection helpers - CSimpleArray & CSimpleMap
|
||||
|
||||
// template class helpers with functions for comparing elements
|
||||
// override if using complex types without operator==
|
||||
template <class T>
|
||||
class CSimpleArrayEqualHelper
|
||||
{
|
||||
public:
|
||||
static bool IsEqual(const T& t1, const T& t2)
|
||||
{
|
||||
return (t1 == t2);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class CSimpleArrayEqualHelperFalse
|
||||
{
|
||||
public:
|
||||
static bool IsEqual(const T&, const T&)
|
||||
{
|
||||
ATLASSERT(false);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class TKey, class TVal>
|
||||
class CSimpleMapEqualHelper
|
||||
{
|
||||
public:
|
||||
static bool IsEqualKey(const TKey& k1, const TKey& k2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TKey>::IsEqual(k1, k2);
|
||||
}
|
||||
|
||||
static bool IsEqualValue(const TVal& v1, const TVal& v2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TVal>::IsEqual(v1, v2);
|
||||
}
|
||||
};
|
||||
|
||||
template <class TKey, class TVal>
|
||||
class CSimpleMapEqualHelperFalse
|
||||
{
|
||||
public:
|
||||
static bool IsEqualKey(const TKey& k1, const TKey& k2)
|
||||
{
|
||||
return CSimpleArrayEqualHelper<TKey>::IsEqual(k1, k2);
|
||||
}
|
||||
|
||||
static bool IsEqualValue(const TVal&, const TVal&)
|
||||
{
|
||||
ATLASSERT(FALSE);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class TEqual = CSimpleArrayEqualHelper< T > >
|
||||
class CSimpleArray
|
||||
{
|
||||
public:
|
||||
// Construction/destruction
|
||||
CSimpleArray() : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
|
||||
{ }
|
||||
|
||||
~CSimpleArray();
|
||||
|
||||
CSimpleArray(const CSimpleArray< T, TEqual >& src) : m_aT(NULL), m_nSize(0), m_nAllocSize(0)
|
||||
{
|
||||
if (src.GetSize())
|
||||
{
|
||||
m_aT = (T*)calloc(src.GetSize(), sizeof(T));
|
||||
if (m_aT != NULL)
|
||||
{
|
||||
m_nAllocSize = src.GetSize();
|
||||
for (int i=0; i<src.GetSize(); i++)
|
||||
Add(src[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
CSimpleArray< T, TEqual >& operator=(const CSimpleArray< T, TEqual >& src)
|
||||
{
|
||||
if (GetSize() != src.GetSize())
|
||||
{
|
||||
RemoveAll();
|
||||
m_aT = (T*)calloc(src.GetSize(), sizeof(T));
|
||||
if (m_aT != NULL)
|
||||
m_nAllocSize = src.GetSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = GetSize(); i > 0; i--)
|
||||
RemoveAt(i - 1);
|
||||
}
|
||||
for (int i=0; i<src.GetSize(); i++)
|
||||
Add(src[i]);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Operations
|
||||
int GetSize() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
BOOL Add(const T& t)
|
||||
{
|
||||
if(m_nSize == m_nAllocSize)
|
||||
{
|
||||
T* aT;
|
||||
int nNewAllocSize = (m_nAllocSize == 0) ? 1 : (m_nSize * 2);
|
||||
|
||||
|
||||
if (nNewAllocSize<0||nNewAllocSize>INT_MAX/sizeof(T))
|
||||
{
|
||||
|
||||
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
aT = (T*)_recalloc(m_aT, nNewAllocSize, sizeof(T));
|
||||
if(aT == NULL)
|
||||
return FALSE;
|
||||
m_nAllocSize = nNewAllocSize;
|
||||
m_aT = aT;
|
||||
|
||||
}
|
||||
InternalSetAtIndex(m_nSize, t);
|
||||
m_nSize++;
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Remove(const T& t)
|
||||
{
|
||||
int nIndex = Find(t);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
return RemoveAt(nIndex);
|
||||
}
|
||||
BOOL RemoveAt(int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
m_aT[nIndex].~T();
|
||||
if(nIndex != (m_nSize - 1))
|
||||
Checked::memmove_s((void*)(m_aT + nIndex), (m_nSize - nIndex) * sizeof(T), (void*)(m_aT + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(T));
|
||||
m_nSize--;
|
||||
return TRUE;
|
||||
}
|
||||
void RemoveAll()
|
||||
{
|
||||
if(m_aT != NULL)
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
m_aT[i].~T();
|
||||
free(m_aT);
|
||||
m_aT = NULL;
|
||||
}
|
||||
m_nSize = 0;
|
||||
m_nAllocSize = 0;
|
||||
}
|
||||
const T& operator[] (int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
{
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
T& operator[] (int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
{
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
}
|
||||
return m_aT[nIndex];
|
||||
}
|
||||
T* GetData() const
|
||||
{
|
||||
return m_aT;
|
||||
}
|
||||
|
||||
int Find(const T& t) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqual(m_aT[i], t))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
BOOL SetAtIndex(int nIndex, const T& t)
|
||||
{
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
InternalSetAtIndex(nIndex, t);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Implementation
|
||||
class Wrapper
|
||||
{
|
||||
public:
|
||||
Wrapper(const T& _t) : t(_t)
|
||||
{
|
||||
}
|
||||
template <class _Ty>
|
||||
void * __cdecl operator new(size_t, _Ty* p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
template <class _Ty>
|
||||
void __cdecl operator delete(void* /* pv */, _Ty* /* p */)
|
||||
{
|
||||
}
|
||||
T t;
|
||||
};
|
||||
|
||||
// Implementation
|
||||
void InternalSetAtIndex(int nIndex, const T& t)
|
||||
{
|
||||
new(m_aT + nIndex) Wrapper(t);
|
||||
}
|
||||
|
||||
typedef T _ArrayElementType;
|
||||
T* m_aT;
|
||||
int m_nSize;
|
||||
int m_nAllocSize;
|
||||
|
||||
};
|
||||
|
||||
#define CSimpleValArray CSimpleArray
|
||||
|
||||
template <class T, class TEqual> inline CSimpleArray<T, TEqual>::~CSimpleArray()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
// intended for small number of simple types or pointers
|
||||
template <class TKey, class TVal, class TEqual = CSimpleMapEqualHelper< TKey, TVal > >
|
||||
class CSimpleMap
|
||||
{
|
||||
public:
|
||||
TKey* m_aKey;
|
||||
TVal* m_aVal;
|
||||
int m_nSize;
|
||||
|
||||
typedef TKey _ArrayKeyType;
|
||||
typedef TVal _ArrayElementType;
|
||||
|
||||
// Construction/destruction
|
||||
CSimpleMap() : m_aKey(NULL), m_aVal(NULL), m_nSize(0)
|
||||
{ }
|
||||
|
||||
~CSimpleMap()
|
||||
{
|
||||
RemoveAll();
|
||||
}
|
||||
|
||||
// Operations
|
||||
int GetSize() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
BOOL Add(const TKey& key, const TVal& val)
|
||||
{
|
||||
TKey* pKey;
|
||||
pKey = (TKey*)_recalloc(m_aKey, (m_nSize + 1), sizeof(TKey));
|
||||
if(pKey == NULL)
|
||||
return FALSE;
|
||||
m_aKey = pKey;
|
||||
TVal* pVal;
|
||||
pVal = (TVal*)_recalloc(m_aVal, (m_nSize + 1), sizeof(TVal));
|
||||
if(pVal == NULL)
|
||||
return FALSE;
|
||||
m_aVal = pVal;
|
||||
InternalSetAtIndex(m_nSize, key, val);
|
||||
m_nSize++;
|
||||
return TRUE;
|
||||
}
|
||||
BOOL Remove(const TKey& key)
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
return RemoveAt(nIndex);
|
||||
}
|
||||
BOOL RemoveAt(int nIndex)
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
m_aKey[nIndex].~TKey();
|
||||
m_aVal[nIndex].~TVal();
|
||||
if(nIndex != (m_nSize - 1))
|
||||
{
|
||||
Checked::memmove_s((void*)(m_aKey + nIndex), (m_nSize - nIndex) * sizeof(TKey), (void*)(m_aKey + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TKey));
|
||||
Checked::memmove_s((void*)(m_aVal + nIndex), (m_nSize - nIndex) * sizeof(TVal), (void*)(m_aVal + nIndex + 1), (m_nSize - (nIndex + 1)) * sizeof(TVal));
|
||||
}
|
||||
TKey* pKey;
|
||||
pKey = (TKey*)_recalloc(m_aKey, (m_nSize - 1), sizeof(TKey));
|
||||
if(pKey != NULL || m_nSize == 1)
|
||||
m_aKey = pKey;
|
||||
TVal* pVal;
|
||||
pVal = (TVal*)_recalloc(m_aVal, (m_nSize - 1), sizeof(TVal));
|
||||
if(pVal != NULL || m_nSize == 1)
|
||||
m_aVal = pVal;
|
||||
m_nSize--;
|
||||
return TRUE;
|
||||
}
|
||||
void RemoveAll()
|
||||
{
|
||||
if(m_aKey != NULL)
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
m_aKey[i].~TKey();
|
||||
m_aVal[i].~TVal();
|
||||
}
|
||||
free(m_aKey);
|
||||
m_aKey = NULL;
|
||||
}
|
||||
if(m_aVal != NULL)
|
||||
{
|
||||
free(m_aVal);
|
||||
m_aVal = NULL;
|
||||
}
|
||||
|
||||
m_nSize = 0;
|
||||
}
|
||||
BOOL SetAt(const TKey& key, const TVal& val)
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return FALSE;
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
m_aKey[nIndex].~TKey();
|
||||
m_aVal[nIndex].~TVal();
|
||||
InternalSetAtIndex(nIndex, key, val);
|
||||
return TRUE;
|
||||
}
|
||||
TVal Lookup(const TKey& key) const
|
||||
{
|
||||
int nIndex = FindKey(key);
|
||||
if(nIndex == -1)
|
||||
return NULL; // must be able to convert
|
||||
return GetValueAt(nIndex);
|
||||
}
|
||||
TKey ReverseLookup(const TVal& val) const
|
||||
{
|
||||
int nIndex = FindVal(val);
|
||||
if(nIndex == -1)
|
||||
return NULL; // must be able to convert
|
||||
return GetKeyAt(nIndex);
|
||||
}
|
||||
TKey& GetKeyAt(int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
|
||||
return m_aKey[nIndex];
|
||||
}
|
||||
TVal& GetValueAt(int nIndex) const
|
||||
{
|
||||
ATLASSERT(nIndex >= 0 && nIndex < m_nSize);
|
||||
if(nIndex < 0 || nIndex >= m_nSize)
|
||||
_AtlRaiseException((DWORD)EXCEPTION_ARRAY_BOUNDS_EXCEEDED);
|
||||
|
||||
return m_aVal[nIndex];
|
||||
}
|
||||
|
||||
int FindKey(const TKey& key) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqualKey(m_aKey[i], key))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
int FindVal(const TVal& val) const
|
||||
{
|
||||
for(int i = 0; i < m_nSize; i++)
|
||||
{
|
||||
if(TEqual::IsEqualValue(m_aVal[i], val))
|
||||
return i;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
BOOL SetAtIndex(int nIndex, const TKey& key, const TVal& val)
|
||||
{
|
||||
if (nIndex < 0 || nIndex >= m_nSize)
|
||||
return FALSE;
|
||||
InternalSetAtIndex(nIndex, key, val);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
// Implementation
|
||||
|
||||
template <typename T>
|
||||
class Wrapper
|
||||
{
|
||||
public:
|
||||
Wrapper(const T& _t) : t(_t)
|
||||
{
|
||||
}
|
||||
template <class _Ty>
|
||||
void *operator new(size_t, _Ty* p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
template <class _Ty>
|
||||
void operator delete(void* /* pv */, _Ty* /* p */)
|
||||
{
|
||||
}
|
||||
T t;
|
||||
};
|
||||
void InternalSetAtIndex(int nIndex, const TKey& key, const TVal& val)
|
||||
{
|
||||
new(m_aKey + nIndex) Wrapper<TKey>(key);
|
||||
new(m_aVal + nIndex) Wrapper<TVal>(val);
|
||||
}
|
||||
};
|
||||
|
||||
#pragma pop_macro("new")
|
||||
|
||||
}; // namespace ATL
|
||||
#pragma pack(pop)
|
||||
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma pop_macro("free")
|
||||
#pragma pop_macro("realloc")
|
||||
#pragma pop_macro("_recalloc")
|
||||
#pragma pop_macro("malloc")
|
||||
#pragma pop_macro("calloc")
|
||||
|
||||
|
||||
#endif // __ATLSIMPCOLL_H__
|
||||
|
||||
450
cpp/jacob/include/atltrace.h
Normal file
450
cpp/jacob/include/atltrace.h
Normal file
@@ -0,0 +1,450 @@
|
||||
// This is a part of the Active Template Library.
|
||||
// Copyright (C) Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Active Template Library Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Active Template Library product.
|
||||
|
||||
#ifndef __ATLTRACE_H__
|
||||
#define __ATLTRACE_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atldef.h>
|
||||
#include <atlconv.h>
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include <atldebugapi.h>
|
||||
|
||||
extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||
#endif // _DEBUG
|
||||
|
||||
|
||||
#pragma pack(push,_ATL_PACKING)
|
||||
namespace ATL
|
||||
{
|
||||
|
||||
// Declare a global instance of this class to automatically register a custom trace category at startup
|
||||
class CTraceCategory
|
||||
{
|
||||
public:
|
||||
explicit CTraceCategory( LPCTSTR pszCategoryName, UINT nStartingLevel = 0 ) throw();
|
||||
|
||||
#ifdef _DEBUG
|
||||
UINT GetLevel() const throw();
|
||||
void SetLevel( UINT nLevel ) throw();
|
||||
ATLTRACESTATUS GetStatus() const throw();
|
||||
void SetStatus( ATLTRACESTATUS eStatus) throw();
|
||||
#endif
|
||||
|
||||
operator DWORD_PTR() const throw();
|
||||
|
||||
public:
|
||||
#ifdef _DEBUG
|
||||
DWORD_PTR m_dwCategory;
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
class CTrace
|
||||
{
|
||||
public:
|
||||
typedef int (__cdecl *fnCrtDbgReport_t)(int,const char *,int,const char *,const char *,...);
|
||||
|
||||
private:
|
||||
CTrace(
|
||||
#ifdef _ATL_NO_DEBUG_CRT
|
||||
fnCrtDbgReport_t pfnCrtDbgReport = NULL)
|
||||
#else
|
||||
fnCrtDbgReport_t pfnCrtDbgReport = _CrtDbgReport)
|
||||
#endif
|
||||
: m_hInst(reinterpret_cast<HINSTANCE>(&__ImageBase)),
|
||||
m_dwModule( 0 )
|
||||
{
|
||||
m_dwModule = AtlTraceRegister(m_hInst, pfnCrtDbgReport);
|
||||
}
|
||||
|
||||
~CTrace()
|
||||
{
|
||||
AtlTraceUnregister(m_dwModule);
|
||||
}
|
||||
|
||||
public:
|
||||
bool ChangeCategory(DWORD_PTR dwCategory, UINT nLevel, ATLTRACESTATUS eStatus)
|
||||
{
|
||||
return 0 !=
|
||||
AtlTraceModifyCategory(0, dwCategory, nLevel, eStatus);
|
||||
}
|
||||
|
||||
bool GetCategory(DWORD_PTR dwCategory, UINT *pnLevel, ATLTRACESTATUS *peStatus)
|
||||
{
|
||||
ATLASSERT(pnLevel && peStatus);
|
||||
return 0 != AtlTraceGetCategory(0, dwCategory, pnLevel, peStatus);
|
||||
}
|
||||
UINT GetLevel()
|
||||
{
|
||||
ATLTRACESTATUS eStatus;
|
||||
UINT nLevel;
|
||||
AtlTraceGetModule(0, m_dwModule, &nLevel, &eStatus);
|
||||
|
||||
return nLevel;
|
||||
}
|
||||
void SetLevel(UINT nLevel)
|
||||
{
|
||||
AtlTraceModifyModule(0, m_dwModule, nLevel, ATLTRACESTATUS_ENABLED);
|
||||
}
|
||||
ATLTRACESTATUS GetStatus()
|
||||
{
|
||||
ATLTRACESTATUS eStatus;
|
||||
UINT nLevel;
|
||||
AtlTraceGetModule(0, m_dwModule, &nLevel, &eStatus);
|
||||
|
||||
return eStatus;
|
||||
}
|
||||
void SetStatus(ATLTRACESTATUS eStatus)
|
||||
{
|
||||
ATLTRACESTATUS eOldStatus;
|
||||
UINT nLevel;
|
||||
AtlTraceGetModule(0, m_dwModule, &nLevel, &eOldStatus);
|
||||
AtlTraceModifyModule(0, m_dwModule, nLevel, eStatus);
|
||||
}
|
||||
void __cdecl TraceV(const char *pszFileName, int nLine,
|
||||
DWORD_PTR dwCategory, UINT nLevel, LPCSTR pszFmt, va_list args) const;
|
||||
void __cdecl TraceV(const char *pszFileName, int nLine,
|
||||
DWORD_PTR dwCategory, UINT nLevel, LPCWSTR pszFmt, va_list args) const;
|
||||
|
||||
DWORD_PTR RegisterCategory(LPCSTR pszCategory)
|
||||
{return(AtlTraceRegisterCategoryA(m_dwModule, pszCategory));}
|
||||
#ifdef _UNICODE
|
||||
DWORD_PTR RegisterCategory(LPCWSTR pszCategory)
|
||||
{return(AtlTraceRegisterCategoryU(m_dwModule, pszCategory));}
|
||||
#endif
|
||||
|
||||
bool LoadSettings(LPCTSTR pszFileName = NULL) const
|
||||
{return 0 != AtlTraceLoadSettings(pszFileName);}
|
||||
void SaveSettings(LPCTSTR pszFileName = NULL) const
|
||||
{AtlTraceSaveSettings(pszFileName);}
|
||||
|
||||
public:
|
||||
static CTrace s_trace;
|
||||
|
||||
protected:
|
||||
HINSTANCE m_hInst;
|
||||
DWORD_PTR m_dwModule;
|
||||
};
|
||||
|
||||
inline void __cdecl CTrace::TraceV(const char *pszFileName, int nLine,
|
||||
DWORD_PTR dwCategory, UINT nLevel, LPCSTR pszFmt, va_list args) const
|
||||
{
|
||||
AtlTraceVA(m_dwModule, pszFileName, nLine, dwCategory, nLevel, pszFmt, args);
|
||||
}
|
||||
inline void __cdecl CTrace::TraceV(const char *pszFileName, int nLine,
|
||||
DWORD_PTR dwCategory, UINT nLevel, LPCWSTR pszFmt, va_list args) const
|
||||
{
|
||||
AtlTraceVU(m_dwModule, pszFileName, nLine, dwCategory, nLevel, pszFmt, args);
|
||||
}
|
||||
|
||||
extern CTraceCategory atlTraceGeneral;
|
||||
|
||||
class CTraceFileAndLineInfo
|
||||
{
|
||||
public:
|
||||
CTraceFileAndLineInfo(const char *pszFileName, int nLineNo)
|
||||
: m_pszFileName(pszFileName), m_nLineNo(nLineNo)
|
||||
{}
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
void __cdecl operator()(DWORD_PTR dwCategory, UINT nLevel, const char *pszFmt, ...) const
|
||||
{
|
||||
va_list ptr; va_start(ptr, pszFmt);
|
||||
ATL::CTrace::s_trace.TraceV(m_pszFileName, m_nLineNo, dwCategory, nLevel, pszFmt, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
void __cdecl operator()(DWORD_PTR dwCategory, UINT nLevel, const wchar_t *pszFmt, ...) const
|
||||
{
|
||||
va_list ptr; va_start(ptr, pszFmt);
|
||||
ATL::CTrace::s_trace.TraceV(m_pszFileName, m_nLineNo, dwCategory, nLevel, pszFmt, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
void __cdecl operator()(const char *pszFmt, ...) const
|
||||
{
|
||||
va_list ptr; va_start(ptr, pszFmt);
|
||||
ATL::CTrace::s_trace.TraceV(m_pszFileName, m_nLineNo, atlTraceGeneral, 0, pszFmt, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
void __cdecl operator()(const wchar_t *pszFmt, ...) const
|
||||
{
|
||||
va_list ptr; va_start(ptr, pszFmt);
|
||||
ATL::CTrace::s_trace.TraceV(m_pszFileName, m_nLineNo, atlTraceGeneral, 0, pszFmt, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
private:
|
||||
/* unimplemented */
|
||||
CTraceFileAndLineInfo &__cdecl operator=(const CTraceFileAndLineInfo &right);
|
||||
|
||||
const char *const m_pszFileName;
|
||||
const int m_nLineNo;
|
||||
};
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
inline CTraceCategory::CTraceCategory( LPCTSTR pszCategoryName, UINT nStartingLevel ) throw() :
|
||||
m_dwCategory( 0 )
|
||||
{
|
||||
m_dwCategory = ATL::CTrace::s_trace.RegisterCategory( pszCategoryName );
|
||||
ATL::CTrace::s_trace.ChangeCategory( m_dwCategory, nStartingLevel, ATLTRACESTATUS_INHERIT);
|
||||
}
|
||||
|
||||
inline CTraceCategory::operator DWORD_PTR() const throw()
|
||||
{
|
||||
return( m_dwCategory );
|
||||
}
|
||||
|
||||
inline UINT CTraceCategory::GetLevel() const throw()
|
||||
{
|
||||
UINT nLevel;
|
||||
ATLTRACESTATUS eStatus;
|
||||
ATL::CTrace::s_trace.GetCategory( m_dwCategory, &nLevel, &eStatus );
|
||||
|
||||
return( nLevel );
|
||||
}
|
||||
|
||||
inline void CTraceCategory::SetLevel( UINT nLevel ) throw()
|
||||
{
|
||||
ATL::CTrace::s_trace.ChangeCategory( m_dwCategory, nLevel, ATLTRACESTATUS_ENABLED );
|
||||
}
|
||||
|
||||
inline ATLTRACESTATUS CTraceCategory::GetStatus() const throw()
|
||||
{
|
||||
UINT nLevel;
|
||||
ATLTRACESTATUS eStatus;
|
||||
ATL::CTrace::s_trace.GetCategory( m_dwCategory, &nLevel, &eStatus );
|
||||
|
||||
return( eStatus );
|
||||
}
|
||||
|
||||
inline void CTraceCategory::SetStatus( ATLTRACESTATUS eStatus ) throw()
|
||||
{
|
||||
UINT nLevel;
|
||||
ATLTRACESTATUS eOldStatus;
|
||||
ATL::CTrace::s_trace.GetCategory( m_dwCategory, &nLevel, &eOldStatus );
|
||||
ATL::CTrace::s_trace.ChangeCategory( m_dwCategory, nLevel, eStatus );
|
||||
}
|
||||
|
||||
#else // !_DEBUG
|
||||
|
||||
inline CTraceCategory::CTraceCategory( LPCTSTR pszCategoryName, UINT nStartingLevel ) throw()
|
||||
{
|
||||
(void)pszCategoryName;
|
||||
(void)nStartingLevel;
|
||||
}
|
||||
|
||||
inline CTraceCategory::operator DWORD_PTR() const throw()
|
||||
{
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
#endif // _DEBUG
|
||||
|
||||
} // namespace ATL
|
||||
|
||||
namespace ATL
|
||||
{
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define DECLARE_TRACE_CATEGORY( name ) extern ATL::CTraceCategory name;
|
||||
#else
|
||||
#define DECLARE_TRACE_CATEGORY( name ) const DWORD_PTR name = 0;
|
||||
#endif
|
||||
|
||||
DECLARE_TRACE_CATEGORY( atlTraceGeneral )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceCOM )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceQI )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceRegistrar )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceRefcount )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceWindowing )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceControls )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceHosting )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceDBClient )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceDBProvider )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceSnapin )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceNotImpl )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceAllocation )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceException )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceTime )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceCache )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceStencil )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceString )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceMap )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceUtil )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceSecurity )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceSync )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceISAPI )
|
||||
|
||||
// atlTraceUser categories are no longer needed. Just declare your own trace category using CTraceCategory.
|
||||
DECLARE_TRACE_CATEGORY( atlTraceUser )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceUser2 )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceUser3 )
|
||||
DECLARE_TRACE_CATEGORY( atlTraceUser4 )
|
||||
|
||||
#pragma deprecated( atlTraceUser )
|
||||
#pragma deprecated( atlTraceUser2 )
|
||||
#pragma deprecated( atlTraceUser3 )
|
||||
#pragma deprecated( atlTraceUser4 )
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
#ifndef _ATL_NO_DEBUG_CRT
|
||||
class CNoUIAssertHook
|
||||
{
|
||||
public:
|
||||
CNoUIAssertHook()
|
||||
{
|
||||
ATLASSERT( s_pfnPrevHook == NULL );
|
||||
s_pfnPrevHook = _CrtSetReportHook(CrtHookProc);
|
||||
}
|
||||
~CNoUIAssertHook()
|
||||
{
|
||||
_CrtSetReportHook(s_pfnPrevHook);
|
||||
s_pfnPrevHook = NULL;
|
||||
}
|
||||
|
||||
private:
|
||||
static int __cdecl CrtHookProc(__in int eReportType, __in_z char* pszMessage, __out int* pnRetVal)
|
||||
{
|
||||
|
||||
if (eReportType == _CRT_ASSERT)
|
||||
{
|
||||
::OutputDebugStringA( "ASSERTION FAILED\n" );
|
||||
::OutputDebugStringA( pszMessage );
|
||||
//If caller doesn't want retVal, so be it.
|
||||
if (pnRetVal != NULL)
|
||||
{
|
||||
*pnRetVal = 1;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (s_pfnPrevHook != NULL)
|
||||
{
|
||||
return s_pfnPrevHook(eReportType, pszMessage, pnRetVal);
|
||||
}
|
||||
else
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
static _CRT_REPORT_HOOK s_pfnPrevHook;
|
||||
};
|
||||
|
||||
__declspec( selectany ) _CRT_REPORT_HOOK CNoUIAssertHook::s_pfnPrevHook = NULL;
|
||||
|
||||
#define DECLARE_NOUIASSERT() ATL::CNoUIAssertHook _g_NoUIAssertHook;
|
||||
|
||||
#endif // _ATL_NO_DEBUG_CRT
|
||||
|
||||
#ifndef ATLTRACE
|
||||
#define ATLTRACE ATL::CTraceFileAndLineInfo(__FILE__, __LINE__)
|
||||
#define ATLTRACE2 ATLTRACE
|
||||
#endif
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
inline void __cdecl AtlTrace(LPCSTR pszFormat, ...)
|
||||
{
|
||||
va_list ptr;
|
||||
va_start(ptr, pszFormat);
|
||||
ATL::CTrace::s_trace.TraceV(NULL, -1, atlTraceGeneral, 0, pszFormat, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
inline void __cdecl AtlTrace(LPCWSTR pszFormat, ...)
|
||||
{
|
||||
va_list ptr;
|
||||
va_start(ptr, pszFormat);
|
||||
ATL::CTrace::s_trace.TraceV(NULL, -1, atlTraceGeneral, 0, pszFormat, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
inline void __cdecl AtlTrace2(DWORD_PTR dwCategory, UINT nLevel, LPCSTR pszFormat, ...)
|
||||
{
|
||||
va_list ptr;
|
||||
va_start(ptr, pszFormat);
|
||||
ATL::CTrace::s_trace.TraceV(NULL, -1, dwCategory, nLevel, pszFormat, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
inline void __cdecl AtlTrace2(DWORD_PTR dwCategory, UINT nLevel, LPCWSTR pszFormat, ...)
|
||||
{
|
||||
va_list ptr;
|
||||
va_start(ptr, pszFormat);
|
||||
ATL::CTrace::s_trace.TraceV(NULL, -1, dwCategory, nLevel, pszFormat, ptr);
|
||||
va_end(ptr);
|
||||
}
|
||||
#pragma warning(pop)
|
||||
|
||||
#define ATLTRACENOTIMPL(funcname) do { ATLTRACE(ATL::atlTraceNotImpl, 0, _T("ATL: %s not implemented.\n"), funcname); return E_NOTIMPL; } while(0)
|
||||
|
||||
#else // !DEBUG
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4793)
|
||||
inline void __cdecl AtlTraceNull(...){}
|
||||
inline void __cdecl AtlTrace(LPCSTR , ...){}
|
||||
inline void __cdecl AtlTrace2(DWORD_PTR, UINT, LPCSTR , ...){}
|
||||
inline void __cdecl AtlTrace(LPCWSTR , ...){}
|
||||
inline void __cdecl AtlTrace2(DWORD_PTR, UINT, LPCWSTR , ...){}
|
||||
#pragma warning(pop)
|
||||
|
||||
#ifndef ATLTRACE
|
||||
|
||||
#define ATLTRACE __noop
|
||||
#define ATLTRACE2 __noop
|
||||
#endif //ATLTRACE
|
||||
#define ATLTRACENOTIMPL(funcname) return E_NOTIMPL
|
||||
#define DECLARE_NOUIASSERT()
|
||||
|
||||
#endif //!_DEBUG
|
||||
|
||||
}; // namespace ATL
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif // __ATLTRACE_H__
|
||||
|
||||
1509
cpp/jacob/include/statreg.h
Normal file
1509
cpp/jacob/include/statreg.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
cpp/jacob/lib/atls.lib
Normal file
BIN
cpp/jacob/lib/atls.lib
Normal file
Binary file not shown.
1
cpp/jacob/msvc/copy.bat
Normal file
1
cpp/jacob/msvc/copy.bat
Normal file
@@ -0,0 +1 @@
|
||||
copy Release\jacob.dll ..\..\..\java\native\
|
||||
20
cpp/jacob/msvc/jacob.sln
Normal file
20
cpp/jacob/msvc/jacob.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual C++ Express 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jacob", "jacob.vcxproj", "{745CA8EA-176E-46A7-B2A5-55260DF5639B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{745CA8EA-176E-46A7-B2A5-55260DF5639B}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{745CA8EA-176E-46A7-B2A5-55260DF5639B}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{745CA8EA-176E-46A7-B2A5-55260DF5639B}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{745CA8EA-176E-46A7-B2A5-55260DF5639B}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
cpp/jacob/msvc/jacob.suo
Normal file
BIN
cpp/jacob/msvc/jacob.suo
Normal file
Binary file not shown.
105
cpp/jacob/msvc/jacob.vcxproj
Normal file
105
cpp/jacob/msvc/jacob.vcxproj
Normal file
@@ -0,0 +1,105 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{745CA8EA-176E-46A7-B2A5-55260DF5639B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>jacob</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>..\include;C:\Program Files %28x86%29\Java\jdk1.6.0_23\include;C:\Program Files %28x86%29\Java\jdk1.6.0_23\include\win32;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>..\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;JACOB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;JACOB_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\ComThread.h" />
|
||||
<ClInclude Include="..\Dispatch.h" />
|
||||
<ClInclude Include="..\DispatchEvents.h" />
|
||||
<ClInclude Include="..\DispatchProxy.h" />
|
||||
<ClInclude Include="..\EnumVariant.h" />
|
||||
<ClInclude Include="..\EventProxy.h" />
|
||||
<ClInclude Include="..\SafeArray.h" />
|
||||
<ClInclude Include="..\STA.h" />
|
||||
<ClInclude Include="..\StdAfx.h" />
|
||||
<ClInclude Include="..\util.h" />
|
||||
<ClInclude Include="..\Variant.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\ComThread.cpp" />
|
||||
<ClCompile Include="..\Dispatch.cpp" />
|
||||
<ClCompile Include="..\DispatchEvents.cpp" />
|
||||
<ClCompile Include="..\DispatchProxy.cpp" />
|
||||
<ClCompile Include="..\EnumVariant.cpp" />
|
||||
<ClCompile Include="..\EventProxy.cpp" />
|
||||
<ClCompile Include="..\SafeArray.cpp" />
|
||||
<ClCompile Include="..\STA.cpp" />
|
||||
<ClCompile Include="..\util.cpp" />
|
||||
<ClCompile Include="..\Variant.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
87
cpp/jacob/msvc/jacob.vcxproj.filters
Normal file
87
cpp/jacob/msvc/jacob.vcxproj.filters
Normal file
@@ -0,0 +1,87 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="targetver.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\SafeArray.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\STA.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\util.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Variant.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\ComThread.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\Dispatch.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\DispatchEvents.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\DispatchProxy.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\EnumVariant.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\EventProxy.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\ComThread.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Dispatch.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\DispatchEvents.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\DispatchProxy.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\EnumVariant.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\EventProxy.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\SafeArray.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\STA.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\util.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\Variant.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
3
cpp/jacob/msvc/jacob.vcxproj.user
Normal file
3
cpp/jacob/msvc/jacob.vcxproj.user
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
||||
75
cpp/jacob/util.cpp
Normal file
75
cpp/jacob/util.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include "Dispatch.h"
|
||||
// Win32 support for Ole Automation
|
||||
#include <wchar.h>
|
||||
#include <string.h>
|
||||
#include <atlbase.h>
|
||||
#include <objbase.h>
|
||||
#include <oleauto.h>
|
||||
#include <olectl.h>
|
||||
#include "util.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
void ThrowComFail(JNIEnv *env, const char* desc, jint hr)
|
||||
{
|
||||
jclass failClass = env->FindClass("com/jacob/com/ComFailException");
|
||||
// call the constructor that takes hr and message
|
||||
jmethodID failCons =
|
||||
env->GetMethodID(failClass, "<init>", "(ILjava/lang/String;)V");
|
||||
if (!desc) {
|
||||
desc = "Java/COM Error";
|
||||
}
|
||||
jstring js = env->NewStringUTF(desc);
|
||||
jthrowable fail = (jthrowable)env->NewObject(failClass, failCons, hr, js);
|
||||
env->Throw(fail);
|
||||
}
|
||||
|
||||
void ThrowComFailUnicode(JNIEnv *env, const wchar_t* desc, jint hr)
|
||||
{
|
||||
if (!desc) {
|
||||
ThrowComFail(env, "Java/COM Error", hr);
|
||||
}
|
||||
jclass failClass = env->FindClass("com/jacob/com/ComFailException");
|
||||
// call the constructor that takes hr and message
|
||||
jmethodID failCons =
|
||||
env->GetMethodID(failClass, "<init>", "(ILjava/lang/String;)V");
|
||||
jstring js = env->NewString((const jchar *) desc, wcslen(desc));
|
||||
jthrowable fail = (jthrowable)env->NewObject(failClass, failCons, hr, js);
|
||||
env->Throw(fail);
|
||||
}
|
||||
|
||||
// if env's are different throw on the 1st env
|
||||
int CheckEnv(JNIEnv *env1, JNIEnv *env2)
|
||||
{
|
||||
if (env1 != env2) {
|
||||
jclass failClass = env1->FindClass("com/jacob/com/WrongThreadException");
|
||||
// call the constructor that takes hr and message
|
||||
jmethodID failCons =
|
||||
env1->GetMethodID(failClass, "<init>", "()V");
|
||||
env1->ThrowNew(failClass, "Wrong Thread");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
29
cpp/jacob/util.h
Normal file
29
cpp/jacob/util.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 1999-2004 Sourceforge JACOB Project.
|
||||
* All rights reserved. Originator: Dan Adler (http://danadler.com).
|
||||
* Get more information about JACOB at http://sourceforge.net/projects/jacob-project
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
#include <objbase.h>
|
||||
extern "C" {
|
||||
VARIANT *extractVariant(JNIEnv *env, jobject arg);
|
||||
void ThrowComFail(JNIEnv *env, const char* desc, jint hr);
|
||||
void ThrowComFailUnicode(JNIEnv *env, const wchar_t* desc, jint hr);
|
||||
IDispatch *extractDispatch(JNIEnv *env, jobject arg);
|
||||
SAFEARRAY *extractSA(JNIEnv *env, jobject arg);
|
||||
void setSA(JNIEnv *env, jobject arg, SAFEARRAY *sa, int copy);
|
||||
SAFEARRAY *copySA(SAFEARRAY *psa);
|
||||
}
|
||||
157
cpp/jintellitype/JIntellitype.cpp
Normal file
157
cpp/jintellitype/JIntellitype.cpp
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
JIntellitype (http://www.melloware.com/)
|
||||
Java JNI API for Windows Intellitype commands and global keystrokes.
|
||||
|
||||
Copyright (C) 1999, 2008 Emil A. Lefkof III, info@melloware.com
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Compiled with Mingw port of GCC,
|
||||
Bloodshed Dev-C++ IDE (http://www.bloodshed.net/devcpp.html)
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "com_melloware_jintellitype_JIntellitype.h"
|
||||
#include "JIntellitypeHandler.h"
|
||||
|
||||
HINSTANCE g_instance = NULL;
|
||||
|
||||
|
||||
BOOL WINAPI DllMain
|
||||
(
|
||||
HINSTANCE hinstDLL, // handle to DLL module
|
||||
DWORD fdwReason, // reason for calling function
|
||||
LPVOID lpvReserved // reserved
|
||||
)
|
||||
{
|
||||
switch( fdwReason )
|
||||
{
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
|
||||
case DLL_PROCESS_ATTACH:
|
||||
g_instance = hinstDLL;
|
||||
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: initializeLibrary
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_initializeLibrary
|
||||
(JNIEnv *env, jobject object)
|
||||
{
|
||||
// Get handler
|
||||
JIntellitypeHandler *l_handler = JIntellitypeHandler::extract( env, object );
|
||||
|
||||
// Create our handler
|
||||
l_handler = new JIntellitypeHandler( env, object );
|
||||
|
||||
// Enable it
|
||||
if( l_handler )
|
||||
l_handler->initialize(env, g_instance);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: regHotKey
|
||||
* Signature: (III)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_regHotKey
|
||||
(JNIEnv *env, jobject object, jint identifier, jint modifier, jint keycode)
|
||||
{
|
||||
// Get handler
|
||||
JIntellitypeHandler *l_handler = JIntellitypeHandler::extract( env, object );
|
||||
|
||||
if( l_handler )
|
||||
{
|
||||
l_handler->regHotKey(identifier, modifier, keycode);
|
||||
}
|
||||
else
|
||||
{
|
||||
// throw exception
|
||||
jclass JIntellitypeException = env->FindClass("com/melloware/jintellitype/JIntellitypeException");
|
||||
env->ThrowNew(JIntellitypeException,"JIntellitype was not initialized properly.");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: unregHotKey
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_unregHotKey
|
||||
(JNIEnv *env, jobject object, jint identifier)
|
||||
{
|
||||
// Get handler
|
||||
JIntellitypeHandler *l_handler = JIntellitypeHandler::extract( env, object );
|
||||
|
||||
if( l_handler )
|
||||
{
|
||||
l_handler->unregHotKey(identifier);
|
||||
}
|
||||
else
|
||||
{
|
||||
// throw exception
|
||||
jclass JIntellitypeException = env->FindClass("com/melloware/jintellitype/JIntellitypeException");
|
||||
env->ThrowNew(JIntellitypeException,"JIntellitype was not initialized properly.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extern "C"
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: terminate
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_terminate
|
||||
(JNIEnv *env, jobject object)
|
||||
{
|
||||
// Get handler
|
||||
JIntellitypeHandler *l_handler = JIntellitypeHandler::extract( env, object );
|
||||
|
||||
// Clean up all resources allocated by this API
|
||||
if( l_handler )
|
||||
l_handler->terminate();
|
||||
|
||||
}
|
||||
|
||||
extern "C"
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: isRunning
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_melloware_jintellitype_JIntellitype_isRunning
|
||||
(JNIEnv *env, jclass, jstring wndName)
|
||||
{
|
||||
// App name for the hidden window's registered class
|
||||
CHAR szAppName[] = "SunAwtFrame";
|
||||
const char *cWndName = env->GetStringUTFChars(wndName, 0);
|
||||
// Find out if there's a hidden window with the given title
|
||||
HWND mHwnd = FindWindow((LPCWSTR)szAppName, (LPCWSTR)cWndName);
|
||||
env->ReleaseStringUTFChars(wndName, cWndName);
|
||||
// If there is, another instance of our app is already running
|
||||
return mHwnd != NULL;
|
||||
}
|
||||
|
||||
279
cpp/jintellitype/JIntellitypeHandler.cpp
Normal file
279
cpp/jintellitype/JIntellitypeHandler.cpp
Normal file
@@ -0,0 +1,279 @@
|
||||
/*
|
||||
JIntellitype (http://www.melloware.com/)
|
||||
Java JNI API for Windows Intellitype commands and global keystrokes.
|
||||
|
||||
Copyright (C) 1999, 2008 Emil A. Lefkof III, info@melloware.com
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Compiled with Mingw port of GCC,
|
||||
Bloodshed Dev-C++ IDE (http://www.bloodshed.net/devcpp.html)
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "JIntellitypeHandler.h"
|
||||
#include "JIntellitypeThread.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
UINT WM_SHELLHOOK = 0;
|
||||
|
||||
/*
|
||||
* Extract the unique handlerID from the java object
|
||||
*/
|
||||
JIntellitypeHandler *JIntellitypeHandler::extract( JNIEnv *env, jobject object )
|
||||
{
|
||||
// Get field ID
|
||||
jfieldID l_handlerId = env->GetFieldID( env->GetObjectClass( object ), "handler", "I" );
|
||||
|
||||
// Get field
|
||||
JIntellitypeHandler *l_handler = (JIntellitypeHandler *) env->GetIntField( object, l_handlerId );
|
||||
|
||||
return l_handler;
|
||||
}
|
||||
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
JIntellitypeHandler::JIntellitypeHandler( JNIEnv *env, jobject object )
|
||||
{
|
||||
m_window = NULL;
|
||||
|
||||
// Reference object
|
||||
m_object = env->NewGlobalRef(object );
|
||||
|
||||
// Get method IDs
|
||||
m_fireHotKey = env->GetMethodID( env->GetObjectClass( m_object ) , "onHotKey", "(I)V" );
|
||||
m_fireIntellitype = env->GetMethodID( env->GetObjectClass( m_object ) , "onIntellitype", "(I)V" );
|
||||
|
||||
// Get field ID
|
||||
jfieldID l_handlerId = env->GetFieldID( env->GetObjectClass( m_object ) , "handler", "I" );
|
||||
|
||||
// Set field
|
||||
env->SetIntField( m_object, l_handlerId, (jint) this );
|
||||
}
|
||||
|
||||
/*
|
||||
* Destructor
|
||||
*/
|
||||
JIntellitypeHandler::~JIntellitypeHandler()
|
||||
{
|
||||
// Get field ID
|
||||
jfieldID l_handlerId = g_JIntellitypeThread.m_env->GetFieldID( g_JIntellitypeThread.m_env->GetObjectClass( m_object ), "handler", "I" );
|
||||
|
||||
// Set field
|
||||
g_JIntellitypeThread.m_env->SetIntField( m_object, l_handlerId, 0 );
|
||||
|
||||
// Release our reference
|
||||
g_JIntellitypeThread.m_env->DeleteGlobalRef( m_object );
|
||||
|
||||
// unregister the shell hook
|
||||
DeregisterShellHookWindow( m_window );
|
||||
|
||||
// Destroy window
|
||||
DestroyWindow( m_window );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Perform initialization of the object and thread.
|
||||
*/
|
||||
void JIntellitypeHandler::initialize( JNIEnv *env, HINSTANCE instance )
|
||||
{
|
||||
m_instance = instance;
|
||||
g_JIntellitypeThread.MakeSureThreadIsUp( env );
|
||||
while( !PostThreadMessage( g_JIntellitypeThread, WM_JINTELLITYPE, INITIALIZE_CODE, (LPARAM) this ) )
|
||||
Sleep( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback method that creates the hidden window on initialization to receive
|
||||
* any WM_HOTKEY messages and process them.
|
||||
*/
|
||||
void JIntellitypeHandler::doInitialize()
|
||||
{
|
||||
// Register window class
|
||||
WNDCLASSEX l_Class;
|
||||
l_Class.cbSize = sizeof( l_Class );
|
||||
l_Class.style = CS_HREDRAW | CS_VREDRAW;
|
||||
l_Class.lpszClassName = TEXT( "JIntellitypeHandlerClass" );
|
||||
l_Class.lpfnWndProc = WndProc;
|
||||
l_Class.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
||||
l_Class.hCursor = NULL;
|
||||
l_Class.hIcon = NULL;
|
||||
l_Class.hIconSm = NULL;
|
||||
l_Class.lpszMenuName = NULL;
|
||||
l_Class.cbClsExtra = 0;
|
||||
l_Class.cbWndExtra = 0;
|
||||
l_Class.hInstance = m_instance;
|
||||
|
||||
if( !RegisterClassEx( &l_Class ) )
|
||||
return;
|
||||
|
||||
// Create window
|
||||
m_window = CreateWindow
|
||||
(
|
||||
TEXT( "JIntellitypeHandlerClass" ),
|
||||
TEXT( "JIntellitypeHandler" ),
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
0, 0, 0, 0,
|
||||
NULL,
|
||||
NULL,
|
||||
m_instance,
|
||||
NULL
|
||||
);
|
||||
|
||||
if( !m_window )
|
||||
return;
|
||||
|
||||
//Set pointer to this object inside the Window's USERDATA section
|
||||
SetWindowLong( m_window, GWL_USERDATA, (LONG) this );
|
||||
|
||||
// hide the window
|
||||
ShowWindow(m_window, SW_HIDE);
|
||||
UpdateWindow(m_window);
|
||||
|
||||
//register this window as a shell hook to intercept WM_APPCOMMAND messages
|
||||
WM_SHELLHOOK = RegisterWindowMessage(TEXT("SHELLHOOK"));
|
||||
BOOL (__stdcall *RegisterShellHookWindow)(HWND) = NULL;
|
||||
RegisterShellHookWindow = (BOOL (__stdcall *)(HWND))GetProcAddress(GetModuleHandle((LPCWSTR)"USER32.DLL"), "RegisterShellHookWindow");
|
||||
|
||||
//make sure it worked
|
||||
if (!RegisterShellHookWindow(m_window)) {
|
||||
// throw exception
|
||||
jclass JIntellitypeException = g_JIntellitypeThread.m_env->FindClass("com/melloware/jintellitype/JIntellitypeException");
|
||||
g_JIntellitypeThread.m_env->ThrowNew(JIntellitypeException,"Could not register window as a shell hook window.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Registers a hotkey.
|
||||
* identifier - unique identifier assigned to this key comination
|
||||
* modifier - ALT, SHIFT, CTRL, WIN or combination of
|
||||
* keycode- Ascii keycode, 65 for A, 66 for B etc
|
||||
*/
|
||||
void JIntellitypeHandler::regHotKey( jint identifier, jint modifier, jint keycode )
|
||||
{
|
||||
JIntellitypeHandlerCallback *callback = (JIntellitypeHandlerCallback*) malloc(sizeof(JIntellitypeHandlerCallback));
|
||||
callback->identifier = identifier;
|
||||
callback->modifier = modifier;
|
||||
callback->keycode = keycode;
|
||||
callback->handler = this;
|
||||
PostThreadMessage( g_JIntellitypeThread, WM_JINTELLITYPE, REGISTER_HOTKEY_CODE, (LPARAM) callback );
|
||||
}
|
||||
|
||||
/*
|
||||
* Actually registers the hotkey using the Win32API RegisterHotKey call.
|
||||
*/
|
||||
void JIntellitypeHandler::doRegHotKey(LPARAM callback_)
|
||||
{
|
||||
JIntellitypeHandlerCallback *callback = (JIntellitypeHandlerCallback*) callback_;
|
||||
RegisterHotKey(m_window, callback->identifier, callback->modifier, callback->keycode);
|
||||
free(callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unregisters a previously assigned hotkey.
|
||||
* identifier - unique identifier assigned to this key comination
|
||||
*/
|
||||
void JIntellitypeHandler::unregHotKey( jint identifier )
|
||||
{
|
||||
JIntellitypeHandlerCallback *callback = (JIntellitypeHandlerCallback*) malloc(sizeof(JIntellitypeHandlerCallback));
|
||||
callback->identifier = identifier;
|
||||
callback->handler = this;
|
||||
PostThreadMessage( g_JIntellitypeThread, WM_JINTELLITYPE, UNREGISTER_HOTKEY_CODE, (LPARAM) callback );
|
||||
}
|
||||
|
||||
/*
|
||||
* Actually unregisters the hotkey using the Win32API UnregisterHotKey call.
|
||||
*/
|
||||
void JIntellitypeHandler::doUnregisterHotKey(LPARAM callback_)
|
||||
{
|
||||
JIntellitypeHandlerCallback *callback = (JIntellitypeHandlerCallback*) callback_;
|
||||
UnregisterHotKey(m_window, callback->identifier);
|
||||
free(callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* When an intellitype command is recieved by the JFrame this method is called
|
||||
* to perform a callback to the Intellitype java listeners.
|
||||
* commandId - the unique command Id from the WM_APPCOMMAND listings
|
||||
*/
|
||||
void JIntellitypeHandler::intellitype( jint commandId )
|
||||
{
|
||||
JIntellitypeHandlerCallback *callback = (JIntellitypeHandlerCallback*) malloc(sizeof(JIntellitypeHandlerCallback));
|
||||
callback->command = commandId;
|
||||
callback->handler = this;
|
||||
PostThreadMessage( g_JIntellitypeThread, WM_JINTELLITYPE, INTELLITYPE_CODE, (LPARAM) callback );
|
||||
}
|
||||
|
||||
/*
|
||||
* Call the correct JVM with the intellitype command for the listeners listening.
|
||||
*/
|
||||
void JIntellitypeHandler::doIntellitype(LPARAM callback_)
|
||||
{
|
||||
JIntellitypeHandlerCallback *callback = (JIntellitypeHandlerCallback*) callback_;
|
||||
g_JIntellitypeThread.m_env->CallVoidMethod(m_object, m_fireIntellitype, callback->command);
|
||||
free(callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* Cleans up resources allocated by JIntellitype.
|
||||
*/
|
||||
void JIntellitypeHandler::terminate()
|
||||
{
|
||||
PostThreadMessage( g_JIntellitypeThread, WM_JINTELLITYPE, TERMINATE_CODE, (LPARAM) this );
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback method to send hotkey to the Java HotKeyListeners registered.
|
||||
*/
|
||||
void JIntellitypeHandler::fireHotKey(jint hotkeyId)
|
||||
{
|
||||
g_JIntellitypeThread.m_env->CallVoidMethod(m_object, m_fireHotKey, hotkeyId);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* WndProc method registered to the hidden window to listen for WM_HOTKEY
|
||||
* messages and send them back to the Java listeners.
|
||||
*/
|
||||
LRESULT CALLBACK JIntellitypeHandler::WndProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam )
|
||||
{
|
||||
|
||||
// check for Intellitype messages and if found send them to Intellitype listeners
|
||||
if (uMessage == WM_SHELLHOOK) {
|
||||
if (wParam == HSHELL_APPCOMMAND) {
|
||||
jint cmd = GET_APPCOMMAND_LPARAM(lParam);
|
||||
JIntellitypeHandler *l_this = (JIntellitypeHandler *) GetWindowLong( hWnd, GWL_USERDATA );
|
||||
l_this->intellitype(cmd);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// check for registered hotkey messages and send them to HotKeyListeners
|
||||
switch( uMessage ) {
|
||||
case WM_HOTKEY: {
|
||||
JIntellitypeHandler *l_this = (JIntellitypeHandler *) GetWindowLong( hWnd, GWL_USERDATA );
|
||||
l_this->fireHotKey(wParam);
|
||||
return TRUE;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return DefWindowProc( hWnd, uMessage, wParam, lParam );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
93
cpp/jintellitype/JIntellitypeHandler.h
Normal file
93
cpp/jintellitype/JIntellitypeHandler.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
JIntellitype (http://www.melloware.com/)
|
||||
Java JNI API for Windows Intellitype commands and global keystrokes.
|
||||
|
||||
Copyright (C) 1999, 2008 Emil A. Lefkof III, info@melloware.com
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Compiled with Mingw port of GCC,
|
||||
Bloodshed Dev-C++ IDE (http://www.bloodshed.net/devcpp.html)
|
||||
*/
|
||||
#ifndef __JIntellitypeHandler_h__
|
||||
#define __JIntellitypeHandler_h__
|
||||
|
||||
#include "JIntellitypeThread.h"
|
||||
|
||||
class JIntellitypeHandler
|
||||
{
|
||||
friend DWORD WINAPI JIntellitypeThread::ThreadProc( LPVOID lpParameter );
|
||||
|
||||
public:
|
||||
|
||||
static JIntellitypeHandler *extract( JNIEnv *env, jobject object );
|
||||
|
||||
JIntellitypeHandler( JNIEnv *env, jobject object );
|
||||
|
||||
void initialize( JNIEnv *env, HINSTANCE instance );
|
||||
void regHotKey( jint identifier, jint modifier, jint keycode );
|
||||
void unregHotKey( jint identifier );
|
||||
void intellitype( jint commandId );
|
||||
void terminate();
|
||||
|
||||
private:
|
||||
|
||||
enum
|
||||
{
|
||||
INITIALIZE_CODE = 1,
|
||||
REGISTER_HOTKEY_CODE = 2,
|
||||
UNREGISTER_HOTKEY_CODE = 3,
|
||||
TERMINATE_CODE = 4,
|
||||
INTELLITYPE_CODE = 5
|
||||
};
|
||||
|
||||
~JIntellitypeHandler();
|
||||
|
||||
void createHiddenWindow();
|
||||
void doInitialize();
|
||||
void doRegHotKey(LPARAM callback);
|
||||
void doUnregisterHotKey(LPARAM callback);
|
||||
void doIntellitype(LPARAM callback);
|
||||
void fireHotKey(jint hotkeyId);
|
||||
void fireIntellitype(jint commandId);
|
||||
|
||||
HINSTANCE m_instance;
|
||||
HWND m_window;
|
||||
jobject m_object;
|
||||
jmethodID m_fireHotKey;
|
||||
jmethodID m_fireIntellitype;
|
||||
|
||||
static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam );
|
||||
static DWORD WINAPI ThreadProc( LPVOID lpParameter );
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
JIntellitypeHandler *handler;
|
||||
jint identifier;
|
||||
jint modifier;
|
||||
jint keycode;
|
||||
jint command;
|
||||
} JIntellitypeHandlerCallback;
|
||||
|
||||
|
||||
#ifndef WM_APPCOMMAND
|
||||
#define WM_APPCOMMAND 0x319
|
||||
#define FAPPCOMMAND_MASK 0x8000
|
||||
#define GET_APPCOMMAND_LPARAM(lParam) ((short)(HIWORD(lParam) & ~FAPPCOMMAND_MASK))
|
||||
#define HSHELL_APPCOMMAND 12
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
133
cpp/jintellitype/JIntellitypeThread.cpp
Normal file
133
cpp/jintellitype/JIntellitypeThread.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
JIntellitype (http://www.melloware.com/)
|
||||
Java JNI API for Windows Intellitype commands and global keystrokes.
|
||||
|
||||
Copyright (C) 1999, 2008 Emil A. Lefkof III, info@melloware.com
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Compiled with Mingw port of GCC,
|
||||
Bloodshed Dev-C++ IDE (http://www.bloodshed.net/devcpp.html)
|
||||
*/
|
||||
#include "stdafx.h"
|
||||
#include "JIntellitypeThread.h"
|
||||
#include "JIntellitypeHandler.h"
|
||||
|
||||
JIntellitypeThread g_JIntellitypeThread;
|
||||
|
||||
|
||||
JIntellitypeThread::JIntellitypeThread()
|
||||
{
|
||||
m_env = NULL;
|
||||
m_thread = 0;
|
||||
m_vm = NULL;
|
||||
m_handlerCount = 0;
|
||||
}
|
||||
|
||||
|
||||
void JIntellitypeThread::MakeSureThreadIsUp( JNIEnv *env )
|
||||
{
|
||||
if( !m_thread )
|
||||
{
|
||||
// Get VM
|
||||
env->GetJavaVM( &m_vm );
|
||||
|
||||
// Start "native" thread
|
||||
CreateThread
|
||||
(
|
||||
NULL,
|
||||
0,
|
||||
ThreadProc,
|
||||
this,
|
||||
0,
|
||||
&m_thread
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JIntellitypeThread::operator DWORD ()
|
||||
{
|
||||
return m_thread;
|
||||
}
|
||||
|
||||
|
||||
DWORD WINAPI JIntellitypeThread::ThreadProc( LPVOID lpParameter )
|
||||
{
|
||||
JIntellitypeThread *l_this = (JIntellitypeThread *) lpParameter;
|
||||
|
||||
// Attach the thread to the VM
|
||||
l_this->m_vm->AttachCurrentThread( (void**) &l_this->m_env, NULL );
|
||||
|
||||
MSG msg;
|
||||
while( GetMessage( &msg, NULL, 0, 0 ) )
|
||||
{
|
||||
if( msg.message == WM_JINTELLITYPE )
|
||||
{
|
||||
// Extract handler
|
||||
JIntellitypeHandler *l_handler;
|
||||
|
||||
switch( msg.wParam )
|
||||
{
|
||||
case JIntellitypeHandler::INITIALIZE_CODE:
|
||||
l_handler = (JIntellitypeHandler*) msg.lParam;
|
||||
l_this->m_handlerCount++;
|
||||
l_handler->doInitialize();
|
||||
break;
|
||||
case JIntellitypeHandler::REGISTER_HOTKEY_CODE:
|
||||
l_handler = ((JIntellitypeHandlerCallback*) msg.lParam)->handler;
|
||||
l_handler->doRegHotKey(msg.lParam);
|
||||
break;
|
||||
|
||||
case JIntellitypeHandler::UNREGISTER_HOTKEY_CODE:
|
||||
l_handler = ((JIntellitypeHandlerCallback*) msg.lParam)->handler;
|
||||
l_handler->doUnregisterHotKey(msg.lParam);
|
||||
break;
|
||||
case JIntellitypeHandler::INTELLITYPE_CODE:
|
||||
l_handler = ((JIntellitypeHandlerCallback*) msg.lParam)->handler;
|
||||
l_handler->doIntellitype(msg.lParam);
|
||||
break;
|
||||
|
||||
case JIntellitypeHandler::TERMINATE_CODE:
|
||||
l_handler = (JIntellitypeHandler*) msg.lParam;
|
||||
|
||||
// Destroy it!
|
||||
delete l_handler;
|
||||
|
||||
// No more handlers?
|
||||
if( !--l_this->m_handlerCount )
|
||||
{
|
||||
l_this->m_thread = 0;
|
||||
|
||||
// Detach thread from VM
|
||||
l_this->m_vm->DetachCurrentThread();
|
||||
|
||||
// Time to die
|
||||
ExitThread( 0 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
}
|
||||
}
|
||||
|
||||
// Detach thread from VM
|
||||
l_this->m_vm->DetachCurrentThread();
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
cpp/jintellitype/JIntellitypeThread.h
Normal file
55
cpp/jintellitype/JIntellitypeThread.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
JIntellitype (http://www.melloware.com/)
|
||||
Java JNI API for Windows Intellitype commands and global keystrokes.
|
||||
|
||||
Copyright (C) 1999, 2008 Emil A. Lefkof III, info@melloware.com
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
Compiled with Mingw port of GCC,
|
||||
Bloodshed Dev-C++ IDE (http://www.bloodshed.net/devcpp.html)
|
||||
*/
|
||||
#ifndef __JIntellitypeThread_h__
|
||||
#define __JIntellitypeThread_h__
|
||||
|
||||
|
||||
class JIntellitypeThread
|
||||
{
|
||||
public:
|
||||
|
||||
JIntellitypeThread();
|
||||
|
||||
void MakeSureThreadIsUp( JNIEnv *env );
|
||||
|
||||
JNIEnv *m_env;
|
||||
static DWORD WINAPI ThreadProc( LPVOID lpParameter );
|
||||
|
||||
operator DWORD ();
|
||||
|
||||
private:
|
||||
|
||||
DWORD m_thread;
|
||||
JavaVM *m_vm;
|
||||
int m_handlerCount;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern JIntellitypeThread g_JIntellitypeThread;
|
||||
|
||||
|
||||
#define WM_JINTELLITYPE (WM_USER+1)
|
||||
|
||||
|
||||
#endif
|
||||
23
cpp/jintellitype/JIntellitype_private.h
Normal file
23
cpp/jintellitype/JIntellitype_private.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/* THIS FILE WILL BE OVERWRITTEN BY DEV-C++ */
|
||||
/* DO NOT EDIT ! */
|
||||
|
||||
#ifndef JINTELLITYPE_PRIVATE_H
|
||||
#define JINTELLITYPE_PRIVATE_H
|
||||
|
||||
/* VERSION DEFINITIONS */
|
||||
#define VER_STRING "1.0.0.465"
|
||||
#define VER_MAJOR 1
|
||||
#define VER_MINOR 0
|
||||
#define VER_RELEASE 0
|
||||
#define VER_BUILD 465
|
||||
#define COMPANY_NAME "Melloware Inc (www.melloware.com)"
|
||||
#define FILE_VERSION "1.0"
|
||||
#define FILE_DESCRIPTION "Java JNI bridge to MS Intellitype commands"
|
||||
#define INTERNAL_NAME ""
|
||||
#define LEGAL_COPYRIGHT "Copyright 2006 Melloware Inc"
|
||||
#define LEGAL_TRADEMARKS "Copyright 2006 Melloware Inc"
|
||||
#define ORIGINAL_FILENAME ""
|
||||
#define PRODUCT_NAME "JIntellitype"
|
||||
#define PRODUCT_VERSION "1.0"
|
||||
|
||||
#endif /*JINTELLITYPE_PRIVATE_H*/
|
||||
8
cpp/jintellitype/StdAfx.cpp
Normal file
8
cpp/jintellitype/StdAfx.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// win32.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
24
cpp/jintellitype/StdAfx.h
Normal file
24
cpp/jintellitype/StdAfx.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#if !defined(AFX_STDAFX_H__1F571525_24C2_11D3_B0CF_0000E85D9A83__INCLUDED_)
|
||||
#define AFX_STDAFX_H__1F571525_24C2_11D3_B0CF_0000E85D9A83__INCLUDED_
|
||||
|
||||
#if _MSC_VER > 1000
|
||||
#pragma once
|
||||
#endif // _MSC_VER > 1000
|
||||
|
||||
// Insert your headers here
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
//{{AFX_INSERT_LOCATION}}
|
||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
||||
|
||||
#endif // !defined(AFX_STDAFX_H__1F571525_24C2_11D3_B0CF_0000E85D9A83__INCLUDED_)
|
||||
53
cpp/jintellitype/com_melloware_jintellitype_JIntellitype.h
Normal file
53
cpp/jintellitype/com_melloware_jintellitype_JIntellitype.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class com_melloware_jintellitype_JIntellitype */
|
||||
|
||||
#ifndef _Included_com_melloware_jintellitype_JIntellitype
|
||||
#define _Included_com_melloware_jintellitype_JIntellitype
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: initializeLibrary
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_initializeLibrary
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: regHotKey
|
||||
* Signature: (III)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_regHotKey
|
||||
(JNIEnv *, jobject, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: terminate
|
||||
* Signature: ()V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_terminate
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: unregHotKey
|
||||
* Signature: (I)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_com_melloware_jintellitype_JIntellitype_unregHotKey
|
||||
(JNIEnv *, jobject, jint);
|
||||
|
||||
/*
|
||||
* Class: com_melloware_jintellitype_JIntellitype
|
||||
* Method: isRunning
|
||||
* Signature: (Ljava/lang/String;)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_com_melloware_jintellitype_JIntellitype_isRunning
|
||||
(JNIEnv *, jclass, jstring);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
1
cpp/jintellitype/msvc/copy.bat
Normal file
1
cpp/jintellitype/msvc/copy.bat
Normal file
@@ -0,0 +1 @@
|
||||
copy Release\jintellitype.dll ..\..\..\java\native\
|
||||
20
cpp/jintellitype/msvc/jintellitype.sln
Normal file
20
cpp/jintellitype/msvc/jintellitype.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual C++ Express 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jintellitype", "jintellitype.vcxproj", "{29297EB4-DE7D-4F2B-9FD7-FEB53409AA7D}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{29297EB4-DE7D-4F2B-9FD7-FEB53409AA7D}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{29297EB4-DE7D-4F2B-9FD7-FEB53409AA7D}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{29297EB4-DE7D-4F2B-9FD7-FEB53409AA7D}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{29297EB4-DE7D-4F2B-9FD7-FEB53409AA7D}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
cpp/jintellitype/msvc/jintellitype.suo
Normal file
BIN
cpp/jintellitype/msvc/jintellitype.suo
Normal file
Binary file not shown.
96
cpp/jintellitype/msvc/jintellitype.vcxproj
Normal file
96
cpp/jintellitype/msvc/jintellitype.vcxproj
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{29297EB4-DE7D-4F2B-9FD7-FEB53409AA7D}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>jintellitype</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IncludePath>C:\Program Files %28x86%29\Java\jdk1.6.0_23\include;C:\Program Files %28x86%29\Java\jdk1.6.0_23\include\win32;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IncludePath>C:\Program Files %28x86%29\Java\jdk1.6.0_23\include;C:\Program Files %28x86%29\Java\jdk1.6.0_23\include\win32;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;JINTELLITYPE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;JINTELLITYPE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy.bat</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\JIntellitype.cpp" />
|
||||
<ClCompile Include="..\JIntellitypeHandler.cpp" />
|
||||
<ClCompile Include="..\JIntellitypeThread.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\com_melloware_jintellitype_JIntellitype.h" />
|
||||
<ClInclude Include="..\JIntellitypeHandler.h" />
|
||||
<ClInclude Include="..\JIntellitypeThread.h" />
|
||||
<ClInclude Include="..\JIntellitype_private.h" />
|
||||
<ClInclude Include="..\StdAfx.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
45
cpp/jintellitype/msvc/jintellitype.vcxproj.filters
Normal file
45
cpp/jintellitype/msvc/jintellitype.vcxproj.filters
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\JIntellitypeThread.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\JIntellitypeHandler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\JIntellitype.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\JIntellitypeHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\JIntellitype_private.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\com_melloware_jintellitype_JIntellitype.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\JIntellitypeThread.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
3
cpp/jintellitype/msvc/jintellitype.vcxproj.user
Normal file
3
cpp/jintellitype/msvc/jintellitype.vcxproj.user
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
||||
190
cpp/wiiuse/classic.c
Normal file
190
cpp/wiiuse/classic.c
Normal file
@@ -0,0 +1,190 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "classic.h"
|
||||
|
||||
static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the classic controller.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @return Returns 1 if handshake was successful, 0 if not.
|
||||
*/
|
||||
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len) {
|
||||
int i;
|
||||
int offset = 0;
|
||||
|
||||
cc->btns = 0;
|
||||
cc->btns_held = 0;
|
||||
cc->btns_released = 0;
|
||||
cc->r_shoulder = 0;
|
||||
cc->l_shoulder = 0;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < len; ++i)
|
||||
data[i] = (data[i] ^ 0x17) + 0x17;
|
||||
|
||||
if (data[offset] == 0xFF) {
|
||||
/*
|
||||
* Sometimes the data returned here is not correct.
|
||||
* This might happen because the wiimote is lagging
|
||||
* behind our initialization sequence.
|
||||
* To fix this just request the handshake again.
|
||||
*
|
||||
* Other times it's just the first 16 bytes are 0xFF,
|
||||
* but since the next 16 bytes are the same, just use
|
||||
* those.
|
||||
*/
|
||||
if (data[offset + 16] == 0xFF) {
|
||||
/* get the calibration data */
|
||||
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||
|
||||
WIIUSE_DEBUG("Classic controller handshake appears invalid, trying again.");
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
||||
return 0;
|
||||
} else
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
|
||||
/* joystick stuff */
|
||||
cc->ljs.max.x = data[0 + offset] / 4;
|
||||
cc->ljs.min.x = data[1 + offset] / 4;
|
||||
cc->ljs.center.x = data[2 + offset] / 4;
|
||||
cc->ljs.max.y = data[3 + offset] / 4;
|
||||
cc->ljs.min.y = data[4 + offset] / 4;
|
||||
cc->ljs.center.y = data[5 + offset] / 4;
|
||||
|
||||
cc->rjs.max.x = data[6 + offset] / 8;
|
||||
cc->rjs.min.x = data[7 + offset] / 8;
|
||||
cc->rjs.center.x = data[8 + offset] / 8;
|
||||
cc->rjs.max.y = data[9 + offset] / 8;
|
||||
cc->rjs.min.y = data[10 + offset] / 8;
|
||||
cc->rjs.center.y = data[11 + offset] / 8;
|
||||
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_CLASSIC;
|
||||
|
||||
#ifdef WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The classic controller disconnected.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
*/
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc) {
|
||||
memset(cc, 0, sizeof(struct classic_ctrl_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle classic controller event.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg) {
|
||||
int i, lx, ly, rx, ry;
|
||||
byte l, r;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
classic_ctrl_pressed_buttons(cc, BIG_ENDIAN_SHORT(*(short*)(msg + 4)));
|
||||
|
||||
/* left/right buttons */
|
||||
l = (((msg[2] & 0x60) >> 2) | ((msg[3] & 0xE0) >> 5));
|
||||
r = (msg[3] & 0x1F);
|
||||
|
||||
/*
|
||||
* TODO - LR range hardcoded from 0x00 to 0x1F.
|
||||
* This is probably in the calibration somewhere.
|
||||
*/
|
||||
cc->r_shoulder = ((float)r / 0x1F);
|
||||
cc->l_shoulder = ((float)l / 0x1F);
|
||||
|
||||
/* calculate joystick orientation */
|
||||
lx = (msg[0] & 0x3F);
|
||||
ly = (msg[1] & 0x3F);
|
||||
rx = ((msg[0] & 0xC0) >> 3) | ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7);
|
||||
ry = (msg[2] & 0x1F);
|
||||
|
||||
calc_joystick_state(&cc->ljs, lx, ly);
|
||||
calc_joystick_state(&cc->rjs, rx, ry);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void classic_ctrl_pressed_buttons(struct classic_ctrl_t* cc, short now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & CLASSIC_CTRL_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
cc->btns_held = (now & cc->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
cc->btns_released = ((cc->btns | cc->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
cc->btns = now;
|
||||
}
|
||||
53
cpp/wiiuse/classic.h
Normal file
53
cpp/wiiuse/classic.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
|
||||
#ifndef CLASSIC_H_INCLUDED
|
||||
#define CLASSIC_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte* data, unsigned short len);
|
||||
|
||||
void classic_ctrl_disconnected(struct classic_ctrl_t* cc);
|
||||
|
||||
void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CLASSIC_H_INCLUDED
|
||||
79
cpp/wiiuse/definitions.h
Normal file
79
cpp/wiiuse/definitions.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief General definitions.
|
||||
*/
|
||||
|
||||
#ifndef DEFINITIONS_H_INCLUDED
|
||||
#define DEFINITIONS_H_INCLUDED
|
||||
|
||||
/* this is wiiuse - used to distinguish from third party programs using wiiuse.h */
|
||||
#include "os.h"
|
||||
|
||||
#define WIIMOTE_PI 3.14159265f
|
||||
|
||||
//#define WITH_WIIUSE_DEBUG
|
||||
|
||||
/* Error output macros */
|
||||
#define WIIUSE_ERROR(fmt, ...) fprintf(stderr, "[ERROR] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
/* Warning output macros */
|
||||
#define WIIUSE_WARNING(fmt, ...) fprintf(stderr, "[WARNING] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
/* Information output macros */
|
||||
#define WIIUSE_INFO(fmt, ...) fprintf(stderr, "[INFO] " fmt "\n", ##__VA_ARGS__)
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
#ifdef WIN32
|
||||
#define WIIUSE_DEBUG(fmt, ...) do { \
|
||||
char* file = __FILE__; \
|
||||
int i = strlen(file) - 1; \
|
||||
for (; i && (file[i] != '\\'); --i); \
|
||||
fprintf(stderr, "[DEBUG] %s:%i: " fmt "\n", file+i+1, __LINE__, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
#else
|
||||
#define WIIUSE_DEBUG(fmt, ...) fprintf(stderr, "[DEBUG] " __FILE__ ":%i: " fmt "\n", __LINE__, ##__VA_ARGS__)
|
||||
#endif
|
||||
#else
|
||||
#define WIIUSE_DEBUG(fmt, ...)
|
||||
#endif
|
||||
|
||||
/* Convert between radians and degrees */
|
||||
#define RAD_TO_DEGREE(r) ((r * 180.0f) / WIIMOTE_PI)
|
||||
#define DEGREE_TO_RAD(d) (d * (WIIMOTE_PI / 180.0f))
|
||||
|
||||
/* Convert to big endian */
|
||||
#define BIG_ENDIAN_LONG(i) (htonl(i))
|
||||
#define BIG_ENDIAN_SHORT(i) (htons(i))
|
||||
|
||||
#define absf(x) ((x >= 0) ? (x) : (x * -1.0f))
|
||||
#define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x)))
|
||||
|
||||
#endif // DEFINITIONS_H_INCLUDED
|
||||
228
cpp/wiiuse/dynamics.c
Normal file
228
cpp/wiiuse/dynamics.c
Normal file
@@ -0,0 +1,228 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles the dynamics of the wiimote.
|
||||
*
|
||||
* The file includes functions that handle the dynamics
|
||||
* of the wiimote. Such dynamics include orientation and
|
||||
* motion sensing.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <float.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "ir.h"
|
||||
#include "dynamics.h"
|
||||
|
||||
/**
|
||||
* @brief Calculate the roll, pitch, yaw.
|
||||
*
|
||||
* @param ac An accelerometer (accel_t) structure.
|
||||
* @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data.
|
||||
* @param orient [out] Pointer to a orient_t structure that will hold the orientation data.
|
||||
* @param rorient [out] Pointer to a orient_t structure that will hold the non-smoothed orientation data.
|
||||
* @param smooth If smoothing should be performed on the angles calculated. 1 to enable, 0 to disable.
|
||||
*
|
||||
* Given the raw acceleration data from the accelerometer struct, calculate
|
||||
* the orientation of the device and set it in the \a orient parameter.
|
||||
*/
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth) {
|
||||
float xg, yg, zg;
|
||||
float x, y, z;
|
||||
|
||||
/*
|
||||
* roll - use atan(z / x) [ ranges from -180 to 180 ]
|
||||
* pitch - use atan(z / y) [ ranges from -180 to 180 ]
|
||||
* yaw - impossible to tell without IR
|
||||
*/
|
||||
|
||||
/* yaw - set to 0, IR will take care of it if it's enabled */
|
||||
orient->yaw = 0.0f;
|
||||
|
||||
/* find out how much it has to move to be 1g */
|
||||
xg = (float)ac->cal_g.x;
|
||||
yg = (float)ac->cal_g.y;
|
||||
zg = (float)ac->cal_g.z;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
x = ((float)accel->x - (float)ac->cal_zero.x) / xg;
|
||||
y = ((float)accel->y - (float)ac->cal_zero.y) / yg;
|
||||
z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||
|
||||
/* make sure x,y,z are between -1 and 1 for the tan functions */
|
||||
if (x < -1.0f) x = -1.0f;
|
||||
else if (x > 1.0f) x = 1.0f;
|
||||
if (y < -1.0f) y = -1.0f;
|
||||
else if (y > 1.0f) y = 1.0f;
|
||||
if (z < -1.0f) z = -1.0f;
|
||||
else if (z > 1.0f) z = 1.0f;
|
||||
|
||||
/* if it is over 1g then it is probably accelerating and not reliable */
|
||||
if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) {
|
||||
/* roll */
|
||||
x = RAD_TO_DEGREE(atan2f(x, z));
|
||||
|
||||
orient->roll = x;
|
||||
orient->a_roll = x;
|
||||
}
|
||||
|
||||
if (abs(accel->y - ac->cal_zero.y) <= ac->cal_g.y) {
|
||||
/* pitch */
|
||||
y = RAD_TO_DEGREE(atan2f(y, z));
|
||||
|
||||
orient->pitch = y;
|
||||
orient->a_pitch = y;
|
||||
}
|
||||
|
||||
/* smooth the angles if enabled */
|
||||
if (smooth) {
|
||||
apply_smoothing(ac, orient, SMOOTH_ROLL);
|
||||
apply_smoothing(ac, orient, SMOOTH_PITCH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the gravity forces on each axis.
|
||||
*
|
||||
* @param ac An accelerometer (accel_t) structure.
|
||||
* @param accel [in] Pointer to a vec3b_t structure that holds the raw acceleration data.
|
||||
* @param gforce [out] Pointer to a gforce_t structure that will hold the gravity force data.
|
||||
*/
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce) {
|
||||
float xg, yg, zg;
|
||||
|
||||
/* find out how much it has to move to be 1g */
|
||||
xg = (float)ac->cal_g.x;
|
||||
yg = (float)ac->cal_g.y;
|
||||
zg = (float)ac->cal_g.z;
|
||||
|
||||
/* find out how much it actually moved and normalize to +/- 1g */
|
||||
gforce->x = ((float)accel->x - (float)ac->cal_zero.x) / xg;
|
||||
gforce->y = ((float)accel->y - (float)ac->cal_zero.y) / yg;
|
||||
gforce->z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the angle and magnitude of a joystick.
|
||||
*
|
||||
* @param js [out] Pointer to a joystick_t structure.
|
||||
* @param x The raw x-axis value.
|
||||
* @param y The raw y-axis value.
|
||||
*/
|
||||
void calc_joystick_state(struct joystick_t* js, float x, float y) {
|
||||
float rx, ry, ang;
|
||||
|
||||
/*
|
||||
* Since the joystick center may not be exactly:
|
||||
* (min + max) / 2
|
||||
* Then the range from the min to the center and the center to the max
|
||||
* may be different.
|
||||
* Because of this, depending on if the current x or y value is greater
|
||||
* or less than the assoicated axis center value, it needs to be interpolated
|
||||
* between the center and the minimum or maxmimum rather than between
|
||||
* the minimum and maximum.
|
||||
*
|
||||
* So we have something like this:
|
||||
* (x min) [-1] ---------*------ [0] (x center) [0] -------- [1] (x max)
|
||||
* Where the * is the current x value.
|
||||
* The range is therefore -1 to 1, 0 being the exact center rather than
|
||||
* the middle of min and max.
|
||||
*/
|
||||
if (x == js->center.x)
|
||||
rx = 0;
|
||||
else if (x >= js->center.x)
|
||||
rx = ((float)(x - js->center.x) / (float)(js->max.x - js->center.x));
|
||||
else
|
||||
rx = ((float)(x - js->min.x) / (float)(js->center.x - js->min.x)) - 1.0f;
|
||||
|
||||
if (y == js->center.y)
|
||||
ry = 0;
|
||||
else if (y >= js->center.y)
|
||||
ry = ((float)(y - js->center.y) / (float)(js->max.y - js->center.y));
|
||||
else
|
||||
ry = ((float)(y - js->min.y) / (float)(js->center.y - js->min.y)) - 1.0f;
|
||||
|
||||
/* calculate the joystick angle and magnitude */
|
||||
ang = RAD_TO_DEGREE(atanf(ry / rx));
|
||||
ang -= 90.0f;
|
||||
if (rx < 0.0f)
|
||||
ang -= 180.0f;
|
||||
js->ang = absf(ang);
|
||||
js->mag = (float) sqrt((rx * rx) + (ry * ry));
|
||||
}
|
||||
|
||||
|
||||
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
|
||||
switch (type) {
|
||||
case SMOOTH_ROLL:
|
||||
{
|
||||
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */
|
||||
if (isnan(ac->st_roll) || isinf(ac->st_roll))
|
||||
ac->st_roll = 0.0f;
|
||||
|
||||
/*
|
||||
* If the sign changes (which will happen if going from -180 to 180)
|
||||
* or from (-1 to 1) then don't smooth, just use the new angle.
|
||||
*/
|
||||
if (((ac->st_roll < 0) && (orient->roll > 0)) || ((ac->st_roll > 0) && (orient->roll < 0))) {
|
||||
ac->st_roll = orient->roll;
|
||||
} else {
|
||||
orient->roll = ac->st_roll + (ac->st_alpha * (orient->a_roll - ac->st_roll));
|
||||
ac->st_roll = orient->roll;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
case SMOOTH_PITCH:
|
||||
{
|
||||
if (isnan(ac->st_pitch) || isinf(ac->st_pitch))
|
||||
ac->st_pitch = 0.0f;
|
||||
|
||||
if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) {
|
||||
ac->st_pitch = orient->pitch;
|
||||
} else {
|
||||
orient->pitch = ac->st_pitch + (ac->st_alpha * (orient->a_pitch - ac->st_pitch));
|
||||
ac->st_pitch = orient->pitch;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
cpp/wiiuse/dynamics.h
Normal file
56
cpp/wiiuse/dynamics.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles the dynamics of the wiimote.
|
||||
*
|
||||
* The file includes functions that handle the dynamics
|
||||
* of the wiimote. Such dynamics include orientation and
|
||||
* motion sensing.
|
||||
*/
|
||||
|
||||
#ifndef DYNAMICS_H_INCLUDED
|
||||
#define DYNAMICS_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct orient_t* orient, int smooth);
|
||||
void calculate_gforce(struct accel_t* ac, struct vec3b_t* accel, struct gforce_t* gforce);
|
||||
void calc_joystick_state(struct joystick_t* js, float x, float y);
|
||||
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // DYNAMICS_H_INCLUDED
|
||||
878
cpp/wiiuse/events.c
Normal file
878
cpp/wiiuse/events.c
Normal file
@@ -0,0 +1,878 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles wiimote events.
|
||||
*
|
||||
* The file includes functions that handle the events
|
||||
* that are sent from the wiimote to us.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "io.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "ir.h"
|
||||
#include "nunchuk.h"
|
||||
#include "classic.h"
|
||||
#include "guitar_hero_3.h"
|
||||
#include "events.h"
|
||||
|
||||
static void idle_cycle(struct wiimote_t* wm);
|
||||
static void clear_dirty_reads(struct wiimote_t* wm);
|
||||
static void propagate_event(struct wiimote_t* wm, byte event, byte* msg);
|
||||
static void event_data_read(struct wiimote_t* wm, byte* msg);
|
||||
static void event_status(struct wiimote_t* wm, byte* msg);
|
||||
static void handle_expansion(struct wiimote_t* wm, byte* msg);
|
||||
|
||||
static void save_state(struct wiimote_t* wm);
|
||||
static int state_changed(struct wiimote_t* wm);
|
||||
|
||||
/**
|
||||
* @brief Poll the wiimotes for any events.
|
||||
*
|
||||
* @param wm An array of pointers to wiimote_t structures.
|
||||
* @param wiimotes The number of wiimote_t structures in the \a wm array.
|
||||
*
|
||||
* @return Returns number of wiimotes that an event has occured on.
|
||||
*
|
||||
* It is necessary to poll the wiimote devices for events
|
||||
* that occur. If an event occurs on a particular wiimote,
|
||||
* the event variable will be set.
|
||||
*/
|
||||
int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
|
||||
int evnt = 0;
|
||||
|
||||
#ifndef WIN32
|
||||
/*
|
||||
* *nix
|
||||
*/
|
||||
struct timeval tv;
|
||||
fd_set fds;
|
||||
int r;
|
||||
int i;
|
||||
int highest_fd = -1;
|
||||
|
||||
if (!wm) return 0;
|
||||
|
||||
/* block select() for 1/2000th of a second */
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
/* only poll it if it is connected */
|
||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
|
||||
FD_SET(wm[i]->in_sock, &fds);
|
||||
|
||||
/* find the highest fd of the connected wiimotes */
|
||||
if (wm[i]->in_sock > highest_fd)
|
||||
highest_fd = wm[i]->in_sock;
|
||||
}
|
||||
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
}
|
||||
|
||||
if (highest_fd == -1)
|
||||
/* nothing to poll */
|
||||
return 0;
|
||||
|
||||
if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
|
||||
WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
|
||||
perror("Error Details");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* check each socket for an event */
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
/* if this wiimote is not connected, skip it */
|
||||
if (!WIIMOTE_IS_CONNECTED(wm[i]))
|
||||
continue;
|
||||
|
||||
if (FD_ISSET(wm[i]->in_sock, &fds)) {
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
|
||||
/* clear out any old read requests */
|
||||
clear_dirty_reads(wm[i]);
|
||||
|
||||
/* read the pending message into the buffer */
|
||||
r = read(wm[i]->in_sock, wm[i]->event_buf, sizeof(wm[i]->event_buf));
|
||||
if (r == -1) {
|
||||
/* error reading data */
|
||||
WIIUSE_ERROR("Receiving wiimote data (id %i).", wm[i]->unid);
|
||||
perror("Error Details");
|
||||
|
||||
if (errno == ENOTCONN) {
|
||||
/* this can happen if the bluetooth dongle is disconnected */
|
||||
WIIUSE_ERROR("Bluetooth appears to be disconnected. Wiimote unid %i will be disconnected.", wm[i]->unid);
|
||||
wiiuse_disconnect(wm[i]);
|
||||
wm[i]->event = WIIUSE_UNEXPECTED_DISCONNECT;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
if (!r) {
|
||||
/* remote disconnect */
|
||||
wiiuse_disconnected(wm[i]);
|
||||
evnt = 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], wm[i]->event_buf[1], wm[i]->event_buf+2);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
} else {
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
}
|
||||
#else
|
||||
/*
|
||||
* Windows
|
||||
*/
|
||||
int i;
|
||||
|
||||
if (!wm) return 0;
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
if (wiiuse_io_read(wm[i])) {
|
||||
/* propagate the event */
|
||||
propagate_event(wm[i], wm[i]->event_buf[0], wm[i]->event_buf+1);
|
||||
evnt += (wm[i]->event != WIIUSE_NONE);
|
||||
|
||||
/* clear out the event buffer */
|
||||
memset(wm[i]->event_buf, 0, sizeof(wm[i]->event_buf));
|
||||
} else {
|
||||
idle_cycle(wm[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return evnt;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Called on a cycle where no significant change occurs.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void idle_cycle(struct wiimote_t* wm) {
|
||||
/*
|
||||
* Smooth the angles.
|
||||
*
|
||||
* This is done to make sure that on every cycle the orientation
|
||||
* angles are smoothed. Normally when an event occurs the angles
|
||||
* are updated and smoothed, but if no packet comes in then the
|
||||
* angles remain the same. This means the angle wiiuse reports
|
||||
* is still an old value. Smoothing needs to be applied in this
|
||||
* case in order for the angle it reports to converge to the true
|
||||
* angle of the device.
|
||||
*/
|
||||
if (WIIUSE_USING_ACC(wm) && WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING)) {
|
||||
apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_ROLL);
|
||||
apply_smoothing(&wm->accel_calib, &wm->orient, SMOOTH_PITCH);
|
||||
}
|
||||
|
||||
/* clear out any old read requests */
|
||||
clear_dirty_reads(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clear out all old 'dirty' read requests.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void clear_dirty_reads(struct wiimote_t* wm) {
|
||||
struct read_req_t* req = wm->read_req;
|
||||
|
||||
while (req && req->dirty) {
|
||||
WIIUSE_DEBUG("Cleared old read request for address: %x", req->addr);
|
||||
|
||||
wm->read_req = req->next;
|
||||
free(req);
|
||||
req = wm->read_req;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Analyze the event that occured on a wiimote.
|
||||
*
|
||||
* @param wm An array of pointers to wiimote_t structures.
|
||||
* @param event The event that occured.
|
||||
* @param msg The message specified in the event packet.
|
||||
*
|
||||
* Pass the event to the registered event callback.
|
||||
*/
|
||||
static void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
||||
save_state(wm);
|
||||
|
||||
switch (event) {
|
||||
case WM_RPT_BTN:
|
||||
{
|
||||
/* button */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC:
|
||||
{
|
||||
/* button - motion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
wm->accel.x = msg[2];
|
||||
wm->accel.y = msg[3];
|
||||
wm->accel.z = msg[4];
|
||||
|
||||
/* calculate the remote orientation */
|
||||
calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
|
||||
|
||||
/* calculate the gforces on each axis */
|
||||
calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_READ:
|
||||
{
|
||||
/* data read */
|
||||
event_data_read(wm, msg);
|
||||
|
||||
/* yeah buttons may be pressed, but this wasn't an "event" */
|
||||
return;
|
||||
}
|
||||
case WM_RPT_CTRL_STATUS:
|
||||
{
|
||||
/* controller status */
|
||||
event_status(wm, msg);
|
||||
|
||||
/* don't execute the event callback */
|
||||
return;
|
||||
}
|
||||
case WM_RPT_BTN_EXP:
|
||||
{
|
||||
/* button - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
handle_expansion(wm, msg+2);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_EXP:
|
||||
{
|
||||
/* button - motion - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
wm->accel.x = msg[2];
|
||||
wm->accel.y = msg[3];
|
||||
wm->accel.z = msg[4];
|
||||
|
||||
calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
|
||||
calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
|
||||
|
||||
handle_expansion(wm, msg+5);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_IR:
|
||||
{
|
||||
/* button - motion - ir */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
wm->accel.x = msg[2];
|
||||
wm->accel.y = msg[3];
|
||||
wm->accel.z = msg[4];
|
||||
|
||||
calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
|
||||
calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
|
||||
|
||||
/* ir */
|
||||
calculate_extended_ir(wm, msg+5);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_IR_EXP:
|
||||
{
|
||||
/* button - ir - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
handle_expansion(wm, msg+12);
|
||||
|
||||
/* ir */
|
||||
calculate_basic_ir(wm, msg+2);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_BTN_ACC_IR_EXP:
|
||||
{
|
||||
/* button - motion - ir - expansion */
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
wm->accel.x = msg[2];
|
||||
wm->accel.y = msg[3];
|
||||
wm->accel.z = msg[4];
|
||||
|
||||
calculate_orientation(&wm->accel_calib, &wm->accel, &wm->orient, WIIMOTE_IS_FLAG_SET(wm, WIIUSE_SMOOTHING));
|
||||
calculate_gforce(&wm->accel_calib, &wm->accel, &wm->gforce);
|
||||
|
||||
handle_expansion(wm, msg+15);
|
||||
|
||||
/* ir */
|
||||
calculate_basic_ir(wm, msg+5);
|
||||
|
||||
break;
|
||||
}
|
||||
case WM_RPT_WRITE:
|
||||
{
|
||||
/* write feedback - safe to skip */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* was there an event? */
|
||||
if (state_changed(wm))
|
||||
wm->event = WIIUSE_EVENT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg) {
|
||||
short now;
|
||||
|
||||
/* convert to big endian */
|
||||
now = BIG_ENDIAN_SHORT(*(short*)msg) & WIIMOTE_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
wm->btns_held = (now & wm->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
wm->btns_released = ((wm->btns | wm->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
wm->btns = now;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Received a data packet from a read request.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*
|
||||
* Data from the wiimote comes in packets. If the requested
|
||||
* data segment size is bigger than one packet can hold then
|
||||
* several packets will be received. These packets are first
|
||||
* reassembled into one, then the registered callback function
|
||||
* that handles data reads is invoked.
|
||||
*/
|
||||
static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
||||
/* we must always assume the packet received is from the most recent request */
|
||||
byte err;
|
||||
byte len;
|
||||
unsigned short offset;
|
||||
struct read_req_t* req = wm->read_req;
|
||||
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
/* find the next non-dirty request */
|
||||
while (req && req->dirty)
|
||||
req = req->next;
|
||||
|
||||
/* if we don't have a request out then we didn't ask for this packet */
|
||||
if (!req) {
|
||||
WIIUSE_WARNING("Received data packet when no request was made.");
|
||||
return;
|
||||
}
|
||||
|
||||
err = msg[2] & 0x0F;
|
||||
|
||||
if (err == 0x08)
|
||||
WIIUSE_WARNING("Unable to read data - address does not exist.");
|
||||
else if (err == 0x07)
|
||||
WIIUSE_WARNING("Unable to read data - address is for write-only registers.");
|
||||
else if (err)
|
||||
WIIUSE_WARNING("Unable to read data - unknown error code %x.", err);
|
||||
|
||||
if (err) {
|
||||
/* this request errored out, so skip it and go to the next one */
|
||||
|
||||
/* delete this request */
|
||||
wm->read_req = req->next;
|
||||
free(req);
|
||||
|
||||
/* if another request exists send it to the wiimote */
|
||||
if (wm->read_req)
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
len = ((msg[2] & 0xF0) >> 4) + 1;
|
||||
offset = BIG_ENDIAN_SHORT(*(unsigned short*)(msg + 3));
|
||||
req->addr = (req->addr & 0xFFFF);
|
||||
|
||||
req->wait -= len;
|
||||
if (req->wait >= req->size)
|
||||
/* this should never happen */
|
||||
req->wait = 0;
|
||||
|
||||
WIIUSE_DEBUG("Received read packet:");
|
||||
WIIUSE_DEBUG(" Packet read offset: %i bytes", offset);
|
||||
WIIUSE_DEBUG(" Request read offset: %i bytes", req->addr);
|
||||
WIIUSE_DEBUG(" Read offset into buf: %i bytes", offset - req->addr);
|
||||
WIIUSE_DEBUG(" Read data size: %i bytes", len);
|
||||
WIIUSE_DEBUG(" Still need: %i bytes", req->wait);
|
||||
|
||||
/* reconstruct this part of the data */
|
||||
memcpy((req->buf + offset - req->addr), (msg + 5), len);
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int i = 0;
|
||||
printf("Read: ");
|
||||
for (; i < req->size - req->wait; ++i)
|
||||
printf("%x ", req->buf[i]);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* if all data has been received, execute the read event callback or generate event */
|
||||
if (!req->wait) {
|
||||
if (req->cb) {
|
||||
/* this was a callback, so invoke it now */
|
||||
req->cb(wm, req->buf, req->size);
|
||||
|
||||
/* delete this request */
|
||||
wm->read_req = req->next;
|
||||
free(req);
|
||||
} else {
|
||||
/*
|
||||
* This should generate an event.
|
||||
* We need to leave the event in the array so the client
|
||||
* can access it still. We'll flag is as being 'dirty'
|
||||
* and give the client one cycle to use it. Next event
|
||||
* we will remove it from the list.
|
||||
*/
|
||||
wm->event = WIIUSE_READ_DATA;
|
||||
req->dirty = 1;
|
||||
}
|
||||
|
||||
/* if another request exists send it to the wiimote */
|
||||
if (wm->read_req)
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read the controller status.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*
|
||||
* Read the controller status and execute the registered status callback.
|
||||
*/
|
||||
static void event_status(struct wiimote_t* wm, byte* msg) {
|
||||
int led[4] = {0};
|
||||
int attachment = 0;
|
||||
int ir = 0;
|
||||
int exp_changed = 0;
|
||||
|
||||
/*
|
||||
* An event occured.
|
||||
* This event can be overwritten by a more specific
|
||||
* event type during a handshake or expansion removal.
|
||||
*/
|
||||
wm->event = WIIUSE_STATUS;
|
||||
|
||||
wiiuse_pressed_buttons(wm, msg);
|
||||
|
||||
/* find what LEDs are lit */
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) led[0] = 1;
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) led[1] = 1;
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1;
|
||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1;
|
||||
|
||||
/* is an attachment connected to the expansion port? */
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT)
|
||||
attachment = 1;
|
||||
|
||||
/* is the speaker enabled? */
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED)
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
|
||||
|
||||
/* is IR sensing enabled? */
|
||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED)
|
||||
ir = 1;
|
||||
|
||||
/* find the battery level and normalize between 0 and 1 */
|
||||
wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE);
|
||||
|
||||
/* expansion port */
|
||||
if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
/* send the initialization code for the attachment */
|
||||
handshake_expansion(wm, NULL, 0);
|
||||
exp_changed = 1;
|
||||
} else if (!attachment && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||
/* attachment removed */
|
||||
disable_expansion(wm);
|
||||
exp_changed = 1;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if (!attachment) {
|
||||
WIIUSE_DEBUG("Setting timeout to normal %i ms.", wm->normal_timeout);
|
||||
wm->timeout = wm->normal_timeout;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* From now on the remote will only send status packets.
|
||||
* We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
|
||||
* reenable other incoming reports.
|
||||
*/
|
||||
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
/*
|
||||
* Since the expansion status changed IR needs to
|
||||
* be reset for the new IR report mode.
|
||||
*/
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
} else
|
||||
wiiuse_set_report_type(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle data from the expansion.
|
||||
*
|
||||
* @param wm A pointer to a wiimote_t structure.
|
||||
* @param msg The message specified in the event packet for the expansion.
|
||||
*/
|
||||
static void handle_expansion(struct wiimote_t* wm, byte* msg) {
|
||||
switch (wm->exp.type) {
|
||||
case EXP_NUNCHUK:
|
||||
nunchuk_event(&wm->exp.nunchuk, msg);
|
||||
break;
|
||||
case EXP_CLASSIC:
|
||||
classic_ctrl_event(&wm->exp.classic, msg);
|
||||
break;
|
||||
case EXP_GUITAR_HERO_3:
|
||||
guitar_hero_3_event(&wm->exp.gh3, msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the expansion device.
|
||||
*
|
||||
* @param wm A pointer to a wiimote_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* Tries to determine what kind of expansion was attached
|
||||
* and invoke the correct handshake function.
|
||||
*
|
||||
* If the data is NULL then this function will try to start
|
||||
* a handshake with the expansion.
|
||||
*/
|
||||
void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
int id;
|
||||
|
||||
if (!data) {
|
||||
byte* handshake_buf;
|
||||
byte buf = 0x00;
|
||||
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||
disable_expansion(wm);
|
||||
|
||||
/* increase the timeout until the handshake completes */
|
||||
#ifdef WIN32
|
||||
WIIUSE_DEBUG("Setting timeout to expansion %i ms.", wm->exp_timeout);
|
||||
wm->timeout = wm->exp_timeout;
|
||||
#endif
|
||||
|
||||
wiiuse_write_data(wm, WM_EXP_MEM_ENABLE, &buf, 1);
|
||||
|
||||
/* get the calibration data */
|
||||
handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
||||
/* tell the wiimote to send expansion data */
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
id = BIG_ENDIAN_LONG(*(int*)(data + 220));
|
||||
|
||||
/* call the corresponding handshake function for this expansion */
|
||||
switch (id) {
|
||||
case EXP_ID_CODE_NUNCHUK:
|
||||
{
|
||||
if (nunchuk_handshake(wm, &wm->exp.nunchuk, data, len))
|
||||
wm->event = WIIUSE_NUNCHUK_INSERTED;
|
||||
break;
|
||||
}
|
||||
case EXP_ID_CODE_CLASSIC_CONTROLLER:
|
||||
{
|
||||
if (classic_ctrl_handshake(wm, &wm->exp.classic, data, len))
|
||||
wm->event = WIIUSE_CLASSIC_CTRL_INSERTED;
|
||||
break;
|
||||
}
|
||||
case EXP_ID_CODE_GUITAR:
|
||||
{
|
||||
if (guitar_hero_3_handshake(wm, &wm->exp.gh3, data, len))
|
||||
wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disable the expansion device if it was enabled.
|
||||
*
|
||||
* @param wm A pointer to a wiimote_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* If the data is NULL then this function will try to start
|
||||
* a handshake with the expansion.
|
||||
*/
|
||||
void disable_expansion(struct wiimote_t* wm) {
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||
return;
|
||||
|
||||
/* tell the assoicated module the expansion was removed */
|
||||
switch (wm->exp.type) {
|
||||
case EXP_NUNCHUK:
|
||||
nunchuk_disconnected(&wm->exp.nunchuk);
|
||||
wm->event = WIIUSE_NUNCHUK_REMOVED;
|
||||
break;
|
||||
case EXP_CLASSIC:
|
||||
classic_ctrl_disconnected(&wm->exp.classic);
|
||||
wm->event = WIIUSE_CLASSIC_CTRL_REMOVED;
|
||||
break;
|
||||
case EXP_GUITAR_HERO_3:
|
||||
guitar_hero_3_disconnected(&wm->exp.gh3);
|
||||
wm->event = WIIUSE_GUITAR_HERO_3_CTRL_REMOVED;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||
wm->exp.type = EXP_NONE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Save important state data.
|
||||
* @param wm A pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void save_state(struct wiimote_t* wm) {
|
||||
/* wiimote */
|
||||
wm->lstate.btns = wm->btns;
|
||||
wm->lstate.accel = wm->accel;
|
||||
|
||||
/* ir */
|
||||
if (WIIUSE_USING_IR(wm)) {
|
||||
wm->lstate.ir_ax = wm->ir.ax;
|
||||
wm->lstate.ir_ay = wm->ir.ay;
|
||||
wm->lstate.ir_distance = wm->ir.distance;
|
||||
}
|
||||
|
||||
/* expansion */
|
||||
switch (wm->exp.type) {
|
||||
case EXP_NUNCHUK:
|
||||
wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag;
|
||||
wm->lstate.exp_btns = wm->exp.nunchuk.btns;
|
||||
wm->lstate.exp_accel = wm->exp.nunchuk.accel;
|
||||
break;
|
||||
|
||||
case EXP_CLASSIC:
|
||||
wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
|
||||
wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
|
||||
wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag;
|
||||
wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder;
|
||||
wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder;
|
||||
wm->lstate.exp_btns = wm->exp.classic.btns;
|
||||
break;
|
||||
|
||||
case EXP_GUITAR_HERO_3:
|
||||
wm->lstate.exp_ljs_ang = wm->exp.gh3.js.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.gh3.js.mag;
|
||||
wm->lstate.exp_r_shoulder = wm->exp.gh3.whammy_bar;
|
||||
wm->lstate.exp_btns = wm->exp.gh3.btns;
|
||||
break;
|
||||
|
||||
case EXP_NONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Determine if the current state differs significantly from the previous.
|
||||
* @param wm A pointer to a wiimote_t structure.
|
||||
* @return 1 if a significant change occured, 0 if not.
|
||||
*/
|
||||
static int state_changed(struct wiimote_t* wm) {
|
||||
#define STATE_CHANGED(a, b) if (a != b) return 1
|
||||
|
||||
#define CROSS_THRESH(last, now, thresh) \
|
||||
do { \
|
||||
if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
|
||||
if ((diff_f(last.roll, now.roll) >= thresh) || \
|
||||
(diff_f(last.pitch, now.pitch) >= thresh) || \
|
||||
(diff_f(last.yaw, now.yaw) >= thresh)) \
|
||||
{ \
|
||||
last = now; \
|
||||
return 1; \
|
||||
} \
|
||||
} else { \
|
||||
if (last.roll != now.roll) return 1; \
|
||||
if (last.pitch != now.pitch) return 1; \
|
||||
if (last.yaw != now.yaw) return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CROSS_THRESH_XYZ(last, now, thresh) \
|
||||
do { \
|
||||
if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) { \
|
||||
if ((diff_f(last.x, now.x) >= thresh) || \
|
||||
(diff_f(last.y, now.y) >= thresh) || \
|
||||
(diff_f(last.z, now.z) >= thresh)) \
|
||||
{ \
|
||||
last = now; \
|
||||
return 1; \
|
||||
} \
|
||||
} else { \
|
||||
if (last.x != now.x) return 1; \
|
||||
if (last.y != now.y) return 1; \
|
||||
if (last.z != now.z) return 1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* ir */
|
||||
if (WIIUSE_USING_IR(wm)) {
|
||||
STATE_CHANGED(wm->lstate.ir_ax, wm->ir.ax);
|
||||
STATE_CHANGED(wm->lstate.ir_ay, wm->ir.ay);
|
||||
STATE_CHANGED(wm->lstate.ir_distance, wm->ir.distance);
|
||||
}
|
||||
|
||||
/* accelerometer */
|
||||
if (WIIUSE_USING_ACC(wm)) {
|
||||
/* raw accelerometer */
|
||||
CROSS_THRESH_XYZ(wm->lstate.accel, wm->accel, wm->accel_threshold);
|
||||
|
||||
/* orientation */
|
||||
CROSS_THRESH(wm->lstate.orient, wm->orient, wm->orient_threshold);
|
||||
}
|
||||
|
||||
/* expansion */
|
||||
switch (wm->exp.type) {
|
||||
case EXP_NUNCHUK:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
|
||||
|
||||
CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
|
||||
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
||||
break;
|
||||
}
|
||||
case EXP_CLASSIC:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
|
||||
break;
|
||||
}
|
||||
case EXP_GUITAR_HERO_3:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
|
||||
break;
|
||||
}
|
||||
case EXP_NONE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
STATE_CHANGED(wm->lstate.btns, wm->btns);
|
||||
|
||||
return 0;
|
||||
}
|
||||
54
cpp/wiiuse/events.h
Normal file
54
cpp/wiiuse/events.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles wiimote events.
|
||||
*
|
||||
* The file includes functions that handle the events
|
||||
* that are sent from the wiimote to us.
|
||||
*/
|
||||
|
||||
#ifndef EVENTS_H_INCLUDED
|
||||
#define EVENTS_H_INCLUDED
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void wiiuse_pressed_buttons(struct wiimote_t* wm, byte* msg);
|
||||
|
||||
void handshake_expansion(struct wiimote_t* wm, byte* data, unsigned short len);
|
||||
void disable_expansion(struct wiimote_t* wm);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // EVENTS_H_INCLUDED
|
||||
172
cpp/wiiuse/guitar_hero_3.c
Normal file
172
cpp/wiiuse/guitar_hero_3.c
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "guitar_hero_3.h"
|
||||
|
||||
static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the guitar.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @return Returns 1 if handshake was successful, 0 if not.
|
||||
*/
|
||||
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len) {
|
||||
int i;
|
||||
int offset = 0;
|
||||
|
||||
/*
|
||||
* The good fellows that made the Guitar Hero 3 controller
|
||||
* failed to factory calibrate the devices. There is no
|
||||
* calibration data on the device.
|
||||
*/
|
||||
|
||||
gh3->btns = 0;
|
||||
gh3->btns_held = 0;
|
||||
gh3->btns_released = 0;
|
||||
gh3->whammy_bar = 0.0f;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < len; ++i)
|
||||
data[i] = (data[i] ^ 0x17) + 0x17;
|
||||
|
||||
if (data[offset] == 0xFF) {
|
||||
/*
|
||||
* Sometimes the data returned here is not correct.
|
||||
* This might happen because the wiimote is lagging
|
||||
* behind our initialization sequence.
|
||||
* To fix this just request the handshake again.
|
||||
*
|
||||
* Other times it's just the first 16 bytes are 0xFF,
|
||||
* but since the next 16 bytes are the same, just use
|
||||
* those.
|
||||
*/
|
||||
if (data[offset + 16] == 0xFF) {
|
||||
/* get the calibration data */
|
||||
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||
|
||||
WIIUSE_DEBUG("Guitar Hero 3 handshake appears invalid, trying again.");
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
||||
return 0;
|
||||
} else
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
/* joystick stuff */
|
||||
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;
|
||||
gh3->js.min.x = GUITAR_HERO_3_JS_MIN_X;
|
||||
gh3->js.center.x = GUITAR_HERO_3_JS_CENTER_X;
|
||||
gh3->js.max.y = GUITAR_HERO_3_JS_MAX_Y;
|
||||
gh3->js.min.y = GUITAR_HERO_3_JS_MIN_Y;
|
||||
gh3->js.center.y = GUITAR_HERO_3_JS_CENTER_Y;
|
||||
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_GUITAR_HERO_3;
|
||||
|
||||
#ifdef WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The guitar disconnected.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
*/
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3) {
|
||||
memset(gh3, 0, sizeof(struct guitar_hero_3_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle guitar event.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg) {
|
||||
int i;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
guitar_hero_3_pressed_buttons(gh3, BIG_ENDIAN_SHORT(*(short*)(msg + 4)));
|
||||
|
||||
/* whammy bar */
|
||||
gh3->whammy_bar = (msg[3] - GUITAR_HERO_3_WHAMMY_BAR_MIN) / (float)(GUITAR_HERO_3_WHAMMY_BAR_MAX - GUITAR_HERO_3_WHAMMY_BAR_MIN);
|
||||
|
||||
/* joy stick */
|
||||
calc_joystick_state(&gh3->js, msg[0], msg[1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param cc A pointer to a classic_ctrl_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void guitar_hero_3_pressed_buttons(struct guitar_hero_3_t* gh3, short now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & GUITAR_HERO_3_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
gh3->btns_held = (now & gh3->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
gh3->btns_released = ((gh3->btns | gh3->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
gh3->btns = now;
|
||||
}
|
||||
62
cpp/wiiuse/guitar_hero_3.h
Normal file
62
cpp/wiiuse/guitar_hero_3.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
|
||||
#ifndef GUITAR_HERO_3_H_INCLUDED
|
||||
#define GUITAR_HERO_3_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#define GUITAR_HERO_3_JS_MIN_X 0xC5
|
||||
#define GUITAR_HERO_3_JS_MAX_X 0xFC
|
||||
#define GUITAR_HERO_3_JS_CENTER_X 0xE0
|
||||
#define GUITAR_HERO_3_JS_MIN_Y 0xC5
|
||||
#define GUITAR_HERO_3_JS_MAX_Y 0xFA
|
||||
#define GUITAR_HERO_3_JS_CENTER_Y 0xE0
|
||||
#define GUITAR_HERO_3_WHAMMY_BAR_MIN 0xEF
|
||||
#define GUITAR_HERO_3_WHAMMY_BAR_MAX 0xFA
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, byte* data, unsigned short len);
|
||||
|
||||
void guitar_hero_3_disconnected(struct guitar_hero_3_t* gh3);
|
||||
|
||||
void guitar_hero_3_event(struct guitar_hero_3_t* gh3, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GUITAR_HERO_3_H_INCLUDED
|
||||
1788
cpp/wiiuse/include/hidpi.h
Normal file
1788
cpp/wiiuse/include/hidpi.h
Normal file
File diff suppressed because it is too large
Load Diff
487
cpp/wiiuse/include/hidsdi.h
Normal file
487
cpp/wiiuse/include/hidsdi.h
Normal file
@@ -0,0 +1,487 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
HIDSDI.H
|
||||
|
||||
Abstract:
|
||||
|
||||
This module contains the PUBLIC definitions for the
|
||||
code that implements the HID dll.
|
||||
|
||||
Environment:
|
||||
|
||||
Kernel & user mode
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
#ifndef _HIDSDI_H
|
||||
#define _HIDSDI_H
|
||||
|
||||
#include <pshpack4.h>
|
||||
|
||||
//#include "wtypes.h"
|
||||
|
||||
//#include <windef.h>
|
||||
//#include <win32.h>
|
||||
//#include <basetyps.h>
|
||||
|
||||
typedef LONG NTSTATUS;
|
||||
#include "hidusage.h"
|
||||
#include "hidpi.h"
|
||||
|
||||
typedef struct _HIDD_CONFIGURATION {
|
||||
PVOID cookie;
|
||||
ULONG size;
|
||||
ULONG RingBufferSize;
|
||||
} HIDD_CONFIGURATION, *PHIDD_CONFIGURATION;
|
||||
|
||||
typedef struct _HIDD_ATTRIBUTES {
|
||||
ULONG Size; // = sizeof (struct _HIDD_ATTRIBUTES)
|
||||
|
||||
//
|
||||
// Vendor ids of this hid device
|
||||
//
|
||||
USHORT VendorID;
|
||||
USHORT ProductID;
|
||||
USHORT VersionNumber;
|
||||
|
||||
//
|
||||
// Additional fields will be added to the end of this structure.
|
||||
//
|
||||
} HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
|
||||
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetAttributes (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PHIDD_ATTRIBUTES Attributes
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Fill in the given HIDD_ATTRIBUTES structure with the attributes of the
|
||||
given hid device.
|
||||
|
||||
--*/
|
||||
|
||||
|
||||
void __stdcall
|
||||
HidD_GetHidGuid (
|
||||
OUT LPGUID HidGuid
|
||||
);
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetPreparsedData (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PHIDP_PREPARSED_DATA * PreparsedData
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Given a handle to a valid Hid Class Device Object, retrieve the preparsed
|
||||
data for the device. This routine will allocate the appropriately
|
||||
sized buffer to hold this preparsed data. It is up to client to call
|
||||
HidP_FreePreparsedData to free the memory allocated to this structure when
|
||||
it is no longer needed.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device that the client obtains using
|
||||
a call to CreateFile on a valid Hid device string name.
|
||||
The string name can be obtained using standard PnP calls.
|
||||
|
||||
PreparsedData An opaque data structure used by other functions in this
|
||||
library to retrieve information about a given device.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful.
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_FreePreparsedData (
|
||||
IN PHIDP_PREPARSED_DATA PreparsedData
|
||||
);
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_FlushQueue (
|
||||
IN HANDLE HidDeviceObject
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Flush the input queue for the given HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device that the client obtains using
|
||||
a call to CreateFile on a valid Hid device string name.
|
||||
The string name can be obtained using standard PnP calls.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetConfiguration (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PHIDD_CONFIGURATION Configuration,
|
||||
IN ULONG ConfigurationLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Get the configuration information for this Hid device
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Configuration A configuration structure. HidD_GetConfiguration MUST
|
||||
be called before the configuration can be modified and
|
||||
set using HidD_SetConfiguration
|
||||
|
||||
ConfigurationLength That is ``sizeof (HIDD_CONFIGURATION)''. Using this
|
||||
parameter, we can later increase the length of the
|
||||
configuration array and not break older apps.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_SetConfiguration (
|
||||
IN HANDLE HidDeviceObject,
|
||||
IN PHIDD_CONFIGURATION Configuration,
|
||||
IN ULONG ConfigurationLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Set the configuration information for this Hid device...
|
||||
|
||||
NOTE: HidD_GetConfiguration must be called to retrieve the current
|
||||
configuration information before this information can be modified
|
||||
and set.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Configuration A configuration structure. HidD_GetConfiguration MUST
|
||||
be called before the configuration can be modified and
|
||||
set using HidD_SetConfiguration
|
||||
|
||||
ConfigurationLength That is ``sizeof (HIDD_CONFIGURATION)''. Using this
|
||||
parameter, we can later increase the length of the
|
||||
configuration array and not break older apps.
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetFeature (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID ReportBuffer,
|
||||
IN ULONG ReportBufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Retrieve a feature report from a HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
ReportBuffer The buffer that the feature report should be placed
|
||||
into. The first byte of the buffer should be set to
|
||||
the report ID of the desired report
|
||||
|
||||
ReportBufferLength The size (in bytes) of ReportBuffer. This value
|
||||
should be greater than or equal to the
|
||||
FeatureReportByteLength field as specified in the
|
||||
HIDP_CAPS structure for the device
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_SetFeature (
|
||||
IN HANDLE HidDeviceObject,
|
||||
IN PVOID ReportBuffer,
|
||||
IN ULONG ReportBufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Send a feature report to a HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
ReportBuffer The buffer of the feature report to send to the device
|
||||
|
||||
ReportBufferLength The size (in bytes) of ReportBuffer. This value
|
||||
should be greater than or equal to the
|
||||
FeatureReportByteLength field as specified in the
|
||||
HIDP_CAPS structure for the device
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetInputReport (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID ReportBuffer,
|
||||
IN ULONG ReportBufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Retrieve an input report from a HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
ReportBuffer The buffer that the input report should be placed
|
||||
into. The first byte of the buffer should be set to
|
||||
the report ID of the desired report
|
||||
|
||||
ReportBufferLength The size (in bytes) of ReportBuffer. This value
|
||||
should be greater than or equal to the
|
||||
InputReportByteLength field as specified in the
|
||||
HIDP_CAPS structure for the device
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_SetOutputReport (
|
||||
IN HANDLE HidDeviceObject,
|
||||
IN PVOID ReportBuffer,
|
||||
IN ULONG ReportBufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
Send an output report to a HID device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
ReportBuffer The buffer of the output report to send to the device
|
||||
|
||||
ReportBufferLength The size (in bytes) of ReportBuffer. This value
|
||||
should be greater than or equal to the
|
||||
OutputReportByteLength field as specified in the
|
||||
HIDP_CAPS structure for the device
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetNumInputBuffers (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PULONG NumberBuffers
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function returns the number of input buffers used by the specified
|
||||
file handle to the Hid device. Each file object has a number of buffers
|
||||
associated with it to queue reports read from the device but which have
|
||||
not yet been read by the user-mode app with a handle to that device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
NumberBuffers Number of buffers currently being used for this file
|
||||
handle to the Hid device
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_SetNumInputBuffers (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT ULONG NumberBuffers
|
||||
);
|
||||
/*++
|
||||
|
||||
Routine Description:
|
||||
This function sets the number of input buffers used by the specified
|
||||
file handle to the Hid device. Each file object has a number of buffers
|
||||
associated with it to queue reports read from the device but which have
|
||||
not yet been read by the user-mode app with a handle to that device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
NumberBuffers New number of buffers to use for this file handle to
|
||||
the Hid device
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetPhysicalDescriptor (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the raw physical descriptor for the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the physical
|
||||
descriptor if one exists for the specified device
|
||||
handle
|
||||
|
||||
BufferLength Length of buffer (in bytes)
|
||||
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetManufacturerString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the manufacturer string from the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the manufacturer
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetProductString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the product string from the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the product
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetIndexedString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
IN ULONG StringIndex,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves a string from the specified Hid device that is
|
||||
specified with a certain string index.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
StringIndex Index of the string to retrieve
|
||||
|
||||
Buffer Buffer which on return will contain the product
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetSerialNumberString (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the serial number string from the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the serial number
|
||||
string returned from the device. This string is a
|
||||
wide-character string
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
BOOLEAN __stdcall
|
||||
HidD_GetMsGenreDescriptor (
|
||||
IN HANDLE HidDeviceObject,
|
||||
OUT PVOID Buffer,
|
||||
IN ULONG BufferLength
|
||||
);
|
||||
/*++
|
||||
Routine Description:
|
||||
This function retrieves the Microsoft Genre descriptor from the specified
|
||||
Hid device.
|
||||
|
||||
Arguments:
|
||||
HidDeviceObject A handle to a Hid Device Object.
|
||||
|
||||
Buffer Buffer which on return will contain the descriptor
|
||||
returned from the device.
|
||||
|
||||
BufferLength Length of Buffer (in bytes)
|
||||
|
||||
Return Value:
|
||||
TRUE if successful
|
||||
FALSE otherwise -- Use GetLastError() to get extended error information
|
||||
--*/
|
||||
|
||||
|
||||
#include <poppack.h>
|
||||
|
||||
#endif
|
||||
|
||||
271
cpp/wiiuse/include/hidusage.h
Normal file
271
cpp/wiiuse/include/hidusage.h
Normal file
@@ -0,0 +1,271 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
HIDUSAGE.H
|
||||
|
||||
Abstract:
|
||||
|
||||
Public Definitions of HID USAGES.
|
||||
|
||||
Environment:
|
||||
|
||||
Kernel & user mode
|
||||
|
||||
--*/
|
||||
|
||||
#ifndef __HIDUSAGE_H__
|
||||
#define __HIDUSAGE_H__
|
||||
|
||||
//
|
||||
// Usage Pages
|
||||
//
|
||||
|
||||
typedef USHORT USAGE, *PUSAGE;
|
||||
|
||||
#define HID_USAGE_PAGE_UNDEFINED ((USAGE) 0x00)
|
||||
#define HID_USAGE_PAGE_GENERIC ((USAGE) 0x01)
|
||||
#define HID_USAGE_PAGE_SIMULATION ((USAGE) 0x02)
|
||||
#define HID_USAGE_PAGE_VR ((USAGE) 0x03)
|
||||
#define HID_USAGE_PAGE_SPORT ((USAGE) 0x04)
|
||||
#define HID_USAGE_PAGE_GAME ((USAGE) 0x05)
|
||||
#define HID_USAGE_PAGE_KEYBOARD ((USAGE) 0x07)
|
||||
#define HID_USAGE_PAGE_LED ((USAGE) 0x08)
|
||||
#define HID_USAGE_PAGE_BUTTON ((USAGE) 0x09)
|
||||
#define HID_USAGE_PAGE_ORDINAL ((USAGE) 0x0A)
|
||||
#define HID_USAGE_PAGE_TELEPHONY ((USAGE) 0x0B)
|
||||
#define HID_USAGE_PAGE_CONSUMER ((USAGE) 0x0C)
|
||||
#define HID_USAGE_PAGE_DIGITIZER ((USAGE) 0x0D)
|
||||
#define HID_USAGE_PAGE_UNICODE ((USAGE) 0x10)
|
||||
#define HID_USAGE_PAGE_ALPHANUMERIC ((USAGE) 0x14)
|
||||
|
||||
|
||||
//
|
||||
// Usages from Generic Desktop Page (0x01)
|
||||
//
|
||||
|
||||
#define HID_USAGE_GENERIC_POINTER ((USAGE) 0x01)
|
||||
#define HID_USAGE_GENERIC_MOUSE ((USAGE) 0x02)
|
||||
#define HID_USAGE_GENERIC_JOYSTICK ((USAGE) 0x04)
|
||||
#define HID_USAGE_GENERIC_GAMEPAD ((USAGE) 0x05)
|
||||
#define HID_USAGE_GENERIC_KEYBOARD ((USAGE) 0x06)
|
||||
#define HID_USAGE_GENERIC_KEYPAD ((USAGE) 0x07)
|
||||
#define HID_USAGE_GENERIC_SYSTEM_CTL ((USAGE) 0x80)
|
||||
|
||||
#define HID_USAGE_GENERIC_X ((USAGE) 0x30)
|
||||
#define HID_USAGE_GENERIC_Y ((USAGE) 0x31)
|
||||
#define HID_USAGE_GENERIC_Z ((USAGE) 0x32)
|
||||
#define HID_USAGE_GENERIC_RX ((USAGE) 0x33)
|
||||
#define HID_USAGE_GENERIC_RY ((USAGE) 0x34)
|
||||
#define HID_USAGE_GENERIC_RZ ((USAGE) 0x35)
|
||||
#define HID_USAGE_GENERIC_SLIDER ((USAGE) 0x36)
|
||||
#define HID_USAGE_GENERIC_DIAL ((USAGE) 0x37)
|
||||
#define HID_USAGE_GENERIC_WHEEL ((USAGE) 0x38)
|
||||
#define HID_USAGE_GENERIC_HATSWITCH ((USAGE) 0x39)
|
||||
#define HID_USAGE_GENERIC_COUNTED_BUFFER ((USAGE) 0x3A)
|
||||
#define HID_USAGE_GENERIC_BYTE_COUNT ((USAGE) 0x3B)
|
||||
#define HID_USAGE_GENERIC_MOTION_WAKEUP ((USAGE) 0x3C)
|
||||
#define HID_USAGE_GENERIC_VX ((USAGE) 0x40)
|
||||
#define HID_USAGE_GENERIC_VY ((USAGE) 0x41)
|
||||
#define HID_USAGE_GENERIC_VZ ((USAGE) 0x42)
|
||||
#define HID_USAGE_GENERIC_VBRX ((USAGE) 0x43)
|
||||
#define HID_USAGE_GENERIC_VBRY ((USAGE) 0x44)
|
||||
#define HID_USAGE_GENERIC_VBRZ ((USAGE) 0x45)
|
||||
#define HID_USAGE_GENERIC_VNO ((USAGE) 0x46)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_POWER ((USAGE) 0x81)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_SLEEP ((USAGE) 0x82)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_WAKE ((USAGE) 0x83)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_CONTEXT_MENU ((USAGE) 0x84)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MAIN_MENU ((USAGE) 0x85)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_APP_MENU ((USAGE) 0x86)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_HELP_MENU ((USAGE) 0x87)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_EXIT ((USAGE) 0x88)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_SELECT ((USAGE) 0x89)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_RIGHT ((USAGE) 0x8A)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_LEFT ((USAGE) 0x8B)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_UP ((USAGE) 0x8C)
|
||||
#define HID_USAGE_GENERIC_SYSCTL_MENU_DOWN ((USAGE) 0x8D)
|
||||
|
||||
//
|
||||
// Usages from Simulation Controls Page (0x02)
|
||||
//
|
||||
|
||||
#define HID_USAGE_SIMULATION_RUDDER ((USAGE) 0xBA)
|
||||
#define HID_USAGE_SIMULATION_THROTTLE ((USAGE) 0xBB)
|
||||
|
||||
//
|
||||
// Virtual Reality Controls Page (0x03)
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Sport Controls Page (0x04)
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Game Controls Page (0x05)
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Keyboard/Keypad Page (0x07)
|
||||
//
|
||||
|
||||
// Error "keys"
|
||||
#define HID_USAGE_KEYBOARD_NOEVENT ((USAGE) 0x00)
|
||||
#define HID_USAGE_KEYBOARD_ROLLOVER ((USAGE) 0x01)
|
||||
#define HID_USAGE_KEYBOARD_POSTFAIL ((USAGE) 0x02)
|
||||
#define HID_USAGE_KEYBOARD_UNDEFINED ((USAGE) 0x03)
|
||||
|
||||
// Letters
|
||||
#define HID_USAGE_KEYBOARD_aA ((USAGE) 0x04)
|
||||
#define HID_USAGE_KEYBOARD_zZ ((USAGE) 0x1D)
|
||||
// Numbers
|
||||
#define HID_USAGE_KEYBOARD_ONE ((USAGE) 0x1E)
|
||||
#define HID_USAGE_KEYBOARD_ZERO ((USAGE) 0x27)
|
||||
// Modifier Keys
|
||||
#define HID_USAGE_KEYBOARD_LCTRL ((USAGE) 0xE0)
|
||||
#define HID_USAGE_KEYBOARD_LSHFT ((USAGE) 0xE1)
|
||||
#define HID_USAGE_KEYBOARD_LALT ((USAGE) 0xE2)
|
||||
#define HID_USAGE_KEYBOARD_LGUI ((USAGE) 0xE3)
|
||||
#define HID_USAGE_KEYBOARD_RCTRL ((USAGE) 0xE4)
|
||||
#define HID_USAGE_KEYBOARD_RSHFT ((USAGE) 0xE5)
|
||||
#define HID_USAGE_KEYBOARD_RALT ((USAGE) 0xE6)
|
||||
#define HID_USAGE_KEYBOARD_RGUI ((USAGE) 0xE7)
|
||||
#define HID_USAGE_KEYBOARD_SCROLL_LOCK ((USAGE) 0x47)
|
||||
#define HID_USAGE_KEYBOARD_NUM_LOCK ((USAGE) 0x53)
|
||||
#define HID_USAGE_KEYBOARD_CAPS_LOCK ((USAGE) 0x39)
|
||||
// Funtion keys
|
||||
#define HID_USAGE_KEYBOARD_F1 ((USAGE) 0x3A)
|
||||
#define HID_USAGE_KEYBOARD_F12 ((USAGE) 0x45)
|
||||
|
||||
#define HID_USAGE_KEYBOARD_RETURN ((USAGE) 0x28)
|
||||
#define HID_USAGE_KEYBOARD_ESCAPE ((USAGE) 0x29)
|
||||
#define HID_USAGE_KEYBOARD_DELETE ((USAGE) 0x2A)
|
||||
|
||||
#define HID_USAGE_KEYBOARD_PRINT_SCREEN ((USAGE) 0x46)
|
||||
|
||||
// and hundreds more...
|
||||
|
||||
//
|
||||
// LED Page (0x08)
|
||||
//
|
||||
|
||||
#define HID_USAGE_LED_NUM_LOCK ((USAGE) 0x01)
|
||||
#define HID_USAGE_LED_CAPS_LOCK ((USAGE) 0x02)
|
||||
#define HID_USAGE_LED_SCROLL_LOCK ((USAGE) 0x03)
|
||||
#define HID_USAGE_LED_COMPOSE ((USAGE) 0x04)
|
||||
#define HID_USAGE_LED_KANA ((USAGE) 0x05)
|
||||
#define HID_USAGE_LED_POWER ((USAGE) 0x06)
|
||||
#define HID_USAGE_LED_SHIFT ((USAGE) 0x07)
|
||||
#define HID_USAGE_LED_DO_NOT_DISTURB ((USAGE) 0x08)
|
||||
#define HID_USAGE_LED_MUTE ((USAGE) 0x09)
|
||||
#define HID_USAGE_LED_TONE_ENABLE ((USAGE) 0x0A)
|
||||
#define HID_USAGE_LED_HIGH_CUT_FILTER ((USAGE) 0x0B)
|
||||
#define HID_USAGE_LED_LOW_CUT_FILTER ((USAGE) 0x0C)
|
||||
#define HID_USAGE_LED_EQUALIZER_ENABLE ((USAGE) 0x0D)
|
||||
#define HID_USAGE_LED_SOUND_FIELD_ON ((USAGE) 0x0E)
|
||||
#define HID_USAGE_LED_SURROUND_FIELD_ON ((USAGE) 0x0F)
|
||||
#define HID_USAGE_LED_REPEAT ((USAGE) 0x10)
|
||||
#define HID_USAGE_LED_STEREO ((USAGE) 0x11)
|
||||
#define HID_USAGE_LED_SAMPLING_RATE_DETECT ((USAGE) 0x12)
|
||||
#define HID_USAGE_LED_SPINNING ((USAGE) 0x13)
|
||||
#define HID_USAGE_LED_CAV ((USAGE) 0x14)
|
||||
#define HID_USAGE_LED_CLV ((USAGE) 0x15)
|
||||
#define HID_USAGE_LED_RECORDING_FORMAT_DET ((USAGE) 0x16)
|
||||
#define HID_USAGE_LED_OFF_HOOK ((USAGE) 0x17)
|
||||
#define HID_USAGE_LED_RING ((USAGE) 0x18)
|
||||
#define HID_USAGE_LED_MESSAGE_WAITING ((USAGE) 0x19)
|
||||
#define HID_USAGE_LED_DATA_MODE ((USAGE) 0x1A)
|
||||
#define HID_USAGE_LED_BATTERY_OPERATION ((USAGE) 0x1B)
|
||||
#define HID_USAGE_LED_BATTERY_OK ((USAGE) 0x1C)
|
||||
#define HID_USAGE_LED_BATTERY_LOW ((USAGE) 0x1D)
|
||||
#define HID_USAGE_LED_SPEAKER ((USAGE) 0x1E)
|
||||
#define HID_USAGE_LED_HEAD_SET ((USAGE) 0x1F)
|
||||
#define HID_USAGE_LED_HOLD ((USAGE) 0x20)
|
||||
#define HID_USAGE_LED_MICROPHONE ((USAGE) 0x21)
|
||||
#define HID_USAGE_LED_COVERAGE ((USAGE) 0x22)
|
||||
#define HID_USAGE_LED_NIGHT_MODE ((USAGE) 0x23)
|
||||
#define HID_USAGE_LED_SEND_CALLS ((USAGE) 0x24)
|
||||
#define HID_USAGE_LED_CALL_PICKUP ((USAGE) 0x25)
|
||||
#define HID_USAGE_LED_CONFERENCE ((USAGE) 0x26)
|
||||
#define HID_USAGE_LED_STAND_BY ((USAGE) 0x27)
|
||||
#define HID_USAGE_LED_CAMERA_ON ((USAGE) 0x28)
|
||||
#define HID_USAGE_LED_CAMERA_OFF ((USAGE) 0x29)
|
||||
#define HID_USAGE_LED_ON_LINE ((USAGE) 0x2A)
|
||||
#define HID_USAGE_LED_OFF_LINE ((USAGE) 0x2B)
|
||||
#define HID_USAGE_LED_BUSY ((USAGE) 0x2C)
|
||||
#define HID_USAGE_LED_READY ((USAGE) 0x2D)
|
||||
#define HID_USAGE_LED_PAPER_OUT ((USAGE) 0x2E)
|
||||
#define HID_USAGE_LED_PAPER_JAM ((USAGE) 0x2F)
|
||||
#define HID_USAGE_LED_REMOTE ((USAGE) 0x30)
|
||||
#define HID_USAGE_LED_FORWARD ((USAGE) 0x31)
|
||||
#define HID_USAGE_LED_REVERSE ((USAGE) 0x32)
|
||||
#define HID_USAGE_LED_STOP ((USAGE) 0x33)
|
||||
#define HID_USAGE_LED_REWIND ((USAGE) 0x34)
|
||||
#define HID_USAGE_LED_FAST_FORWARD ((USAGE) 0x35)
|
||||
#define HID_USAGE_LED_PLAY ((USAGE) 0x36)
|
||||
#define HID_USAGE_LED_PAUSE ((USAGE) 0x37)
|
||||
#define HID_USAGE_LED_RECORD ((USAGE) 0x38)
|
||||
#define HID_USAGE_LED_ERROR ((USAGE) 0x39)
|
||||
#define HID_USAGE_LED_SELECTED_INDICATOR ((USAGE) 0x3A)
|
||||
#define HID_USAGE_LED_IN_USE_INDICATOR ((USAGE) 0x3B)
|
||||
#define HID_USAGE_LED_MULTI_MODE_INDICATOR ((USAGE) 0x3C)
|
||||
#define HID_USAGE_LED_INDICATOR_ON ((USAGE) 0x3D)
|
||||
#define HID_USAGE_LED_INDICATOR_FLASH ((USAGE) 0x3E)
|
||||
#define HID_USAGE_LED_INDICATOR_SLOW_BLINK ((USAGE) 0x3F)
|
||||
#define HID_USAGE_LED_INDICATOR_FAST_BLINK ((USAGE) 0x40)
|
||||
#define HID_USAGE_LED_INDICATOR_OFF ((USAGE) 0x41)
|
||||
#define HID_USAGE_LED_FLASH_ON_TIME ((USAGE) 0x42)
|
||||
#define HID_USAGE_LED_SLOW_BLINK_ON_TIME ((USAGE) 0x43)
|
||||
#define HID_USAGE_LED_SLOW_BLINK_OFF_TIME ((USAGE) 0x44)
|
||||
#define HID_USAGE_LED_FAST_BLINK_ON_TIME ((USAGE) 0x45)
|
||||
#define HID_USAGE_LED_FAST_BLINK_OFF_TIME ((USAGE) 0x46)
|
||||
#define HID_USAGE_LED_INDICATOR_COLOR ((USAGE) 0x47)
|
||||
#define HID_USAGE_LED_RED ((USAGE) 0x48)
|
||||
#define HID_USAGE_LED_GREEN ((USAGE) 0x49)
|
||||
#define HID_USAGE_LED_AMBER ((USAGE) 0x4A)
|
||||
#define HID_USAGE_LED_GENERIC_INDICATOR ((USAGE) 0x3B)
|
||||
|
||||
//
|
||||
// Button Page (0x09)
|
||||
//
|
||||
// There is no need to label these usages.
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Ordinal Page (0x0A)
|
||||
//
|
||||
// There is no need to label these usages.
|
||||
//
|
||||
|
||||
|
||||
//
|
||||
// Telephony Device Page (0x0B)
|
||||
//
|
||||
|
||||
#define HID_USAGE_TELEPHONY_PHONE ((USAGE) 0x01)
|
||||
#define HID_USAGE_TELEPHONY_ANSWERING_MACHINE ((USAGE) 0x02)
|
||||
#define HID_USAGE_TELEPHONY_MESSAGE_CONTROLS ((USAGE) 0x03)
|
||||
#define HID_USAGE_TELEPHONY_HANDSET ((USAGE) 0x04)
|
||||
#define HID_USAGE_TELEPHONY_HEADSET ((USAGE) 0x05)
|
||||
#define HID_USAGE_TELEPHONY_KEYPAD ((USAGE) 0x06)
|
||||
#define HID_USAGE_TELEPHONY_PROGRAMMABLE_BUTTON ((USAGE) 0x07)
|
||||
|
||||
//
|
||||
// and others...
|
||||
//
|
||||
|
||||
#define HID_USAGE_CONSUMERCTRL ((USAGE)0x01)
|
||||
#define HID_USAGE_DIGITIZER_PEN ((USAGE)0x02)
|
||||
#define HID_USAGE_DIGITIZER_IN_RANGE ((USAGE)0x32)
|
||||
#define HID_USAGE_DIGITIZER_TIP_SWITCH ((USAGE)0x42)
|
||||
#define HID_USAGE_DIGITIZER_BARREL_SWITCH ((USAGE)0x44)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
119
cpp/wiiuse/io.c
Normal file
119
cpp/wiiuse/io.c
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O (non-OS specific).
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "io.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get initialization data from the wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data unused
|
||||
* @param len unused
|
||||
*
|
||||
* When first called for a wiimote_t structure, a request
|
||||
* is sent to the wiimote for initialization information.
|
||||
* This includes factory set accelerometer data.
|
||||
* The handshake will be concluded when the wiimote responds
|
||||
* with this data.
|
||||
*/
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len) {
|
||||
if (!wm) return;
|
||||
|
||||
switch (wm->handshake_state) {
|
||||
case 0:
|
||||
{
|
||||
/* send request to wiimote for accelerometer calibration */
|
||||
byte* buf;
|
||||
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
|
||||
buf = (byte*)malloc(sizeof(byte) * 8);
|
||||
wiiuse_read_data_cb(wm, wiiuse_handshake, buf, WM_MEM_OFFSET_CALIBRATION, 7);
|
||||
wm->handshake_state++;
|
||||
|
||||
wiiuse_set_leds(wm, WIIMOTE_LED_NONE);
|
||||
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
struct read_req_t* req = wm->read_req;
|
||||
struct accel_t* accel = &wm->accel_calib;
|
||||
|
||||
/* received read data */
|
||||
accel->cal_zero.x = req->buf[0];
|
||||
accel->cal_zero.y = req->buf[1];
|
||||
accel->cal_zero.z = req->buf[2];
|
||||
|
||||
accel->cal_g.x = req->buf[4] - accel->cal_zero.x;
|
||||
accel->cal_g.y = req->buf[5] - accel->cal_zero.y;
|
||||
accel->cal_g.z = req->buf[6] - accel->cal_zero.z;
|
||||
|
||||
/* done with the buffer */
|
||||
free(req->buf);
|
||||
|
||||
/* handshake is done */
|
||||
WIIUSE_DEBUG("Handshake finished. Calibration: Idle: X=%x Y=%x Z=%x\t+1g: X=%x Y=%x Z=%x",
|
||||
accel->cal_zero.x, accel->cal_zero.y, accel->cal_zero.z,
|
||||
accel->cal_g.x, accel->cal_g.y, accel->cal_g.z);
|
||||
|
||||
|
||||
/* request the status of the wiimote to see if there is an expansion */
|
||||
wiiuse_status(wm);
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
||||
wm->handshake_state++;
|
||||
|
||||
/* now enable IR if it was set before the handshake completed */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
56
cpp/wiiuse/io.h
Normal file
56
cpp/wiiuse/io.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O.
|
||||
*/
|
||||
|
||||
#ifndef CONNECT_H_INCLUDED
|
||||
#define CONNECT_H_INCLUDED
|
||||
|
||||
#ifndef WIN32
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, unsigned short len);
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm);
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CONNECT_H_INCLUDED
|
||||
270
cpp/wiiuse/io_nix.c
Normal file
270
cpp/wiiuse/io_nix.c
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for *nix.
|
||||
*/
|
||||
|
||||
#ifndef WIN32
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#include <bluetooth/hci.h>
|
||||
#include <bluetooth/hci_lib.h>
|
||||
#include <bluetooth/l2cap.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "io.h"
|
||||
|
||||
static int wiiuse_connect_single(struct wiimote_t* wm, char* address);
|
||||
|
||||
/**
|
||||
* @brief Find a wiimote or wiimotes.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param max_wiimotes The number of wiimote structures in \a wm.
|
||||
* @param timeout The number of seconds before the search times out.
|
||||
*
|
||||
* @return The number of wiimotes found.
|
||||
*
|
||||
* @see wiimote_connect()
|
||||
*
|
||||
* This function will only look for wiimote devices. \n
|
||||
* When a device is found the address in the structures will be set. \n
|
||||
* You can then call wiimote_connect() to connect to the found \n
|
||||
* devices.
|
||||
*/
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
int device_id;
|
||||
int device_sock;
|
||||
int found_devices;
|
||||
int found_wiimotes;
|
||||
|
||||
/* reset all wiimote bluetooth device addresses */
|
||||
for (found_wiimotes = 0; found_wiimotes < max_wiimotes; ++found_wiimotes)
|
||||
wm[found_wiimotes]->bdaddr = *BDADDR_ANY;
|
||||
found_wiimotes = 0;
|
||||
|
||||
/* get the id of the first bluetooth device. */
|
||||
device_id = hci_get_route(NULL);
|
||||
if (device_id < 0) {
|
||||
perror("hci_get_route");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* create a socket to the device */
|
||||
device_sock = hci_open_dev(device_id);
|
||||
if (device_sock < 0) {
|
||||
perror("hci_open_dev");
|
||||
return 0;
|
||||
}
|
||||
|
||||
inquiry_info scan_info_arr[128];
|
||||
inquiry_info* scan_info = scan_info_arr;
|
||||
memset(&scan_info_arr, 0, sizeof(scan_info_arr));
|
||||
|
||||
/* scan for bluetooth devices for 'timeout' seconds */
|
||||
found_devices = hci_inquiry(device_id, timeout, 128, NULL, &scan_info, IREQ_CACHE_FLUSH);
|
||||
if (found_devices < 0) {
|
||||
perror("hci_inquiry");
|
||||
return 0;
|
||||
}
|
||||
|
||||
WIIUSE_INFO("Found %i bluetooth device(s).", found_devices);
|
||||
|
||||
int i = 0;
|
||||
|
||||
/* display discovered devices */
|
||||
for (; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) {
|
||||
if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2))
|
||||
{
|
||||
/* found a device */
|
||||
ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str);
|
||||
|
||||
WIIUSE_INFO("Found wiimote (%s) [id %i].", wm[found_wiimotes]->bdaddr_str, wm[found_wiimotes]->unid);
|
||||
|
||||
wm[found_wiimotes]->bdaddr = scan_info[i].bdaddr;
|
||||
WIIMOTE_ENABLE_STATE(wm[found_wiimotes], WIIMOTE_STATE_DEV_FOUND);
|
||||
++found_wiimotes;
|
||||
}
|
||||
}
|
||||
|
||||
close(device_sock);
|
||||
return found_wiimotes;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote or wiimotes once an address is known.
|
||||
*
|
||||
* @param wm An array of wiimote_t structures.
|
||||
* @param wiimotes The number of wiimote structures in \a wm.
|
||||
*
|
||||
* @return The number of wiimotes that successfully connected.
|
||||
*
|
||||
* @see wiiuse_find()
|
||||
* @see wiiuse_connect_single()
|
||||
* @see wiiuse_disconnect()
|
||||
*
|
||||
* Connect to a number of wiimotes when the address is already set
|
||||
* in the wiimote_t structures. These addresses are normally set
|
||||
* by the wiiuse_find() function, but can also be set manually.
|
||||
*/
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int connected = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND))
|
||||
/* if the device address is not set, skip it */
|
||||
continue;
|
||||
|
||||
if (wiiuse_connect_single(wm[i], NULL))
|
||||
++connected;
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Connect to a wiimote with a known address.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param address The address of the device to connect to.
|
||||
* If NULL, use the address in the struct set by wiiuse_find().
|
||||
*
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
static int wiiuse_connect_single(struct wiimote_t* wm, char* address) {
|
||||
struct sockaddr_l2 addr;
|
||||
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
|
||||
addr.l2_family = AF_BLUETOOTH;
|
||||
|
||||
if (address)
|
||||
/* use provided address */
|
||||
str2ba(address, &addr.l2_bdaddr);
|
||||
else
|
||||
/* use address of device discovered */
|
||||
addr.l2_bdaddr = wm->bdaddr;
|
||||
|
||||
/*
|
||||
* OUTPUT CHANNEL
|
||||
*/
|
||||
wm->out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
||||
if (wm->out_sock == -1)
|
||||
return 0;
|
||||
|
||||
addr.l2_psm = htobs(WM_OUTPUT_CHANNEL);
|
||||
|
||||
/* connect to wiimote */
|
||||
if (connect(wm->out_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
perror("connect() output sock");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* INPUT CHANNEL
|
||||
*/
|
||||
wm->in_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
||||
if (wm->in_sock == -1) {
|
||||
close(wm->out_sock);
|
||||
wm->out_sock = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
addr.l2_psm = htobs(WM_INPUT_CHANNEL);
|
||||
|
||||
/* connect to wiimote */
|
||||
if (connect(wm->in_sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
|
||||
perror("connect() interrupt sock");
|
||||
close(wm->out_sock);
|
||||
wm->out_sock = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm->unid);
|
||||
|
||||
/* do the handshake */
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
|
||||
wiiuse_set_report_type(wm);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Disconnect a wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiiuse_connect()
|
||||
*
|
||||
* Note that this will not free the wiimote structure.
|
||||
*/
|
||||
void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
close(wm->out_sock);
|
||||
close(wm->in_sock);
|
||||
|
||||
wm->out_sock = -1;
|
||||
wm->in_sock = -1;
|
||||
wm->event = WIIUSE_NONE;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
/* not used */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
|
||||
return write(wm->out_sock, buf, len);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* ifndef WIN32 */
|
||||
247
cpp/wiiuse/io_win.c
Normal file
247
cpp/wiiuse/io_win.c
Normal file
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles device I/O for Windows.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <hidsdi.h>
|
||||
#include <setupapi.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "io.h"
|
||||
|
||||
|
||||
int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
||||
GUID device_id;
|
||||
HANDLE dev;
|
||||
HDEVINFO device_info;
|
||||
int i, index;
|
||||
DWORD len;
|
||||
SP_DEVICE_INTERFACE_DATA device_data;
|
||||
PSP_DEVICE_INTERFACE_DETAIL_DATA detail_data = NULL;
|
||||
HIDD_ATTRIBUTES attr;
|
||||
int found = 0;
|
||||
|
||||
(void) timeout; // unused
|
||||
|
||||
device_data.cbSize = sizeof(device_data);
|
||||
index = 0;
|
||||
|
||||
/* get the device id */
|
||||
HidD_GetHidGuid(&device_id);
|
||||
|
||||
/* get all hid devices connected */
|
||||
device_info = SetupDiGetClassDevs(&device_id, NULL, NULL, (DIGCF_DEVICEINTERFACE | DIGCF_PRESENT));
|
||||
|
||||
for (;; ++index) {
|
||||
|
||||
if (detail_data) {
|
||||
free(detail_data);
|
||||
detail_data = NULL;
|
||||
}
|
||||
|
||||
/* query the next hid device info */
|
||||
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data))
|
||||
break;
|
||||
|
||||
/* get the size of the data block required */
|
||||
i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL);
|
||||
detail_data = malloc(len);
|
||||
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||
|
||||
/* query the data for this device */
|
||||
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL))
|
||||
continue;
|
||||
|
||||
/* open the device */
|
||||
dev = CreateFile(detail_data->DevicePath,
|
||||
(GENERIC_READ | GENERIC_WRITE),
|
||||
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
if (dev == INVALID_HANDLE_VALUE)
|
||||
continue;
|
||||
|
||||
/* get device attributes */
|
||||
attr.Size = sizeof(attr);
|
||||
i = HidD_GetAttributes(dev, &attr);
|
||||
|
||||
if ((attr.VendorID == WM_VENDOR_ID) && (attr.ProductID == WM_PRODUCT_ID)) {
|
||||
/* this is a wiimote */
|
||||
wm[found]->dev_handle = dev;
|
||||
|
||||
wm[found]->hid_overlap.hEvent = CreateEvent(NULL, 1, 1, "");
|
||||
wm[found]->hid_overlap.Offset = 0;
|
||||
wm[found]->hid_overlap.OffsetHigh = 0;
|
||||
|
||||
WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_DEV_FOUND);
|
||||
WIIMOTE_ENABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED);
|
||||
|
||||
/* try to set the output report to see if the device is actually connected */
|
||||
if (!wiiuse_set_report_type(wm[found])) {
|
||||
WIIMOTE_DISABLE_STATE(wm[found], WIIMOTE_STATE_CONNECTED);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* do the handshake */
|
||||
wiiuse_handshake(wm[found], NULL, 0);
|
||||
|
||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid);
|
||||
|
||||
++found;
|
||||
if (found >= max_wiimotes)
|
||||
break;
|
||||
} else {
|
||||
/* not a wiimote */
|
||||
CloseHandle(dev);
|
||||
}
|
||||
}
|
||||
|
||||
if (detail_data)
|
||||
free(detail_data);
|
||||
|
||||
SetupDiDestroyDeviceInfoList(device_info);
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_connect(struct wiimote_t** wm, int wiimotes) {
|
||||
int connected = 0;
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED))
|
||||
++connected;
|
||||
}
|
||||
|
||||
return connected;
|
||||
}
|
||||
|
||||
|
||||
void wiiuse_disconnect(struct wiimote_t* wm) {
|
||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
CloseHandle(wm->dev_handle);
|
||||
wm->dev_handle = 0;
|
||||
|
||||
ResetEvent(&wm->hid_overlap);
|
||||
|
||||
wm->event = WIIUSE_NONE;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_read(struct wiimote_t* wm) {
|
||||
DWORD b, r;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
|
||||
if (!ReadFile(wm->dev_handle, wm->event_buf, sizeof(wm->event_buf), &b, &wm->hid_overlap)) {
|
||||
/* partial read */
|
||||
b = GetLastError();
|
||||
|
||||
if ((b == ERROR_HANDLE_EOF) || (b == ERROR_DEVICE_NOT_CONNECTED)) {
|
||||
/* remote disconnect */
|
||||
wiiuse_disconnected(wm);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = WaitForSingleObject(wm->hid_overlap.hEvent, wm->timeout);
|
||||
if (r == WAIT_TIMEOUT) {
|
||||
/* timeout - cancel and continue */
|
||||
|
||||
if (*wm->event_buf)
|
||||
WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
|
||||
|
||||
CancelIo(wm->dev_handle);
|
||||
ResetEvent(wm->hid_overlap.hEvent);
|
||||
return 0;
|
||||
} else if (r == WAIT_FAILED) {
|
||||
WIIUSE_WARNING("A wait error occured on reading from wiimote %i.", wm->unid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0))
|
||||
return 0;
|
||||
}
|
||||
|
||||
ResetEvent(wm->hid_overlap.hEvent);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
|
||||
DWORD bytes;
|
||||
int i;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
|
||||
switch (wm->stack) {
|
||||
case WIIUSE_STACK_UNKNOWN:
|
||||
{
|
||||
/* try to auto-detect the stack type */
|
||||
if (i = WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap)) {
|
||||
/* bluesoleil will always return 1 here, even if it's not connected */
|
||||
wm->stack = WIIUSE_STACK_BLUESOLEIL;
|
||||
return i;
|
||||
}
|
||||
|
||||
if (i = HidD_SetOutputReport(wm->dev_handle, buf, len)) {
|
||||
wm->stack = WIIUSE_STACK_MS;
|
||||
return i;
|
||||
}
|
||||
|
||||
WIIUSE_ERROR("Unable to determine bluetooth stack type.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
case WIIUSE_STACK_MS:
|
||||
return HidD_SetOutputReport(wm->dev_handle, buf, len);
|
||||
|
||||
case WIIUSE_STACK_BLUESOLEIL:
|
||||
return WriteFile(wm->dev_handle, buf, 22, &bytes, &wm->hid_overlap);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* ifdef WIN32 */
|
||||
748
cpp/wiiuse/ir.c
Normal file
748
cpp/wiiuse/ir.c
Normal file
@@ -0,0 +1,748 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles IR data.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "ir.h"
|
||||
|
||||
static int get_ir_sens(struct wiimote_t* wm, char** block1, char** block2);
|
||||
static void interpret_ir_data(struct wiimote_t* wm);
|
||||
static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang);
|
||||
static void get_ir_dot_avg(struct ir_dot_t* dot, int* x, int* y);
|
||||
static void reorder_ir_dots(struct ir_dot_t* dot);
|
||||
static float ir_distance(struct ir_dot_t* dot);
|
||||
static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offset_x, int offset_y);
|
||||
static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int vy);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set if the wiimote should track IR targets.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*/
|
||||
void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
||||
byte buf;
|
||||
char* block1 = NULL;
|
||||
char* block2 = NULL;
|
||||
int ir_level;
|
||||
|
||||
if (!wm)
|
||||
return;
|
||||
|
||||
/*
|
||||
* Wait for the handshake to finish first.
|
||||
* When it handshake finishes and sees that
|
||||
* IR is enabled, it will call this function
|
||||
* again to actually enable IR.
|
||||
*/
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE)) {
|
||||
WIIUSE_DEBUG("Tried to enable IR, will wait until handshake finishes.");
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to make sure a sensitivity setting is selected.
|
||||
*/
|
||||
ir_level = get_ir_sens(wm, &block1, &block2);
|
||||
if (!ir_level) {
|
||||
WIIUSE_ERROR("No IR sensitivity setting selected.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status) {
|
||||
/* if already enabled then stop */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
return;
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
} else {
|
||||
/* if already disabled then stop */
|
||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
return;
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
}
|
||||
|
||||
/* set camera 1 and 2 */
|
||||
buf = (status ? 0x04 : 0x00);
|
||||
wiiuse_send(wm, WM_CMD_IR, &buf, 1);
|
||||
wiiuse_send(wm, WM_CMD_IR_2, &buf, 1);
|
||||
|
||||
if (!status) {
|
||||
WIIUSE_DEBUG("Disabled IR cameras for wiimote id %i.", wm->unid);
|
||||
wiiuse_set_report_type(wm);
|
||||
return;
|
||||
}
|
||||
|
||||
/* enable IR, set sensitivity */
|
||||
buf = 0x08;
|
||||
wiiuse_write_data(wm, WM_REG_IR, &buf, 1);
|
||||
|
||||
/* wait for the wiimote to catch up */
|
||||
#ifndef WIN32
|
||||
usleep(50000);
|
||||
#else
|
||||
Sleep(50);
|
||||
#endif
|
||||
|
||||
/* write sensitivity blocks */
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (byte*)block1, 9);
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
|
||||
|
||||
/* set the IR mode */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
||||
buf = WM_IR_TYPE_BASIC;
|
||||
else
|
||||
buf = WM_IR_TYPE_EXTENDED;
|
||||
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
||||
|
||||
#ifndef WIN32
|
||||
usleep(50000);
|
||||
#else
|
||||
Sleep(50);
|
||||
#endif
|
||||
|
||||
/* set the wiimote report type */
|
||||
wiiuse_set_report_type(wm);
|
||||
|
||||
WIIUSE_DEBUG("Enabled IR camera for wiimote id %i (sensitivity level %i).", wm->unid, ir_level);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the IR sensitivity settings.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param block1 [out] Pointer to where block1 will be set.
|
||||
* @param block2 [out] Pointer to where block2 will be set.
|
||||
*
|
||||
* @return Returns the sensitivity level.
|
||||
*/
|
||||
static int get_ir_sens(struct wiimote_t* wm, char** block1, char** block2) {
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL1)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL1;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL1;
|
||||
return 1;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL2)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL2;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL2;
|
||||
return 2;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL3)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL3;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL3;
|
||||
return 3;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL4)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL4;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL4;
|
||||
return 4;
|
||||
} else if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR_SENS_LVL5)) {
|
||||
*block1 = WM_IR_BLOCK1_LEVEL5;
|
||||
*block2 = WM_IR_BLOCK2_LEVEL5;
|
||||
return 5;
|
||||
}
|
||||
|
||||
*block1 = NULL;
|
||||
*block2 = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the virtual screen resolution for IR tracking.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*/
|
||||
void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.vres[0] = (x-1);
|
||||
wm->ir.vres[1] = (y-1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the XY position for the IR cursor.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.pos = pos;
|
||||
|
||||
switch (pos) {
|
||||
|
||||
case WIIUSE_IR_ABOVE:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = WM_ASPECT_16_9_Y/2 - 70;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = WM_ASPECT_4_3_Y/2 - 100;
|
||||
|
||||
return;
|
||||
|
||||
case WIIUSE_IR_BELOW:
|
||||
wm->ir.offset[0] = 0;
|
||||
|
||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
||||
wm->ir.offset[1] = -WM_ASPECT_16_9_Y/2 + 100;
|
||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
||||
wm->ir.offset[1] = -WM_ASPECT_4_3_Y/2 + 70;
|
||||
|
||||
return;
|
||||
|
||||
default:
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the aspect ratio of the TV/monitor.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3
|
||||
*/
|
||||
void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->ir.aspect = aspect;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_4_3) {
|
||||
wm->ir.vres[0] = WM_ASPECT_4_3_X;
|
||||
wm->ir.vres[1] = WM_ASPECT_4_3_Y;
|
||||
} else {
|
||||
wm->ir.vres[0] = WM_ASPECT_16_9_X;
|
||||
wm->ir.vres[1] = WM_ASPECT_16_9_Y;
|
||||
}
|
||||
|
||||
/* reset the position offsets */
|
||||
wiiuse_set_ir_position(wm, wm->ir.pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the IR sensitivity.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param level 1-5, same as Wii system sensitivity setting.
|
||||
*
|
||||
* If the level is < 1, then level will be set to 1.
|
||||
* If the level is > 5, then level will be set to 5.
|
||||
*/
|
||||
void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) {
|
||||
char* block1 = NULL;
|
||||
char* block2 = NULL;
|
||||
|
||||
if (!wm) return;
|
||||
|
||||
if (level > 5) level = 5;
|
||||
if (level < 1) level = 1;
|
||||
|
||||
WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL2 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL3 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL4 |
|
||||
WIIMOTE_STATE_IR_SENS_LVL5));
|
||||
|
||||
switch (level) {
|
||||
case 1:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL1);
|
||||
break;
|
||||
case 2:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL2);
|
||||
break;
|
||||
case 3:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL3);
|
||||
break;
|
||||
case 4:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL4);
|
||||
break;
|
||||
case 5:
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR_SENS_LVL5);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
/* set the new sensitivity */
|
||||
get_ir_sens(wm, &block1, &block2);
|
||||
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK1, (byte*)block1, 9);
|
||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
|
||||
|
||||
WIIUSE_DEBUG("Set IR sensitivity to level %i (unid %i)", level, wm->unid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the data from the IR spots. Basic IR mode.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Data returned by the wiimote for the IR spots.
|
||||
*/
|
||||
void calculate_basic_ir(struct wiimote_t* wm, byte* data) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
|
||||
dot[0].rx = 1023 - (data[0] | ((data[2] & 0x30) << 4));
|
||||
dot[0].ry = data[1] | ((data[2] & 0xC0) << 2);
|
||||
|
||||
dot[1].rx = 1023 - (data[3] | ((data[2] & 0x03) << 8));
|
||||
dot[1].ry = data[4] | ((data[2] & 0x0C) << 6);
|
||||
|
||||
dot[2].rx = 1023 - (data[5] | ((data[7] & 0x30) << 4));
|
||||
dot[2].ry = data[6] | ((data[7] & 0xC0) << 2);
|
||||
|
||||
dot[3].rx = 1023 - (data[8] | ((data[7] & 0x03) << 8));
|
||||
dot[3].ry = data[9] | ((data[7] & 0x0C) << 6);
|
||||
|
||||
/* set each IR spot to visible if spot is in range */
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].ry == 1023)
|
||||
dot[i].visible = 0;
|
||||
else {
|
||||
dot[i].visible = 1;
|
||||
dot[i].size = 0; /* since we don't know the size, set it as 0 */
|
||||
}
|
||||
}
|
||||
|
||||
interpret_ir_data(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the data from the IR spots. Extended IR mode.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Data returned by the wiimote for the IR spots.
|
||||
*/
|
||||
void calculate_extended_ir(struct wiimote_t* wm, byte* data) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].rx = 1023 - (data[3*i] | ((data[(3*i)+2] & 0x30) << 4));
|
||||
dot[i].ry = data[(3*i)+1] | ((data[(3*i)+2] & 0xC0) << 2);
|
||||
|
||||
dot[i].size = data[(3*i)+2] & 0x0F;
|
||||
|
||||
/* if in range set to visible */
|
||||
if (dot[i].ry == 1023)
|
||||
dot[i].visible = 0;
|
||||
else
|
||||
dot[i].visible = 1;
|
||||
}
|
||||
|
||||
interpret_ir_data(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interpret IR data into more user friendly variables.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
static void interpret_ir_data(struct wiimote_t* wm) {
|
||||
struct ir_dot_t* dot = wm->ir.dot;
|
||||
int i;
|
||||
float roll = 0.0f;
|
||||
int last_num_dots = wm->ir.num_dots;
|
||||
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC))
|
||||
roll = wm->orient.roll;
|
||||
|
||||
/* count visible dots */
|
||||
wm->ir.num_dots = 0;
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible)
|
||||
wm->ir.num_dots++;
|
||||
}
|
||||
|
||||
switch (wm->ir.num_dots) {
|
||||
case 0:
|
||||
{
|
||||
wm->ir.state = 0;
|
||||
|
||||
/* reset the dot ordering */
|
||||
for (i = 0; i < 4; ++i)
|
||||
dot[i].order = 0;
|
||||
|
||||
wm->ir.x = 0;
|
||||
wm->ir.y = 0;
|
||||
wm->ir.z = 0.0f;
|
||||
|
||||
return;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
if (wm->ir.state < 2) {
|
||||
/*
|
||||
* Only 1 known dot, so use just that.
|
||||
*/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
wm->ir.x = dot[i].x;
|
||||
wm->ir.y = dot[i].y;
|
||||
|
||||
wm->ir.ax = wm->ir.x;
|
||||
wm->ir.ay = wm->ir.y;
|
||||
|
||||
/* can't calculate yaw because we don't have the distance */
|
||||
//wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
ir_convert_to_vres(&wm->ir.x, &wm->ir.y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* Only see 1 dot but know theres 2.
|
||||
* Try to estimate where the other one
|
||||
* should be and use that.
|
||||
*/
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
int ox = 0;
|
||||
int x, y;
|
||||
|
||||
if (dot[i].order == 1)
|
||||
/* visible is the left dot - estimate where the right is */
|
||||
ox = dot[i].x + wm->ir.distance;
|
||||
else if (dot[i].order == 2)
|
||||
/* visible is the right dot - estimate where the left is */
|
||||
ox = dot[i].x - wm->ir.distance;
|
||||
|
||||
x = ((signed int)dot[i].x + ox) / 2;
|
||||
y = dot[i].y;
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
/*
|
||||
* Two (or more) dots known and seen.
|
||||
* Average them together to estimate the true location.
|
||||
*/
|
||||
int x, y;
|
||||
wm->ir.state = 2;
|
||||
|
||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||
|
||||
/* if there is at least 1 new dot, reorder them all */
|
||||
if (wm->ir.num_dots > last_num_dots) {
|
||||
reorder_ir_dots(dot);
|
||||
wm->ir.x = 0;
|
||||
wm->ir.y = 0;
|
||||
}
|
||||
|
||||
wm->ir.distance = ir_distance(dot);
|
||||
wm->ir.z = 1023 - wm->ir.distance;
|
||||
|
||||
get_ir_dot_avg(wm->ir.dot, &x, &y);
|
||||
|
||||
wm->ir.ax = x;
|
||||
wm->ir.ay = y;
|
||||
wm->orient.yaw = calc_yaw(&wm->ir);
|
||||
|
||||
if (ir_correct_for_bounds(&x, &y, wm->ir.aspect, wm->ir.offset[0], wm->ir.offset[1])) {
|
||||
ir_convert_to_vres(&x, &y, wm->ir.aspect, wm->ir.vres[0], wm->ir.vres[1]);
|
||||
wm->ir.x = x;
|
||||
wm->ir.y = y;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int ir_level;
|
||||
WIIUSE_GET_IR_SENSITIVITY(wm, &ir_level);
|
||||
WIIUSE_DEBUG("IR sensitivity: %i", ir_level);
|
||||
WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots);
|
||||
for (i = 0; i < 4; ++i)
|
||||
if (dot[i].visible)
|
||||
WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y);
|
||||
WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fix the rotation of the IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
* @param ang The roll angle to correct by (-180, 180)
|
||||
*
|
||||
* If there is roll then the dots are rotated
|
||||
* around the origin and give a false cursor
|
||||
* position. Correct for the roll.
|
||||
*
|
||||
* If the accelerometer is off then obviously
|
||||
* this will not do anything and the cursor
|
||||
* position may be inaccurate.
|
||||
*/
|
||||
static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang) {
|
||||
float s, c;
|
||||
int x, y;
|
||||
int i;
|
||||
|
||||
if (!ang) {
|
||||
for (i = 0; i < 4; ++i) {
|
||||
dot[i].x = dot[i].rx;
|
||||
dot[i].y = dot[i].ry;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
s = sin(DEGREE_TO_RAD(ang));
|
||||
c = cos(DEGREE_TO_RAD(ang));
|
||||
|
||||
/*
|
||||
* [ cos(theta) -sin(theta) ][ ir->rx ]
|
||||
* [ sin(theta) cos(theta) ][ ir->ry ]
|
||||
*/
|
||||
|
||||
for (i = 0; i < 4; ++i) {
|
||||
if (!dot[i].visible)
|
||||
continue;
|
||||
|
||||
x = dot[i].rx - (1024/2);
|
||||
y = dot[i].ry - (768/2);
|
||||
|
||||
dot[i].x = (c * x) + (-s * y);
|
||||
dot[i].y = (s * x) + (c * y);
|
||||
|
||||
dot[i].x += (1024/2);
|
||||
dot[i].y += (768/2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Average IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
* @param x [out] Average X
|
||||
* @param y [out] Average Y
|
||||
*/
|
||||
static void get_ir_dot_avg(struct ir_dot_t* dot, int* x, int* y) {
|
||||
int vis = 0, i = 0;
|
||||
|
||||
*x = 0;
|
||||
*y = 0;
|
||||
|
||||
for (; i < 4; ++i) {
|
||||
if (dot[i].visible) {
|
||||
*x += dot[i].x;
|
||||
*y += dot[i].y;
|
||||
++vis;
|
||||
}
|
||||
}
|
||||
|
||||
*x /= vis;
|
||||
*y /= vis;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Reorder the IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
*/
|
||||
static void reorder_ir_dots(struct ir_dot_t* dot) {
|
||||
int i, j, order;
|
||||
|
||||
/* reset the dot ordering */
|
||||
for (i = 0; i < 4; ++i)
|
||||
dot[i].order = 0;
|
||||
|
||||
for (order = 1; order < 5; ++order) {
|
||||
i = 0;
|
||||
|
||||
for (; !dot[i].visible || dot[i].order; ++i)
|
||||
if (i > 4)
|
||||
return;
|
||||
|
||||
for (j = 0; j < 4; ++j) {
|
||||
if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x))
|
||||
i = j;
|
||||
}
|
||||
|
||||
dot[i].order = order;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate the distance between the first 2 visible IR dots.
|
||||
*
|
||||
* @param dot An array of 4 ir_dot_t objects.
|
||||
*/
|
||||
static float ir_distance(struct ir_dot_t* dot) {
|
||||
int i1, i2;
|
||||
int xd, yd;
|
||||
|
||||
for (i1 = 0; i1 < 4; ++i1)
|
||||
if (dot[i1].visible)
|
||||
break;
|
||||
if (i1 == 4)
|
||||
return 0.0f;
|
||||
|
||||
for (i2 = i1+1; i2 < 4; ++i2)
|
||||
if (dot[i2].visible)
|
||||
break;
|
||||
if (i2 == 4)
|
||||
return 0.0f;
|
||||
|
||||
xd = dot[i2].x - dot[i1].x;
|
||||
yd = dot[i2].y - dot[i1].y;
|
||||
|
||||
return sqrt(xd*xd + yd*yd);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Correct for the IR bounding box.
|
||||
*
|
||||
* @param x [out] The current X, it will be updated if valid.
|
||||
* @param y [out] The current Y, it will be updated if valid.
|
||||
* @param aspect Aspect ratio of the screen.
|
||||
* @param offset_x The X offset of the bounding box.
|
||||
* @param offset_y The Y offset of the bounding box.
|
||||
*
|
||||
* @return Returns 1 if the point is valid and was updated.
|
||||
*
|
||||
* Nintendo was smart with this bit. They sacrifice a little
|
||||
* precision for a big increase in usability.
|
||||
*/
|
||||
static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offset_x, int offset_y) {
|
||||
int x0, y0;
|
||||
int xs, ys;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_16_9) {
|
||||
xs = WM_ASPECT_16_9_X;
|
||||
ys = WM_ASPECT_16_9_Y;
|
||||
} else {
|
||||
xs = WM_ASPECT_4_3_X;
|
||||
ys = WM_ASPECT_4_3_Y;
|
||||
}
|
||||
|
||||
x0 = ((1024 - xs) / 2) + offset_x;
|
||||
y0 = ((768 - ys) / 2) + offset_y;
|
||||
|
||||
if ((*x >= x0)
|
||||
&& (*x <= (x0 + xs))
|
||||
&& (*y >= y0)
|
||||
&& (*y <= (y0 + ys)))
|
||||
{
|
||||
*x -= offset_x;
|
||||
*y -= offset_y;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interpolate the point to the user defined virtual screen resolution.
|
||||
*/
|
||||
static void ir_convert_to_vres(int* x, int* y, enum aspect_t aspect, int vx, int vy) {
|
||||
int xs, ys;
|
||||
|
||||
if (aspect == WIIUSE_ASPECT_16_9) {
|
||||
xs = WM_ASPECT_16_9_X;
|
||||
ys = WM_ASPECT_16_9_Y;
|
||||
} else {
|
||||
xs = WM_ASPECT_4_3_X;
|
||||
ys = WM_ASPECT_4_3_Y;
|
||||
}
|
||||
|
||||
*x -= ((1024-xs)/2);
|
||||
*y -= ((768-ys)/2);
|
||||
|
||||
*x = (*x / (float)xs) * vx;
|
||||
*y = (*y / (float)ys) * vy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate yaw given the IR data.
|
||||
*
|
||||
* @param ir IR data structure.
|
||||
*/
|
||||
float calc_yaw(struct ir_t* ir) {
|
||||
float x;
|
||||
|
||||
x = ir->ax - 512;
|
||||
x = x * (ir->z / 1024.0f);
|
||||
|
||||
return RAD_TO_DEGREE( atanf(x / ir->z) );
|
||||
}
|
||||
56
cpp/wiiuse/ir.h
Normal file
56
cpp/wiiuse/ir.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Handles IR data.
|
||||
*/
|
||||
|
||||
#ifndef IR_H_INCLUDED
|
||||
#define IR_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#define WII_VRES_X 560
|
||||
#define WII_VRES_Y 340
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void calculate_basic_ir(struct wiimote_t* wm, byte* data);
|
||||
void calculate_extended_ir(struct wiimote_t* wm, byte* data);
|
||||
float calc_yaw(struct ir_t* ir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // IR_H_INCLUDED
|
||||
|
||||
|
||||
BIN
cpp/wiiuse/lib/hid.lib
Normal file
BIN
cpp/wiiuse/lib/hid.lib
Normal file
Binary file not shown.
4
cpp/wiiuse/msvc/copy.bat
Normal file
4
cpp/wiiuse/msvc/copy.bat
Normal file
@@ -0,0 +1,4 @@
|
||||
copy ..\wiiuse.h ..\..\WiiUseJ\
|
||||
copy ..\speaker.h ..\..\WiiUseJ\
|
||||
copy Release\wiiuse.lib ..\..\WiiUseJ\lib\
|
||||
copy Release\wiiuse.dll ..\..\..\java\native\
|
||||
20
cpp/wiiuse/msvc/wiiuse.sln
Normal file
20
cpp/wiiuse/msvc/wiiuse.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual C++ Express 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wiiuse", "wiiuse.vcxproj", "{385472E8-DD54-4F51-83A4-99D7669CB693}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{385472E8-DD54-4F51-83A4-99D7669CB693}.Debug|Win32.ActiveCfg = Release|Win32
|
||||
{385472E8-DD54-4F51-83A4-99D7669CB693}.Debug|Win32.Build.0 = Release|Win32
|
||||
{385472E8-DD54-4F51-83A4-99D7669CB693}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{385472E8-DD54-4F51-83A4-99D7669CB693}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
BIN
cpp/wiiuse/msvc/wiiuse.suo
Normal file
BIN
cpp/wiiuse/msvc/wiiuse.suo
Normal file
Binary file not shown.
199
cpp/wiiuse/msvc/wiiuse.vcxproj
Normal file
199
cpp/wiiuse/msvc/wiiuse.vcxproj
Normal file
@@ -0,0 +1,199 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{385472E8-DD54-4F51-83A4-99D7669CB693}</ProjectGuid>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<UseOfMfc>false</UseOfMfc>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC60.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup>
|
||||
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">.\Release\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
|
||||
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug\</OutDir>
|
||||
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">.\Debug\</IntDir>
|
||||
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
|
||||
<IncludePath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">..\lib;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Midl>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MkTypLibCompatible>true</MkTypLibCompatible>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<TargetEnvironment>Win32</TargetEnvironment>
|
||||
<TypeLibraryName>.\Release/wiiuse.tlb</TypeLibraryName>
|
||||
<HeaderFileName>
|
||||
</HeaderFileName>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;WIIUSE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<StringPooling>true</StringPooling>
|
||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<PrecompiledHeaderOutputFile>.\Release/wiiuse.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerListingLocation>.\Release/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\Release/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\Release/</ProgramDataBaseFileName>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0409</Culture>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>odbc32.lib;odbccp32.lib;Ws2_32.lib;hid.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>.\Release/wiiuse.dll</OutputFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<ProgramDatabaseFile>.\Release/wiiuse.pdb</ProgramDatabaseFile>
|
||||
<ImportLibrary>.\Release/wiiuse.lib</ImportLibrary>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<Bscmake>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>.\Release/wiiuse.bsc</OutputFile>
|
||||
</Bscmake>
|
||||
<PostBuildEvent>
|
||||
<Command>copy.bat</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Midl>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MkTypLibCompatible>true</MkTypLibCompatible>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<TargetEnvironment>Win32</TargetEnvironment>
|
||||
<TypeLibraryName>.\Debug/wiiuse.tlb</TypeLibraryName>
|
||||
<HeaderFileName>
|
||||
</HeaderFileName>
|
||||
</Midl>
|
||||
<ClCompile>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;WIIUSE_EXPORTS;WITH_WIIUSE_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<MinimalRebuild>true</MinimalRebuild>
|
||||
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
<PrecompiledHeaderOutputFile>.\Debug/wiiuse.pch</PrecompiledHeaderOutputFile>
|
||||
<AssemblerListingLocation>.\Debug/</AssemblerListingLocation>
|
||||
<ObjectFileName>.\Debug/</ObjectFileName>
|
||||
<ProgramDataBaseFileName>.\Debug/</ProgramDataBaseFileName>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<Culture>0x0409</Culture>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<AdditionalDependencies>odbc32.lib;odbccp32.lib;Ws2_32.lib;hid.lib;setupapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<OutputFile>.\Debug/wiiuse.dll</OutputFile>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<ProgramDatabaseFile>.\Debug/wiiuse.pdb</ProgramDatabaseFile>
|
||||
<ImportLibrary>.\Debug/wiiuse.lib</ImportLibrary>
|
||||
<TargetMachine>MachineX86</TargetMachine>
|
||||
</Link>
|
||||
<Bscmake>
|
||||
<SuppressStartupBanner>true</SuppressStartupBanner>
|
||||
<OutputFile>.\Debug/wiiuse.bsc</OutputFile>
|
||||
</Bscmake>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\classic.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\dynamics.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\events.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\guitar_hero_3.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\io.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\io_nix.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\io_win.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\ir.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\nunchuk.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\speaker.c" />
|
||||
<ClCompile Include="..\wiiuse.c">
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\classic.h" />
|
||||
<ClInclude Include="..\definitions.h" />
|
||||
<ClInclude Include="..\dynamics.h" />
|
||||
<ClInclude Include="..\events.h" />
|
||||
<ClInclude Include="..\guitar_hero_3.h" />
|
||||
<ClInclude Include="..\io.h" />
|
||||
<ClInclude Include="..\ir.h" />
|
||||
<ClInclude Include="..\nunchuk.h" />
|
||||
<ClInclude Include="..\os.h" />
|
||||
<ClInclude Include="..\speaker.h" />
|
||||
<ClInclude Include="..\wiiuse.h" />
|
||||
<ClInclude Include="..\wiiuse_internal.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\CHANGELOG" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
95
cpp/wiiuse/msvc/wiiuse.vcxproj.filters
Normal file
95
cpp/wiiuse/msvc/wiiuse.vcxproj.filters
Normal file
@@ -0,0 +1,95 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{8c12ab0c-4eef-42ef-9998-bd56225be1bc}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{999fa8e0-d309-441b-a788-abffd9c66b35}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{a74a0b98-edc7-4944-9e03-b7f95ebfb613}</UniqueIdentifier>
|
||||
<Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\classic.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\dynamics.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\events.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\guitar_hero_3.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\io.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\io_nix.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\io_win.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\ir.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\nunchuk.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\wiiuse.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\speaker.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\classic.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\definitions.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\dynamics.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\events.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\guitar_hero_3.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\io.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\ir.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\nunchuk.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\os.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\wiiuse.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\wiiuse_internal.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\speaker.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\CHANGELOG">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
3
cpp/wiiuse/msvc/wiiuse.vcxproj.user
Normal file
3
cpp/wiiuse/msvc/wiiuse.vcxproj.user
Normal file
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
||||
210
cpp/wiiuse/nunchuk.c
Normal file
210
cpp/wiiuse/nunchuk.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "dynamics.h"
|
||||
#include "events.h"
|
||||
#include "nunchuk.h"
|
||||
|
||||
static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now);
|
||||
|
||||
/**
|
||||
* @brief Handle the handshake data from the nunchuk.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
* @param data The data read in from the device.
|
||||
* @param len The length of the data block, in bytes.
|
||||
*
|
||||
* @return Returns 1 if handshake was successful, 0 if not.
|
||||
*/
|
||||
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len) {
|
||||
int i;
|
||||
int offset = 0;
|
||||
|
||||
nc->btns = 0;
|
||||
nc->btns_held = 0;
|
||||
nc->btns_released = 0;
|
||||
|
||||
/* set the smoothing to the same as the wiimote */
|
||||
nc->flags = &wm->flags;
|
||||
nc->accel_calib.st_alpha = wm->accel_calib.st_alpha;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < len; ++i)
|
||||
data[i] = (data[i] ^ 0x17) + 0x17;
|
||||
|
||||
if (data[offset] == 0xFF) {
|
||||
/*
|
||||
* Sometimes the data returned here is not correct.
|
||||
* This might happen because the wiimote is lagging
|
||||
* behind our initialization sequence.
|
||||
* To fix this just request the handshake again.
|
||||
*
|
||||
* Other times it's just the first 16 bytes are 0xFF,
|
||||
* but since the next 16 bytes are the same, just use
|
||||
* those.
|
||||
*/
|
||||
if (data[offset + 16] == 0xFF) {
|
||||
/* get the calibration data */
|
||||
byte* handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||
|
||||
WIIUSE_DEBUG("Nunchuk handshake appears invalid, trying again.");
|
||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||
|
||||
return 0;
|
||||
} else
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
nc->accel_calib.cal_zero.x = data[offset + 0];
|
||||
nc->accel_calib.cal_zero.y = data[offset + 1];
|
||||
nc->accel_calib.cal_zero.z = data[offset + 2];
|
||||
nc->accel_calib.cal_g.x = data[offset + 4];
|
||||
nc->accel_calib.cal_g.y = data[offset + 5];
|
||||
nc->accel_calib.cal_g.z = data[offset + 6];
|
||||
nc->js.max.x = data[offset + 8];
|
||||
nc->js.min.x = data[offset + 9];
|
||||
nc->js.center.x = data[offset + 10];
|
||||
nc->js.max.y = data[offset + 11];
|
||||
nc->js.min.y = data[offset + 12];
|
||||
nc->js.center.y = data[offset + 13];
|
||||
|
||||
/* default the thresholds to the same as the wiimote */
|
||||
nc->orient_threshold = wm->orient_threshold;
|
||||
nc->accel_threshold = wm->accel_threshold;
|
||||
|
||||
/* handshake done */
|
||||
wm->exp.type = EXP_NUNCHUK;
|
||||
|
||||
#ifdef WIN32
|
||||
wm->timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The nunchuk disconnected.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
*/
|
||||
void nunchuk_disconnected(struct nunchuk_t* nc) {
|
||||
memset(nc, 0, sizeof(struct nunchuk_t));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle nunchuk event.
|
||||
*
|
||||
* @param nc A pointer to a nunchuk_t structure.
|
||||
* @param msg The message specified in the event packet.
|
||||
*/
|
||||
void nunchuk_event(struct nunchuk_t* nc, byte* msg) {
|
||||
int i;
|
||||
|
||||
/* decrypt data */
|
||||
for (i = 0; i < 6; ++i)
|
||||
msg[i] = (msg[i] ^ 0x17) + 0x17;
|
||||
|
||||
/* get button states */
|
||||
nunchuk_pressed_buttons(nc, msg[5]);
|
||||
|
||||
/* calculate joystick state */
|
||||
calc_joystick_state(&nc->js, msg[0], msg[1]);
|
||||
|
||||
/* calculate orientation */
|
||||
nc->accel.x = msg[2];
|
||||
nc->accel.y = msg[3];
|
||||
nc->accel.z = msg[4];
|
||||
|
||||
calculate_orientation(&nc->accel_calib, &nc->accel, &nc->orient, NUNCHUK_IS_FLAG_SET(nc, WIIUSE_SMOOTHING));
|
||||
calculate_gforce(&nc->accel_calib, &nc->accel, &nc->gforce);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find what buttons are pressed.
|
||||
*
|
||||
* @param nc Pointer to a nunchuk_t structure.
|
||||
* @param msg The message byte specified in the event packet.
|
||||
*/
|
||||
static void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now) {
|
||||
/* message is inverted (0 is active, 1 is inactive) */
|
||||
now = ~now & NUNCHUK_BUTTON_ALL;
|
||||
|
||||
/* pressed now & were pressed, then held */
|
||||
nc->btns_held = (now & nc->btns);
|
||||
|
||||
/* were pressed or were held & not pressed now, then released */
|
||||
nc->btns_released = ((nc->btns | nc->btns_held) & ~now);
|
||||
|
||||
/* buttons pressed now */
|
||||
nc->btns = now;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the orientation event threshold for the nunchuk.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure with a nunchuk attached.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->exp.nunchuk.orient_threshold = threshold;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the accelerometer event threshold for the nunchuk.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure with a nunchuk attached.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*
|
||||
* See wiiuse_set_orient_threshold() for details.
|
||||
*/
|
||||
void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->exp.nunchuk.accel_threshold = threshold;
|
||||
}
|
||||
53
cpp/wiiuse/nunchuk.h
Normal file
53
cpp/wiiuse/nunchuk.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
|
||||
#ifndef NUNCHUK_H_INCLUDED
|
||||
#define NUNCHUK_H_INCLUDED
|
||||
|
||||
#include "wiiuse_internal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, unsigned short len);
|
||||
|
||||
void nunchuk_disconnected(struct nunchuk_t* nc);
|
||||
|
||||
void nunchuk_event(struct nunchuk_t* nc, byte* msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // NUNCHUK_H_INCLUDED
|
||||
56
cpp/wiiuse/os.h
Normal file
56
cpp/wiiuse/os.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Operating system related definitions.
|
||||
*
|
||||
* This file is an attempt to separate operating system
|
||||
* dependent functions and choose what should be used
|
||||
* at compile time.
|
||||
*/
|
||||
|
||||
#ifndef OS_H_INCLUDED
|
||||
#define OS_H_INCLUDED
|
||||
|
||||
#ifdef WIN32
|
||||
/* windows */
|
||||
#define isnan(x) _isnan(x)
|
||||
#define isinf(x) !_finite(x)
|
||||
|
||||
/* disable warnings I don't care about */
|
||||
#pragma warning(disable:4244) /* possible loss of data conversion */
|
||||
#pragma warning(disable:4273) /* inconsistent dll linkage */
|
||||
#pragma warning(disable:4217)
|
||||
#else
|
||||
/* nix */
|
||||
#endif
|
||||
|
||||
|
||||
#endif // OS_H_INCLUDED
|
||||
63
cpp/wiiuse/speaker.c
Normal file
63
cpp/wiiuse/speaker.c
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <stdio.h>
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "speaker.h"
|
||||
|
||||
void wiiuse_speaker_enable(struct wiimote_t* wm) {
|
||||
byte buf = WIIMOTE_GET_RUMBLE(wm) | WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED;
|
||||
wiiuse_send(wm, WM_CMD_SPEAKER_ENABLE, &buf, 1);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_disable(struct wiimote_t* wm) {
|
||||
byte buf = WIIMOTE_GET_RUMBLE(wm);
|
||||
wiiuse_send(wm, WM_CMD_SPEAKER_ENABLE, &buf, 1);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_mute(struct wiimote_t* wm) {
|
||||
byte buf = WIIMOTE_GET_RUMBLE(wm) | WM_CTRL_STATUS_BYTE1_SPEAKER_MUTE;
|
||||
wiiuse_send(wm, WM_CMD_SPEAKER_MUTE, &buf , 1);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_unmute(struct wiimote_t* wm) {
|
||||
byte buf = WIIMOTE_GET_RUMBLE(wm);
|
||||
wiiuse_send(wm, WM_CMD_SPEAKER_MUTE, &buf, 1);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_config(struct wiimote_t* wm, unsigned short freq, byte vol) {
|
||||
if (freq > 0x0000) {
|
||||
cfg[2] = freq & 0x00ff;
|
||||
cfg[3] = (freq & 0xff00) >> 8;
|
||||
}
|
||||
printf("speaker 0x%02x%02x\n", cfg[2], cfg[3]);
|
||||
fflush(stdout);
|
||||
if (vol > 0x00) {
|
||||
cfg[4] = vol;
|
||||
}
|
||||
wiiuse_write_data(wm, WM_REG_SPEAKER, cfg, 9);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_data(struct wiimote_t* wm, byte* data) {
|
||||
byte buf[21];
|
||||
buf[0] = sizeof(data) << 3;
|
||||
memcpy(buf + 1, data, 20);
|
||||
wiiuse_send(wm, WM_CMD_STREAM_DATA, buf, 21);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_activate(struct wiimote_t* wm) {
|
||||
wiiuse_speaker_enable(wm);
|
||||
wiiuse_speaker_unmute(wm);
|
||||
wiiuse_speaker_config(wm, 0x00, 0x00);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_deactivate(struct wiimote_t* wm) {
|
||||
wiiuse_speaker_mute(wm);
|
||||
wiiuse_speaker_disable(wm);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_frequency(struct wiimote_t* wm, unsigned short freq) {
|
||||
wiiuse_speaker_config(wm, freq, 0x00);
|
||||
}
|
||||
|
||||
void wiiuse_speaker_volume(struct wiimote_t* wm, byte vol) {
|
||||
wiiuse_speaker_config(wm, 0x0000, vol);
|
||||
}
|
||||
23
cpp/wiiuse/speaker.h
Normal file
23
cpp/wiiuse/speaker.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "wiiuse.h"
|
||||
|
||||
#define WIIMOTE_GET_RUMBLE(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE) ? 0x01 : 0x00)
|
||||
|
||||
#define WM_CMD_SPEAKER_ENABLE 0x14
|
||||
#define WM_CMD_STREAM_DATA 0x18
|
||||
#define WM_CMD_SPEAKER_MUTE 0x19
|
||||
|
||||
#define WM_CTRL_STATUS_BYTE1_SPEAKER_MUTE 0x04
|
||||
|
||||
#define WM_REG_SPEAKER 0x04a20001
|
||||
|
||||
static byte cfg[9] = {0x00, 0x00, 0x00, 0xdd, 0x40, 0x00, 0x00, 0x01, 0x01};
|
||||
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, byte vol);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_frequency(struct wiimote_t* wm, unsigned short freq);
|
||||
WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data);
|
||||
764
cpp/wiiuse/wiiuse.c
Normal file
764
cpp/wiiuse/wiiuse.c
Normal file
@@ -0,0 +1,764 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief General wiimote operations.
|
||||
*
|
||||
* The file includes functions that handle general
|
||||
* tasks. Most of these are functions that are part
|
||||
* of the API.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <Winsock2.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
#include "wiiuse_internal.h"
|
||||
#include "events.h"
|
||||
#include "io.h"
|
||||
|
||||
static int g_banner = 0;
|
||||
|
||||
/**
|
||||
* @breif Returns the version of the library.
|
||||
*/
|
||||
const char* wiiuse_version() {
|
||||
return WIIUSE_VERSION;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Clean up wiimote_t array created by wiiuse_init()
|
||||
*/
|
||||
void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) {
|
||||
int i = 0;
|
||||
|
||||
if (!wm)
|
||||
return;
|
||||
|
||||
WIIUSE_INFO("wiiuse clean up...");
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
wiiuse_disconnect(wm[i]);
|
||||
free(wm[i]);
|
||||
}
|
||||
|
||||
free(wm);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initialize an array of wiimote structures.
|
||||
*
|
||||
* @param wiimotes Number of wiimote_t structures to create.
|
||||
*
|
||||
* @return An array of initialized wiimote_t structures.
|
||||
*
|
||||
* @see wiiuse_connect()
|
||||
*
|
||||
* The array returned by this function can be passed to various
|
||||
* functions, including wiiuse_connect().
|
||||
*/
|
||||
struct wiimote_t** wiiuse_init(int wiimotes) {
|
||||
int i = 0;
|
||||
struct wiimote_t** wm = NULL;
|
||||
|
||||
/*
|
||||
* Please do not remove this banner.
|
||||
* GPL asks that you please leave output credits intact.
|
||||
* Thank you.
|
||||
*
|
||||
* This banner is only displayed once so that if you need
|
||||
* to call this function again it won't be intrusive.
|
||||
*/
|
||||
if (!g_banner) {
|
||||
printf( "wiiuse v" WIIUSE_VERSION " loaded.\n"
|
||||
" By: Michael Laforest <thepara[at]gmail{dot}com>\n"
|
||||
" http://wiiuse.net http://wiiuse.sf.net\n");
|
||||
g_banner = 1;
|
||||
}
|
||||
|
||||
if (!wiimotes)
|
||||
return NULL;
|
||||
|
||||
wm = malloc(sizeof(struct wiimote_t*) * wiimotes);
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i] = malloc(sizeof(struct wiimote_t));
|
||||
memset(wm[i], 0, sizeof(struct wiimote_t));
|
||||
|
||||
wm[i]->unid = i+1;
|
||||
|
||||
#ifndef WIN32
|
||||
wm[i]->bdaddr = *BDADDR_ANY;
|
||||
wm[i]->out_sock = -1;
|
||||
wm[i]->in_sock = -1;
|
||||
#else
|
||||
wm[i]->dev_handle = 0;
|
||||
wm[i]->stack = WIIUSE_STACK_UNKNOWN;
|
||||
wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
|
||||
wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT;
|
||||
wm[i]->timeout = wm[i]->normal_timeout;
|
||||
#endif
|
||||
|
||||
wm[i]->state = WIIMOTE_INIT_STATES;
|
||||
wm[i]->flags = WIIUSE_INIT_FLAGS;
|
||||
|
||||
wm[i]->event = WIIUSE_NONE;
|
||||
|
||||
wm[i]->exp.type = EXP_NONE;
|
||||
|
||||
wiiuse_set_aspect_ratio(wm[i], WIIUSE_ASPECT_4_3);
|
||||
wiiuse_set_ir_position(wm[i], WIIUSE_IR_ABOVE);
|
||||
|
||||
wm[i]->orient_threshold = 0.5f;
|
||||
wm[i]->accel_threshold = 5;
|
||||
|
||||
wm[i]->accel_calib.st_alpha = WIIUSE_DEFAULT_SMOOTH_ALPHA;
|
||||
}
|
||||
|
||||
return wm;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief The wiimote disconnected.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_disconnected(struct wiimote_t* wm) {
|
||||
if (!wm) return;
|
||||
|
||||
WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid);
|
||||
|
||||
/* disable the connected flag */
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
|
||||
|
||||
/* reset a bunch of stuff */
|
||||
#ifndef WIN32
|
||||
wm->out_sock = -1;
|
||||
wm->in_sock = -1;
|
||||
#else
|
||||
wm->dev_handle = 0;
|
||||
#endif
|
||||
|
||||
wm->leds = 0;
|
||||
wm->state = WIIMOTE_INIT_STATES;
|
||||
wm->read_req = NULL;
|
||||
wm->handshake_state = 0;
|
||||
wm->btns = 0;
|
||||
wm->btns_held = 0;
|
||||
wm->btns_released = 0;
|
||||
memset(wm->event_buf, 0, sizeof(wm->event_buf));
|
||||
|
||||
wm->event = WIIUSE_DISCONNECT;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enable or disable the rumble.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*/
|
||||
void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
||||
byte buf;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
/* make sure to keep the current lit leds */
|
||||
buf = wm->leds;
|
||||
|
||||
if (status) {
|
||||
WIIUSE_DEBUG("Starting rumble...");
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
|
||||
buf |= 0x01;
|
||||
} else {
|
||||
WIIUSE_DEBUG("Stopping rumble...");
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_RUMBLE);
|
||||
}
|
||||
|
||||
/* preserve IR state */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
buf |= 0x04;
|
||||
|
||||
wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Toggle the state of the rumble.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_toggle_rumble(struct wiimote_t* wm) {
|
||||
if (!wm) return;
|
||||
|
||||
wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the enabled LEDs.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param leds What LEDs to enable.
|
||||
*
|
||||
* \a leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, or WIIMOTE_LED_4.
|
||||
*/
|
||||
void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
|
||||
byte buf;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
/* remove the lower 4 bits because they control rumble */
|
||||
wm->leds = (leds & 0xF0);
|
||||
|
||||
/* make sure if the rumble is on that we keep it on */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
||||
wm->leds |= 0x01;
|
||||
|
||||
buf = wm->leds;
|
||||
|
||||
wiiuse_send(wm, WM_CMD_LED, &buf, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set if the wiimote should report motion sensing.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param status 1 to enable, 0 to disable.
|
||||
*
|
||||
* Since reporting motion sensing sends a lot of data,
|
||||
* the wiimote saves power by not transmitting it
|
||||
* by default.
|
||||
*/
|
||||
void wiiuse_motion_sensing(struct wiimote_t* wm, int status) {
|
||||
if (status)
|
||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||
else
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||
|
||||
wiiuse_set_report_type(wm);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the report type based on the current wiimote state.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @return The report type sent.
|
||||
*
|
||||
* The wiimote reports formatted packets depending on the
|
||||
* report type that was last requested. This function will
|
||||
* update the type of report that should be sent based on
|
||||
* the current state of the device.
|
||||
*/
|
||||
int wiiuse_set_report_type(struct wiimote_t* wm) {
|
||||
byte buf[2];
|
||||
int motion, exp, ir;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
|
||||
buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */
|
||||
buf[1] = 0x00;
|
||||
|
||||
/* if rumble is enabled, make sure we keep it */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
||||
buf[0] |= 0x01;
|
||||
|
||||
motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC);
|
||||
exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP);
|
||||
ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR);
|
||||
|
||||
if (motion && ir && exp) buf[1] = WM_RPT_BTN_ACC_IR_EXP;
|
||||
else if (motion && exp) buf[1] = WM_RPT_BTN_ACC_EXP;
|
||||
else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR;
|
||||
else if (ir && exp) buf[1] = WM_RPT_BTN_IR_EXP;
|
||||
else if (ir) buf[1] = WM_RPT_BTN_ACC_IR;
|
||||
else if (exp) buf[1] = WM_RPT_BTN_EXP;
|
||||
else if (motion) buf[1] = WM_RPT_BTN_ACC;
|
||||
else buf[1] = WM_RPT_BTN;
|
||||
|
||||
WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]);
|
||||
|
||||
exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2);
|
||||
if (exp <= 0)
|
||||
return exp;
|
||||
|
||||
return buf[1];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read data from the wiimote (callback version).
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param read_cb Function pointer to call when the data arrives from the wiimote.
|
||||
* @param buffer An allocated buffer to store the data as it arrives from the wiimote.
|
||||
* Must be persistent in memory and large enough to hold the data.
|
||||
* @param addr The address of wiimote memory to read from.
|
||||
* @param len The length of the block to be read.
|
||||
*
|
||||
* The library can only handle one data read request at a time
|
||||
* because it must keep track of the buffer and other
|
||||
* events that are specific to that request. So if a request
|
||||
* has already been made, subsequent requests will be added
|
||||
* to a pending list and be sent out when the previous
|
||||
* finishes.
|
||||
*/
|
||||
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int addr, unsigned short len) {
|
||||
struct read_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
if (!buffer || !len || !read_cb)
|
||||
return 0;
|
||||
|
||||
/* make this request structure */
|
||||
req = (struct read_req_t*)malloc(sizeof(struct read_req_t));
|
||||
req->cb = read_cb;
|
||||
req->buf = buffer;
|
||||
req->addr = addr;
|
||||
req->size = len;
|
||||
req->wait = len;
|
||||
req->dirty = 0;
|
||||
req->next = NULL;
|
||||
|
||||
/* add this to the request list */
|
||||
if (!wm->read_req) {
|
||||
/* root node */
|
||||
wm->read_req = req;
|
||||
|
||||
WIIUSE_DEBUG("Data read request can be sent out immediately.");
|
||||
|
||||
/* send the request out immediately */
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
} else {
|
||||
struct read_req_t* nptr = wm->read_req;
|
||||
for (; nptr->next; nptr = nptr->next);
|
||||
nptr->next = req;
|
||||
|
||||
WIIUSE_DEBUG("Added pending data read request.");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Read data from the wiimote (event version).
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param buffer An allocated buffer to store the data as it arrives from the wiimote.
|
||||
* Must be persistent in memory and large enough to hold the data.
|
||||
* @param addr The address of wiimote memory to read from.
|
||||
* @param len The length of the block to be read.
|
||||
*
|
||||
* The library can only handle one data read request at a time
|
||||
* because it must keep track of the buffer and other
|
||||
* events that are specific to that request. So if a request
|
||||
* has already been made, subsequent requests will be added
|
||||
* to a pending list and be sent out when the previous
|
||||
* finishes.
|
||||
*/
|
||||
int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int addr, unsigned short len) {
|
||||
struct read_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
if (!buffer || !len)
|
||||
return 0;
|
||||
|
||||
/* make this request structure */
|
||||
req = (struct read_req_t*)malloc(sizeof(struct read_req_t));
|
||||
req->cb = NULL;
|
||||
req->buf = buffer;
|
||||
req->addr = addr;
|
||||
req->size = len;
|
||||
req->wait = len;
|
||||
req->dirty = 0;
|
||||
req->next = NULL;
|
||||
|
||||
/* add this to the request list */
|
||||
if (!wm->read_req) {
|
||||
/* root node */
|
||||
wm->read_req = req;
|
||||
|
||||
WIIUSE_DEBUG("Data read request can be sent out immediately.");
|
||||
|
||||
/* send the request out immediately */
|
||||
wiiuse_send_next_pending_read_request(wm);
|
||||
} else {
|
||||
struct read_req_t* nptr = wm->read_req;
|
||||
for (; nptr->next; nptr = nptr->next);
|
||||
nptr->next = req;
|
||||
|
||||
WIIUSE_DEBUG("Added pending data read request.");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send the next pending data read request to the wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* @see wiiuse_read_data()
|
||||
*
|
||||
* This function is not part of the wiiuse API.
|
||||
*/
|
||||
void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) {
|
||||
byte buf[6];
|
||||
struct read_req_t* req;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
if (!wm->read_req) return;
|
||||
|
||||
/* skip over dirty ones since they have already been read */
|
||||
req = wm->read_req;
|
||||
while (req && req->dirty)
|
||||
req = req->next;
|
||||
if (!req)
|
||||
return;
|
||||
|
||||
/* the offset is in big endian */
|
||||
*(int*)(buf) = BIG_ENDIAN_LONG(req->addr);
|
||||
|
||||
/* the length is in big endian */
|
||||
*(short*)(buf + 4) = BIG_ENDIAN_SHORT(req->size);
|
||||
|
||||
WIIUSE_DEBUG("Request read at address: 0x%x length: %i", req->addr, req->size);
|
||||
wiiuse_send(wm, WM_CMD_READ_DATA, buf, 6);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Request the wiimote controller status.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*
|
||||
* Controller status includes: battery level, LED status, expansions
|
||||
*/
|
||||
void wiiuse_status(struct wiimote_t* wm) {
|
||||
byte buf = 0;
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return;
|
||||
|
||||
WIIUSE_DEBUG("Requested wiimote status.");
|
||||
|
||||
wiiuse_send(wm, WM_CMD_CTRL_STATUS, &buf, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Find a wiimote_t structure by its unique identifier.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param wiimotes The number of wiimote_t structures in \a wm.
|
||||
* @param unid The unique identifier to search for.
|
||||
*
|
||||
* @return Pointer to a wiimote_t structure, or NULL if not found.
|
||||
*/
|
||||
struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) {
|
||||
int i = 0;
|
||||
|
||||
for (; i < wiimotes; ++i) {
|
||||
if (wm[i]->unid == unid)
|
||||
return wm[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Write data to the wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param addr The address to write to.
|
||||
* @param data The data to be written to the memory location.
|
||||
* @param len The length of the block to be written.
|
||||
*/
|
||||
int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len) {
|
||||
byte buf[21] = {0}; /* the payload is always 23 */
|
||||
|
||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
||||
return 0;
|
||||
if (!data || !len)
|
||||
return 0;
|
||||
|
||||
WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr);
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int i = 0;
|
||||
printf("Write data is: ");
|
||||
for (; i < len; ++i)
|
||||
printf("%x ", data[i]);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* the offset is in big endian */
|
||||
*(int*)(buf) = BIG_ENDIAN_LONG(addr);
|
||||
|
||||
/* length */
|
||||
*(byte*)(buf + 4) = len;
|
||||
|
||||
/* data */
|
||||
memcpy(buf + 5, data, len);
|
||||
|
||||
wiiuse_send(wm, WM_CMD_WRITE_DATA, buf, 21);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Send a packet to the wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param report_type The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h
|
||||
* @param msg The payload.
|
||||
* @param len Length of the payload in bytes.
|
||||
*
|
||||
* This function should replace any write()s directly to the wiimote device.
|
||||
*/
|
||||
int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
|
||||
byte buf[32]; /* no payload is better than this */
|
||||
int rumble = 0;
|
||||
|
||||
#ifndef WIN32
|
||||
buf[0] = WM_SET_REPORT | WM_BT_OUTPUT;
|
||||
buf[1] = report_type;
|
||||
#else
|
||||
buf[0] = report_type;
|
||||
#endif
|
||||
|
||||
switch (report_type) {
|
||||
case WM_CMD_LED:
|
||||
case WM_CMD_RUMBLE:
|
||||
case WM_CMD_CTRL_STATUS:
|
||||
{
|
||||
/* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */
|
||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
||||
rumble = 1;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
memcpy(buf+2, msg, len);
|
||||
if (rumble)
|
||||
buf[2] |= 0x01;
|
||||
#else
|
||||
memcpy(buf+1, msg, len);
|
||||
if (rumble)
|
||||
buf[1] |= 0x01;
|
||||
#endif
|
||||
|
||||
#ifdef WITH_WIIUSE_DEBUG
|
||||
{
|
||||
int x = 2;
|
||||
printf("[DEBUG] (id %i) SEND: (%x) %.2x ", wm->unid, buf[0], buf[1]);
|
||||
#ifndef WIN32
|
||||
for (; x < len+2; ++x)
|
||||
#else
|
||||
for (; x < len+1; ++x)
|
||||
#endif
|
||||
printf("%.2x ", buf[x]);
|
||||
printf("\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef WIN32
|
||||
return wiiuse_io_write(wm, buf, len+2);
|
||||
#else
|
||||
return wiiuse_io_write(wm, buf, len+1);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set flags for the specified wiimote.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param enable Flags to enable.
|
||||
* @param disable Flags to disable.
|
||||
*
|
||||
* @return The flags set after 'enable' and 'disable' have been applied.
|
||||
*
|
||||
* The values 'enable' and 'disable' may be any flags OR'ed together.
|
||||
* Flags are defined in wiiuse.h.
|
||||
*/
|
||||
int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
|
||||
if (!wm) return 0;
|
||||
|
||||
/* remove mutually exclusive flags */
|
||||
enable &= ~disable;
|
||||
disable &= ~enable;
|
||||
|
||||
wm->flags |= enable;
|
||||
wm->flags &= ~disable;
|
||||
|
||||
return wm->flags;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the wiimote smoothing alpha value.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param alpha The alpha value to set. Between 0 and 1.
|
||||
*
|
||||
* @return Returns the old alpha value.
|
||||
*
|
||||
* The alpha value is between 0 and 1 and is used in an exponential
|
||||
* smoothing algorithm.
|
||||
*
|
||||
* Smoothing is only performed if the WIIMOTE_USE_SMOOTHING is set.
|
||||
*/
|
||||
float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) {
|
||||
float old;
|
||||
|
||||
if (!wm) return 0.0f;
|
||||
|
||||
old = wm->accel_calib.st_alpha;
|
||||
|
||||
wm->accel_calib.st_alpha = alpha;
|
||||
|
||||
/* if there is a nunchuk set that too */
|
||||
if (wm->exp.type == EXP_NUNCHUK)
|
||||
wm->exp.nunchuk.accel_calib.st_alpha = alpha;
|
||||
|
||||
return old;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the bluetooth stack type to use.
|
||||
*
|
||||
* @param wm Array of wiimote_t structures.
|
||||
* @param wiimotes Number of objects in the wm array.
|
||||
* @param type The type of bluetooth stack to use.
|
||||
*/
|
||||
void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type) {
|
||||
#ifdef WIN32
|
||||
int i;
|
||||
|
||||
if (!wm) return;
|
||||
|
||||
for (i = 0; i < wiimotes; ++i)
|
||||
wm[i]->stack = type;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the orientation event threshold.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*
|
||||
* If threshold is 0.01, and any angle changes by 0.01 then a significant change
|
||||
* has occured and the event callback will be invoked. If threshold is 1 then
|
||||
* the angle has to change by a full degree to generate an event.
|
||||
*/
|
||||
void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->orient_threshold = threshold;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the accelerometer event threshold.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param threshold The decimal place that should be considered a significant change.
|
||||
*/
|
||||
void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->accel_threshold = threshold;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Try to resync with the wiimote by starting a new handshake.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
*/
|
||||
void wiiuse_resync(struct wiimote_t* wm) {
|
||||
if (!wm) return;
|
||||
|
||||
wm->handshake_state = 0;
|
||||
wiiuse_handshake(wm, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set the normal and expansion handshake timeouts.
|
||||
*
|
||||
* @param wm Array of wiimote_t structures.
|
||||
* @param wiimotes Number of objects in the wm array.
|
||||
* @param normal_timeout The timeout in milliseconds for a normal read.
|
||||
* @param exp_timeout The timeout in millisecondsd to wait for an expansion handshake.
|
||||
*/
|
||||
void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout) {
|
||||
#ifdef WIN32
|
||||
int i;
|
||||
|
||||
if (!wm) return;
|
||||
|
||||
for (i = 0; i < wiimotes; ++i) {
|
||||
wm[i]->normal_timeout = normal_timeout;
|
||||
wm[i]->exp_timeout = exp_timeout;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
653
cpp/wiiuse/wiiuse.h
Normal file
653
cpp/wiiuse/wiiuse.h
Normal file
@@ -0,0 +1,653 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @brief API header file.
|
||||
*
|
||||
* If this file is included from inside the wiiuse source
|
||||
* and not from a third party program, then wiimote_internal.h
|
||||
* is also included which extends this file.
|
||||
*/
|
||||
|
||||
#ifndef WIIUSE_H_INCLUDED
|
||||
#define WIIUSE_H_INCLUDED
|
||||
|
||||
#ifdef _WIN32
|
||||
/* windows */
|
||||
#include <windows.h>
|
||||
#else
|
||||
/* nix */
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_INTERNAL_H_INCLUDED
|
||||
#define WCONST
|
||||
#else
|
||||
#define WCONST const
|
||||
#endif
|
||||
|
||||
/* led bit masks */
|
||||
#define WIIMOTE_LED_NONE 0x00
|
||||
#define WIIMOTE_LED_1 0x10
|
||||
#define WIIMOTE_LED_2 0x20
|
||||
#define WIIMOTE_LED_3 0x40
|
||||
#define WIIMOTE_LED_4 0x80
|
||||
|
||||
/* button codes */
|
||||
#define WIIMOTE_BUTTON_TWO 0x0001
|
||||
#define WIIMOTE_BUTTON_ONE 0x0002
|
||||
#define WIIMOTE_BUTTON_B 0x0004
|
||||
#define WIIMOTE_BUTTON_A 0x0008
|
||||
#define WIIMOTE_BUTTON_MINUS 0x0010
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040
|
||||
#define WIIMOTE_BUTTON_HOME 0x0080
|
||||
#define WIIMOTE_BUTTON_LEFT 0x0100
|
||||
#define WIIMOTE_BUTTON_RIGHT 0x0200
|
||||
#define WIIMOTE_BUTTON_DOWN 0x0400
|
||||
#define WIIMOTE_BUTTON_UP 0x0800
|
||||
#define WIIMOTE_BUTTON_PLUS 0x1000
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000
|
||||
#define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000
|
||||
#define WIIMOTE_BUTTON_UNKNOWN 0x8000
|
||||
#define WIIMOTE_BUTTON_ALL 0x1F9F
|
||||
|
||||
/* nunchul button codes */
|
||||
#define NUNCHUK_BUTTON_Z 0x01
|
||||
#define NUNCHUK_BUTTON_C 0x02
|
||||
#define NUNCHUK_BUTTON_ALL 0x03
|
||||
|
||||
/* classic controller button codes */
|
||||
#define CLASSIC_CTRL_BUTTON_UP 0x0001
|
||||
#define CLASSIC_CTRL_BUTTON_LEFT 0x0002
|
||||
#define CLASSIC_CTRL_BUTTON_ZR 0x0004
|
||||
#define CLASSIC_CTRL_BUTTON_X 0x0008
|
||||
#define CLASSIC_CTRL_BUTTON_A 0x0010
|
||||
#define CLASSIC_CTRL_BUTTON_Y 0x0020
|
||||
#define CLASSIC_CTRL_BUTTON_B 0x0040
|
||||
#define CLASSIC_CTRL_BUTTON_ZL 0x0080
|
||||
#define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
|
||||
#define CLASSIC_CTRL_BUTTON_PLUS 0x0400
|
||||
#define CLASSIC_CTRL_BUTTON_HOME 0x0800
|
||||
#define CLASSIC_CTRL_BUTTON_MINUS 0x1000
|
||||
#define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
|
||||
#define CLASSIC_CTRL_BUTTON_DOWN 0x4000
|
||||
#define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
|
||||
#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
|
||||
|
||||
/* guitar hero 3 button codes */
|
||||
#define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
|
||||
#define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
|
||||
#define GUITAR_HERO_3_BUTTON_GREEN 0x0010
|
||||
#define GUITAR_HERO_3_BUTTON_BLUE 0x0020
|
||||
#define GUITAR_HERO_3_BUTTON_RED 0x0040
|
||||
#define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
|
||||
#define GUITAR_HERO_3_BUTTON_PLUS 0x0400
|
||||
#define GUITAR_HERO_3_BUTTON_MINUS 0x1000
|
||||
#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
|
||||
#define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
|
||||
|
||||
|
||||
/* wiimote option flags */
|
||||
#define WIIUSE_SMOOTHING 0x01
|
||||
#define WIIUSE_CONTINUOUS 0x02
|
||||
#define WIIUSE_ORIENT_THRESH 0x04
|
||||
#define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH)
|
||||
|
||||
#define WIIUSE_ORIENT_PRECISION 100.0f
|
||||
|
||||
/* expansion codes */
|
||||
#define EXP_NONE 0
|
||||
#define EXP_NUNCHUK 1
|
||||
#define EXP_CLASSIC 2
|
||||
#define EXP_GUITAR_HERO_3 3
|
||||
|
||||
/* IR correction types */
|
||||
typedef enum ir_position_t {
|
||||
WIIUSE_IR_ABOVE,
|
||||
WIIUSE_IR_BELOW
|
||||
} ir_position_t;
|
||||
|
||||
/**
|
||||
* @brief Check if a button is pressed.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is pressed, 0 if not.
|
||||
*/
|
||||
#define IS_PRESSED(dev, button) ((dev->btns & button) == button)
|
||||
|
||||
/**
|
||||
* @brief Check if a button is being held.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is held, 0 if not.
|
||||
*/
|
||||
#define IS_HELD(dev, button) ((dev->btns_held & button) == button)
|
||||
|
||||
/**
|
||||
* @brief Check if a button is released on this event. \n\n
|
||||
* This does not mean the button is not pressed, it means \n
|
||||
* this button was just now released.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is released, 0 if not.
|
||||
*
|
||||
*/
|
||||
#define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
|
||||
|
||||
/**
|
||||
* @brief Check if a button has just been pressed this event.
|
||||
* @param dev Pointer to a wiimote_t or expansion structure.
|
||||
* @param button The button you are interested in.
|
||||
* @return 1 if the button is pressed, 0 if not.
|
||||
*/
|
||||
#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
|
||||
|
||||
/**
|
||||
* @brief Return the IR sensitivity level.
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param lvl [out] Pointer to an int that will hold the level setting.
|
||||
* If no level is set 'lvl' will be set to 0.
|
||||
*/
|
||||
#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
|
||||
do { \
|
||||
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
|
||||
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
|
||||
else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
|
||||
else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
|
||||
else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
|
||||
else *lvl = 0; \
|
||||
} while (0)
|
||||
|
||||
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
|
||||
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
|
||||
#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
|
||||
#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
|
||||
|
||||
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
|
||||
|
||||
/*
|
||||
* Largest known payload is 21 bytes.
|
||||
* Add 2 for the prefix and round up to a power of 2.
|
||||
*/
|
||||
#define MAX_PAYLOAD 32
|
||||
|
||||
/*
|
||||
* This is left over from an old hack, but it may actually
|
||||
* be a useful feature to keep so it wasn't removed.
|
||||
*/
|
||||
#ifdef WIN32
|
||||
#define WIIMOTE_DEFAULT_TIMEOUT 10
|
||||
#define WIIMOTE_EXP_TIMEOUT 10
|
||||
#endif
|
||||
|
||||
typedef unsigned char byte;
|
||||
typedef char sbyte;
|
||||
|
||||
struct wiimote_t;
|
||||
struct vec3b_t;
|
||||
struct orient_t;
|
||||
struct gforce_t;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Callback that handles a read event.
|
||||
*
|
||||
* @param wm Pointer to a wiimote_t structure.
|
||||
* @param data Pointer to the filled data block.
|
||||
* @param len Length in bytes of the data block.
|
||||
*
|
||||
* @see wiiuse_init()
|
||||
*
|
||||
* A registered function of this type is called automatically by the wiiuse
|
||||
* library when the wiimote has returned the full data requested by a previous
|
||||
* call to wiiuse_read_data().
|
||||
*/
|
||||
typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len);
|
||||
|
||||
|
||||
/**
|
||||
* @struct read_req_t
|
||||
* @brief Data read request structure.
|
||||
*/
|
||||
struct read_req_t {
|
||||
wiiuse_read_cb cb; /**< read data callback */
|
||||
byte* buf; /**< buffer where read data is written */
|
||||
unsigned int addr; /**< the offset that the read started at */
|
||||
unsigned short size; /**< the length of the data read */
|
||||
unsigned short wait; /**< num bytes still needed to finish read */
|
||||
byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */
|
||||
|
||||
struct read_req_t* next; /**< next read request in the queue */
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec2b_t
|
||||
* @brief Unsigned x,y byte vector.
|
||||
*/
|
||||
typedef struct vec2b_t {
|
||||
byte x, y;
|
||||
} vec2b_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3b_t
|
||||
* @brief Unsigned x,y,z byte vector.
|
||||
*/
|
||||
typedef struct vec3b_t {
|
||||
byte x, y, z;
|
||||
} vec3b_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct vec3f_t
|
||||
* @brief Signed x,y,z float struct.
|
||||
*/
|
||||
typedef struct vec3f_t {
|
||||
float x, y, z;
|
||||
} vec3f_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct orient_t
|
||||
* @brief Orientation struct.
|
||||
*
|
||||
* Yaw, pitch, and roll range from -180 to 180 degrees.
|
||||
*/
|
||||
typedef struct orient_t {
|
||||
float roll; /**< roll, this may be smoothed if enabled */
|
||||
float pitch; /**< pitch, this may be smoothed if enabled */
|
||||
float yaw;
|
||||
|
||||
float a_roll; /**< absolute roll, unsmoothed */
|
||||
float a_pitch; /**< absolute pitch, unsmoothed */
|
||||
} orient_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct gforce_t
|
||||
* @brief Gravity force struct.
|
||||
*/
|
||||
typedef struct gforce_t {
|
||||
float x, y, z;
|
||||
} gforce_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct accel_t
|
||||
* @brief Accelerometer struct. For any device with an accelerometer.
|
||||
*/
|
||||
typedef struct accel_t {
|
||||
struct vec3b_t cal_zero; /**< zero calibration */
|
||||
struct vec3b_t cal_g; /**< 1g difference around 0cal */
|
||||
|
||||
float st_roll; /**< last smoothed roll value */
|
||||
float st_pitch; /**< last smoothed roll pitch */
|
||||
float st_alpha; /**< alpha value for smoothing [0-1] */
|
||||
} accel_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_dot_t
|
||||
* @brief A single IR source.
|
||||
*/
|
||||
typedef struct ir_dot_t {
|
||||
byte visible; /**< if the IR source is visible */
|
||||
|
||||
unsigned int x; /**< interpolated X coordinate */
|
||||
unsigned int y; /**< interpolated Y coordinate */
|
||||
|
||||
short rx; /**< raw X coordinate (0-1023) */
|
||||
short ry; /**< raw Y coordinate (0-767) */
|
||||
|
||||
byte order; /**< increasing order by x-axis value */
|
||||
|
||||
byte size; /**< size of the IR dot (0-15) */
|
||||
} ir_dot_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum aspect_t
|
||||
* @brief Screen aspect ratio.
|
||||
*/
|
||||
typedef enum aspect_t {
|
||||
WIIUSE_ASPECT_4_3,
|
||||
WIIUSE_ASPECT_16_9
|
||||
} aspect_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct ir_t
|
||||
* @brief IR struct. Hold all data related to the IR tracking.
|
||||
*/
|
||||
typedef struct ir_t {
|
||||
struct ir_dot_t dot[4]; /**< IR dots */
|
||||
byte num_dots; /**< number of dots at this time */
|
||||
|
||||
enum aspect_t aspect; /**< aspect ratio of the screen */
|
||||
|
||||
enum ir_position_t pos; /**< IR sensor bar position */
|
||||
|
||||
unsigned int vres[2]; /**< IR virtual screen resolution */
|
||||
int offset[2]; /**< IR XY correction offset */
|
||||
int state; /**< keeps track of the IR state */
|
||||
|
||||
int ax; /**< absolute X coordinate */
|
||||
int ay; /**< absolute Y coordinate */
|
||||
|
||||
int x; /**< calculated X coordinate */
|
||||
int y; /**< calculated Y coordinate */
|
||||
|
||||
float distance; /**< pixel distance between first 2 dots*/
|
||||
float z; /**< calculated distance */
|
||||
} ir_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct joystick_t
|
||||
* @brief Joystick calibration structure.
|
||||
*
|
||||
* The angle \a ang is relative to the positive y-axis into quadrant I
|
||||
* and ranges from 0 to 360 degrees. So if the joystick is held straight
|
||||
* upwards then angle is 0 degrees. If it is held to the right it is 90,
|
||||
* down is 180, and left is 270.
|
||||
*
|
||||
* The magnitude \a mag is the distance from the center to where the
|
||||
* joystick is being held. The magnitude ranges from 0 to 1.
|
||||
* If the joystick is only slightly tilted from the center the magnitude
|
||||
* will be low, but if it is closer to the outter edge the value will
|
||||
* be higher.
|
||||
*/
|
||||
typedef struct joystick_t {
|
||||
struct vec2b_t max; /**< maximum joystick values */
|
||||
struct vec2b_t min; /**< minimum joystick values */
|
||||
struct vec2b_t center; /**< center joystick values */
|
||||
|
||||
float ang; /**< angle the joystick is being held */
|
||||
float mag; /**< magnitude of the joystick (range 0-1) */
|
||||
} joystick_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct nunchuk_t
|
||||
* @brief Nunchuk expansion device.
|
||||
*/
|
||||
typedef struct nunchuk_t {
|
||||
struct accel_t accel_calib; /**< nunchuk accelerometer calibration */
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
|
||||
int* flags; /**< options flag (points to wiimote_t.flags) */
|
||||
|
||||
byte btns; /**< what buttons have just been pressed */
|
||||
byte btns_held; /**< what buttons are being held down */
|
||||
byte btns_released; /**< what buttons were just released this */
|
||||
|
||||
float orient_threshold; /**< threshold for orient to generate an event */
|
||||
int accel_threshold; /**< threshold for accel to generate an event */
|
||||
|
||||
struct vec3b_t accel; /**< current raw acceleration data */
|
||||
struct orient_t orient; /**< current orientation on each axis */
|
||||
struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
} nunchuk_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct classic_ctrl_t
|
||||
* @brief Classic controller expansion device.
|
||||
*/
|
||||
typedef struct classic_ctrl_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
float r_shoulder; /**< right shoulder button (range 0-1) */
|
||||
float l_shoulder; /**< left shoulder button (range 0-1) */
|
||||
|
||||
struct joystick_t ljs; /**< left joystick calibration */
|
||||
struct joystick_t rjs; /**< right joystick calibration */
|
||||
} classic_ctrl_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct guitar_hero_3_t
|
||||
* @brief Guitar Hero 3 expansion device.
|
||||
*/
|
||||
typedef struct guitar_hero_3_t {
|
||||
short btns; /**< what buttons have just been pressed */
|
||||
short btns_held; /**< what buttons are being held down */
|
||||
short btns_released; /**< what buttons were just released this */
|
||||
|
||||
float whammy_bar; /**< whammy bar (range 0-1) */
|
||||
|
||||
struct joystick_t js; /**< joystick calibration */
|
||||
} guitar_hero_3_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct expansion_t
|
||||
* @brief Generic expansion device plugged into wiimote.
|
||||
*/
|
||||
typedef struct expansion_t {
|
||||
int type; /**< type of expansion attached */
|
||||
|
||||
union {
|
||||
struct nunchuk_t nunchuk;
|
||||
struct classic_ctrl_t classic;
|
||||
struct guitar_hero_3_t gh3;
|
||||
};
|
||||
} expansion_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum win32_bt_stack_t
|
||||
* @brief Available bluetooth stacks for Windows.
|
||||
*/
|
||||
typedef enum win_bt_stack_t {
|
||||
WIIUSE_STACK_UNKNOWN,
|
||||
WIIUSE_STACK_MS,
|
||||
WIIUSE_STACK_BLUESOLEIL
|
||||
} win_bt_stack_t;
|
||||
|
||||
|
||||
/**
|
||||
* @struct wiimote_state_t
|
||||
* @brief Significant data from the previous event.
|
||||
*/
|
||||
typedef struct wiimote_state_t {
|
||||
/* expansion_t */
|
||||
float exp_ljs_ang;
|
||||
float exp_rjs_ang;
|
||||
float exp_ljs_mag;
|
||||
float exp_rjs_mag;
|
||||
unsigned short exp_btns;
|
||||
struct orient_t exp_orient;
|
||||
struct vec3b_t exp_accel;
|
||||
float exp_r_shoulder;
|
||||
float exp_l_shoulder;
|
||||
|
||||
/* ir_t */
|
||||
int ir_ax;
|
||||
int ir_ay;
|
||||
float ir_distance;
|
||||
|
||||
struct orient_t orient;
|
||||
unsigned short btns;
|
||||
|
||||
struct vec3b_t accel;
|
||||
} wiimote_state_t;
|
||||
|
||||
|
||||
/**
|
||||
* @enum WIIUSE_EVENT_TYPE
|
||||
* @brief Events that wiiuse can generate from a poll.
|
||||
*/
|
||||
typedef enum WIIUSE_EVENT_TYPE {
|
||||
WIIUSE_NONE = 0,
|
||||
WIIUSE_EVENT,
|
||||
WIIUSE_STATUS,
|
||||
WIIUSE_CONNECT,
|
||||
WIIUSE_DISCONNECT,
|
||||
WIIUSE_UNEXPECTED_DISCONNECT,
|
||||
WIIUSE_READ_DATA,
|
||||
WIIUSE_NUNCHUK_INSERTED,
|
||||
WIIUSE_NUNCHUK_REMOVED,
|
||||
WIIUSE_CLASSIC_CTRL_INSERTED,
|
||||
WIIUSE_CLASSIC_CTRL_REMOVED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
|
||||
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED
|
||||
} WIIUSE_EVENT_TYPE;
|
||||
|
||||
/**
|
||||
* @struct wiimote_t
|
||||
* @brief Wiimote structure.
|
||||
*/
|
||||
typedef struct wiimote_t {
|
||||
WCONST int unid; /**< user specified id */
|
||||
|
||||
#ifndef WIN32
|
||||
WCONST bdaddr_t bdaddr; /**< bt address */
|
||||
WCONST char bdaddr_str[18]; /**< readable bt address */
|
||||
WCONST int out_sock; /**< output socket */
|
||||
WCONST int in_sock; /**< input socket */
|
||||
#else
|
||||
WCONST HANDLE dev_handle; /**< HID handle */
|
||||
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
|
||||
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
|
||||
WCONST int timeout; /**< read timeout */
|
||||
WCONST byte normal_timeout; /**< normal timeout */
|
||||
WCONST byte exp_timeout; /**< timeout for expansion handshake */
|
||||
#endif
|
||||
|
||||
WCONST int state; /**< various state flags */
|
||||
WCONST byte leds; /**< currently lit leds */
|
||||
WCONST float battery_level; /**< battery level */
|
||||
|
||||
WCONST int flags; /**< options flag */
|
||||
|
||||
WCONST byte handshake_state; /**< the state of the connection handshake */
|
||||
|
||||
WCONST struct read_req_t* read_req; /**< list of data read requests */
|
||||
WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
|
||||
WCONST struct expansion_t exp; /**< wiimote expansion device */
|
||||
|
||||
WCONST struct vec3b_t accel; /**< current raw acceleration data */
|
||||
WCONST struct orient_t orient; /**< current orientation on each axis */
|
||||
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
|
||||
|
||||
WCONST struct ir_t ir; /**< IR data */
|
||||
|
||||
WCONST unsigned short btns; /**< what buttons have just been pressed */
|
||||
WCONST unsigned short btns_held; /**< what buttons are being held down */
|
||||
WCONST unsigned short btns_released; /**< what buttons were just released this */
|
||||
|
||||
WCONST float orient_threshold; /**< threshold for orient to generate an event */
|
||||
WCONST int accel_threshold; /**< threshold for accel to generate an event */
|
||||
|
||||
WCONST struct wiimote_state_t lstate; /**< last saved state */
|
||||
|
||||
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
|
||||
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
|
||||
} wiimote;
|
||||
|
||||
|
||||
/*****************************************
|
||||
*
|
||||
* Include API specific stuff
|
||||
*
|
||||
*****************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIIUSE_EXPORT_DECL __declspec(dllexport)
|
||||
#define WIIUSE_IMPORT_DECL __declspec(dllimport)
|
||||
#else
|
||||
#define WIIUSE_EXPORT_DECL
|
||||
#define WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef WIIUSE_COMPILE_LIB
|
||||
#define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
|
||||
#else
|
||||
#define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* wiiuse.c */
|
||||
WIIUSE_EXPORT extern const char* wiiuse_version();
|
||||
|
||||
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
|
||||
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
|
||||
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
|
||||
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
|
||||
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
|
||||
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
/* connect.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
|
||||
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
|
||||
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
|
||||
|
||||
/* events.c */
|
||||
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
|
||||
|
||||
/* ir.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
|
||||
|
||||
/* nunchuk.c */
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
|
||||
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* WIIUSE_H_INCLUDED */
|
||||
|
||||
226
cpp/wiiuse/wiiuse_internal.h
Normal file
226
cpp/wiiuse/wiiuse_internal.h
Normal file
@@ -0,0 +1,226 @@
|
||||
/*
|
||||
* wiiuse
|
||||
*
|
||||
* Written By:
|
||||
* Michael Laforest < para >
|
||||
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
|
||||
*
|
||||
* Copyright 2006-2007
|
||||
*
|
||||
* This file is part of wiiuse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Header$
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief General internal wiiuse stuff.
|
||||
*
|
||||
* Since Wiiuse is a library, wiiuse.h is a duplicate
|
||||
* of the API header.
|
||||
*
|
||||
* The code that would normally go in that file, but
|
||||
* which is not needed by third party developers,
|
||||
* is put here.
|
||||
*
|
||||
* So wiiuse_internal.h is included by other files
|
||||
* internally, wiiuse.h is included only here.
|
||||
*/
|
||||
|
||||
#ifndef WIIUSE_INTERNAL_H_INCLUDED
|
||||
#define WIIUSE_INTERNAL_H_INCLUDED
|
||||
|
||||
#ifndef WIN32
|
||||
#include <arpa/inet.h> /* htons() */
|
||||
#include <bluetooth/bluetooth.h>
|
||||
#endif
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
/* wiiuse version */
|
||||
#define WIIUSE_VERSION "0.12"
|
||||
|
||||
/********************
|
||||
*
|
||||
* Wiimote internal codes
|
||||
*
|
||||
********************/
|
||||
|
||||
/* Communication channels */
|
||||
#define WM_OUTPUT_CHANNEL 0x11
|
||||
#define WM_INPUT_CHANNEL 0x13
|
||||
|
||||
#define WM_SET_REPORT 0x50
|
||||
|
||||
/* commands */
|
||||
#define WM_CMD_LED 0x11
|
||||
#define WM_CMD_REPORT_TYPE 0x12
|
||||
#define WM_CMD_RUMBLE 0x13
|
||||
#define WM_CMD_IR 0x13
|
||||
#define WM_CMD_CTRL_STATUS 0x15
|
||||
#define WM_CMD_WRITE_DATA 0x16
|
||||
#define WM_CMD_READ_DATA 0x17
|
||||
#define WM_CMD_IR_2 0x1A
|
||||
|
||||
/* input report ids */
|
||||
#define WM_RPT_CTRL_STATUS 0x20
|
||||
#define WM_RPT_READ 0x21
|
||||
#define WM_RPT_WRITE 0x22
|
||||
#define WM_RPT_BTN 0x30
|
||||
#define WM_RPT_BTN_ACC 0x31
|
||||
#define WM_RPT_BTN_ACC_IR 0x33
|
||||
#define WM_RPT_BTN_EXP 0x34
|
||||
#define WM_RPT_BTN_ACC_EXP 0x35
|
||||
#define WM_RPT_BTN_IR_EXP 0x36
|
||||
#define WM_RPT_BTN_ACC_IR_EXP 0x37
|
||||
|
||||
#define WM_BT_INPUT 0x01
|
||||
#define WM_BT_OUTPUT 0x02
|
||||
|
||||
/* Identify the wiimote device by its class */
|
||||
#define WM_DEV_CLASS_0 0x04
|
||||
#define WM_DEV_CLASS_1 0x25
|
||||
#define WM_DEV_CLASS_2 0x00
|
||||
#define WM_VENDOR_ID 0x057E
|
||||
#define WM_PRODUCT_ID 0x0306
|
||||
|
||||
/* controller status stuff */
|
||||
#define WM_MAX_BATTERY_CODE 0xC8
|
||||
|
||||
/* offsets in wiimote memory */
|
||||
#define WM_MEM_OFFSET_CALIBRATION 0x16
|
||||
#define WM_EXP_MEM_BASE 0x04A40000
|
||||
#define WM_EXP_MEM_ENABLE 0x04A40040
|
||||
#define WM_EXP_MEM_CALIBR 0x04A40020
|
||||
|
||||
#define WM_REG_IR 0x04B00030
|
||||
#define WM_REG_IR_BLOCK1 0x04B00000
|
||||
#define WM_REG_IR_BLOCK2 0x04B0001A
|
||||
#define WM_REG_IR_MODENUM 0x04B00033
|
||||
|
||||
/* ir block data */
|
||||
#define WM_IR_BLOCK1_LEVEL1 "\x02\x00\x00\x71\x01\x00\x64\x00\xfe"
|
||||
#define WM_IR_BLOCK2_LEVEL1 "\xfd\x05"
|
||||
#define WM_IR_BLOCK1_LEVEL2 "\x02\x00\x00\x71\x01\x00\x96\x00\xb4"
|
||||
#define WM_IR_BLOCK2_LEVEL2 "\xb3\x04"
|
||||
#define WM_IR_BLOCK1_LEVEL3 "\x02\x00\x00\x71\x01\x00\xaa\x00\x64"
|
||||
#define WM_IR_BLOCK2_LEVEL3 "\x63\x03"
|
||||
#define WM_IR_BLOCK1_LEVEL4 "\x02\x00\x00\x71\x01\x00\xc8\x00\x36"
|
||||
#define WM_IR_BLOCK2_LEVEL4 "\x35\x03"
|
||||
#define WM_IR_BLOCK1_LEVEL5 "\x07\x00\x00\x71\x01\x00\x72\x00\x20"
|
||||
#define WM_IR_BLOCK2_LEVEL5 "\x1f\x03"
|
||||
|
||||
#define WM_IR_TYPE_BASIC 0x01
|
||||
#define WM_IR_TYPE_EXTENDED 0x03
|
||||
|
||||
/* controller status flags for the first message byte */
|
||||
/* bit 1 is unknown */
|
||||
#define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02
|
||||
#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04
|
||||
#define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_1 0x10
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_2 0x20
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_3 0x40
|
||||
#define WM_CTRL_STATUS_BYTE1_LED_4 0x80
|
||||
|
||||
/* aspect ratio */
|
||||
#define WM_ASPECT_16_9_X 660
|
||||
#define WM_ASPECT_16_9_Y 370
|
||||
#define WM_ASPECT_4_3_X 560
|
||||
#define WM_ASPECT_4_3_Y 420
|
||||
|
||||
|
||||
/**
|
||||
* Expansion stuff
|
||||
*/
|
||||
|
||||
/* encrypted expansion id codes (located at 0x04A400FC) */
|
||||
#define EXP_ID_CODE_NUNCHUK 0x9A1EFEFE
|
||||
#define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD
|
||||
#define EXP_ID_CODE_GUITAR 0x9A1EFDFB
|
||||
|
||||
#define EXP_HANDSHAKE_LEN 224
|
||||
|
||||
/********************
|
||||
*
|
||||
* End Wiimote internal codes
|
||||
*
|
||||
********************/
|
||||
|
||||
/* wiimote state flags - (some duplicated in wiiuse.h)*/
|
||||
#define WIIMOTE_STATE_DEV_FOUND 0x0001
|
||||
#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 /* actual connection exists but no handshake yet */
|
||||
#define WIIMOTE_STATE_CONNECTED 0x0008
|
||||
#define WIIMOTE_STATE_RUMBLE 0x0010
|
||||
#define WIIMOTE_STATE_ACC 0x0020
|
||||
#define WIIMOTE_STATE_EXP 0x0040
|
||||
#define WIIMOTE_STATE_IR 0x0080
|
||||
#define WIIMOTE_STATE_SPEAKER 0x0100
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL1 0x0200
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL2 0x0400
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL3 0x0800
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL4 0x1000
|
||||
#define WIIMOTE_STATE_IR_SENS_LVL5 0x2000
|
||||
|
||||
#define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3)
|
||||
|
||||
/* macro to manage states */
|
||||
#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s))
|
||||
#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s))
|
||||
#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s))
|
||||
#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
|
||||
|
||||
#define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s))
|
||||
#define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s))
|
||||
#define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s))
|
||||
#define WIIMOTE_TOGGLE_FLAG(wm, s) ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
|
||||
|
||||
#define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s))
|
||||
|
||||
/* misc macros */
|
||||
#define WIIMOTE_ID(wm) (wm->unid)
|
||||
#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED))
|
||||
|
||||
/*
|
||||
* Smooth tilt calculations are computed with the
|
||||
* exponential moving average formula:
|
||||
* St = St_last + (alpha * (tilt - St_last))
|
||||
* alpha is between 0 and 1
|
||||
*/
|
||||
#define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f
|
||||
|
||||
#define SMOOTH_ROLL 0x01
|
||||
#define SMOOTH_PITCH 0x02
|
||||
|
||||
#include "wiiuse.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* not part of the api */
|
||||
int wiiuse_set_report_type(struct wiimote_t* wm);
|
||||
void wiiuse_send_next_pending_read_request(struct wiimote_t* wm);
|
||||
int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len);
|
||||
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int offset, unsigned short len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* WIIUSE_INTERNAL_H_INCLUDED */
|
||||
BIN
cpp/wiiusej/lib/wiiuse.lib
Normal file
BIN
cpp/wiiusej/lib/wiiuse.lib
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user