diff options
author | patthoyts <patthoyts> | 2005-02-28 15:10:40 +0000 |
---|---|---|
committer | patthoyts <patthoyts> | 2005-02-28 15:10:40 +0000 |
commit | a11037ca6adfe358d1ea7adaf6d143200da59f32 (patch) | |
tree | 903fb481e9196ceb3433c78039a8248b85b27bb0 /jim-win32.c | |
parent | d2eede78abab64cc2c8f746c2195ef56d17ffd3f (diff) | |
download | jimtcl-a11037ca6adfe358d1ea7adaf6d143200da59f32.zip jimtcl-a11037ca6adfe358d1ea7adaf6d143200da59f32.tar.gz jimtcl-a11037ca6adfe358d1ea7adaf6d143200da59f32.tar.bz2 |
Added some more API functions, Beep, GetComputerName, SetComputerName,
GetUserName, GetVersion, GetTickCount, GetSystemTime.
Diffstat (limited to 'jim-win32.c')
-rw-r--r-- | jim-win32.c | 154 |
1 files changed, 151 insertions, 3 deletions
diff --git a/jim-win32.c b/jim-win32.c index 253becd..e640b0d 100644 --- a/jim-win32.c +++ b/jim-win32.c @@ -22,6 +22,7 @@ #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <shellapi.h> +#include <lmcons.h> #include <ctype.h> #define JIM_EXTENSION @@ -30,6 +31,7 @@ #if _MSC_VER >= 1000 #pragma comment(lib, "shell32") #pragma comment(lib, "user32") +#pragma comment(lib, "advapi32") #endif /* _MSC_VER >= 1000 */ __declspec(dllexport) int Jim_OnLoad(Jim_Interp *interp); @@ -83,7 +85,8 @@ Win32_ShellExecute(Jim_Interp *interp, int objc, Jim_Obj **objv) parm = Jim_GetString(objv[3], NULL); r = (int)ShellExecuteA(NULL, verb, file, parm, cwd, SW_SHOWNORMAL); if (r < 33) - Jim_SetResult(interp, Win32ErrorObj(interp, "shellexecute", GetLastError())); + Jim_SetResult(interp, + Win32ErrorObj(interp, "ShellExecute", GetLastError())); return (r < 33) ? JIM_ERR : JIM_OK; } @@ -106,7 +109,8 @@ Win32_FindWindow(Jim_Interp *interp, int objc, Jim_Obj **objv) hwnd = FindWindowA(class, title); if (hwnd == NULL) { - Jim_SetResult(interp, Win32ErrorObj(interp, "findwindow", GetLastError())); + Jim_SetResult(interp, + Win32ErrorObj(interp, "FindWindow", GetLastError())); r = JIM_ERR; } else { Jim_SetResult(interp, Jim_NewIntObj(interp, (long)hwnd)); @@ -128,12 +132,149 @@ Win32_CloseWindow(Jim_Interp *interp, int objc, Jim_Obj **objv) return JIM_ERR; if (!CloseWindow((HWND)hwnd)) { Jim_SetResult(interp, - Win32ErrorObj(interp, "closewindow", GetLastError())); + Win32ErrorObj(interp, "CloseWindow", GetLastError())); return JIM_ERR; } return JIM_OK; } + +static int +Win32_Beep(Jim_Interp *interp, int objc, Jim_Obj **objv) +{ + long freq, duration; + int r = JIM_OK; + + if (objc != 3) { + Jim_WrongNumArgs(interp, 1, objv, "freq duration"); + return JIM_ERR; + } + r = Jim_GetLong(interp, objv[1], &freq); + if (r == JIM_OK) + r = Jim_GetLong(interp, objv[2], &duration); + if (freq < 0x25) freq = 0x25; + if (freq > 0x7fff) freq = 0x7fff; + if (r == JIM_OK) { + if (!Beep(freq, duration)) { + Jim_SetResult(interp, + Win32ErrorObj(interp, "Beep", GetLastError())); + r = JIM_ERR; + } + } + return r; +} + +static int +Win32_GetComputerName(Jim_Interp *interp, int objc, Jim_Obj **objv) +{ + char name[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD size = MAX_COMPUTERNAME_LENGTH; + int r = JIM_OK; + + if (objc != 1) { + Jim_WrongNumArgs(interp, 1, objv, ""); + return JIM_ERR; + } + + if (GetComputerNameA(name, &size)) { + Jim_Obj *nameObj = Jim_NewStringObj(interp, name, size); + Jim_SetResult(interp, nameObj); + } else { + Jim_SetResult(interp, + Win32ErrorObj(interp, "GetComputerName", GetLastError())); + r = JIM_ERR; + } + + return r; +} + +static int +Win32_GetUserName(Jim_Interp *interp, int objc, Jim_Obj **objv) +{ + char name[UNLEN + 1]; + DWORD size = UNLEN; + int r = JIM_OK; + + if (objc != 1) { + Jim_WrongNumArgs(interp, 1, objv, ""); + return JIM_ERR; + } + + if (GetUserNameA(name, &size)) { + Jim_Obj *nameObj = Jim_NewStringObj(interp, name, size); + Jim_SetResult(interp, nameObj); + } else { + Jim_SetResult(interp, + Win32ErrorObj(interp, "GetUserName", GetLastError())); + r = JIM_ERR; + } + + return r; +} + + +static int +Win32_GetVersion(Jim_Interp *interp, int objc, Jim_Obj **objv) +{ + Jim_SetResult(interp, Jim_NewIntObj(interp, GetVersion())); + return JIM_OK; +} + +static int +Win32_GetTickCount(Jim_Interp *interp, int objc, Jim_Obj **objv) +{ + Jim_SetResult(interp, Jim_NewIntObj(interp, GetTickCount())); + return JIM_OK; +} + +static int +Win32_GetSystemTime(Jim_Interp *interp, int objc, Jim_Obj **objv) +{ + Jim_Obj *a[16]; + SYSTEMTIME t; + GetSystemTime(&t); + + a[0] = Jim_NewStringObj(interp, "year", -1); + a[1] = Jim_NewIntObj(interp, t.wYear); + a[2] = Jim_NewStringObj(interp, "month", -1); + a[3] = Jim_NewIntObj(interp, t.wMonth); + a[4] = Jim_NewStringObj(interp, "dayofweek", -1); + a[5] = Jim_NewIntObj(interp, t.wDayOfWeek); + a[6] = Jim_NewStringObj(interp, "day", -1); + a[7] = Jim_NewIntObj(interp, t.wDay); + a[8] = Jim_NewStringObj(interp, "hour", -1); + a[9] = Jim_NewIntObj(interp, t.wHour); + a[10] = Jim_NewStringObj(interp, "minute", -1); + a[11] = Jim_NewIntObj(interp, t.wMinute); + a[12] = Jim_NewStringObj(interp, "second", -1); + a[13] = Jim_NewIntObj(interp, t.wSecond); + a[14] = Jim_NewStringObj(interp, "milliseconds", -1); + a[15] = Jim_NewIntObj(interp, t.wMilliseconds); + + Jim_SetResult(interp, Jim_NewListObj(interp, a, 16)); + return JIM_OK; +} + + +static int +Win32_SetComputerName(Jim_Interp *interp, int objc, Jim_Obj **objv) +{ + int r = JIM_OK; + char *name; + if (objc != 2) { + Jim_WrongNumArgs(interp, 1, objv, "computername"); + return JIM_ERR; + } + name = Jim_GetString(objv[1], NULL); + if (!SetComputerNameA(name)) { + Jim_SetResult(interp, + Win32ErrorObj(interp, "SetComputerName", GetLastError())); + r = JIM_ERR; + } + return r; +} + + /* ---------------------------------------------------------------------- */ int Jim_OnLoad(Jim_Interp *interp) @@ -142,5 +283,12 @@ Jim_OnLoad(Jim_Interp *interp) Jim_CreateCommand(interp, "win32.ShellExecute", Win32_ShellExecute, NULL); Jim_CreateCommand(interp, "win32.FindWindow", Win32_FindWindow, NULL); Jim_CreateCommand(interp, "win32.CloseWindow", Win32_CloseWindow, NULL); + Jim_CreateCommand(interp, "win32.Beep", Win32_Beep, NULL); + Jim_CreateCommand(interp, "win32.GetComputerName", Win32_GetComputerName, NULL); + Jim_CreateCommand(interp, "win32.SetComputerName", Win32_SetComputerName, NULL); + Jim_CreateCommand(interp, "win32.GetUserName", Win32_GetUserName, NULL); + Jim_CreateCommand(interp, "win32.GetVersion", Win32_GetVersion, NULL); + Jim_CreateCommand(interp, "win32.GetTickCount", Win32_GetTickCount, NULL); + Jim_CreateCommand(interp, "win32.GetSystemTime", Win32_GetSystemTime, NULL); return JIM_OK; } |