summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-09-20 15:02:42 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-09-20 15:02:42 (GMT)
commit213711869322b5aa9b50b4eed31a91f662c058bb (patch)
tree3129e6f519777439ff66f3605a0375be5af01133 /win
parent3147adf34639c8a4c2aa49422c70fafb3b59c722 (diff)
parent1ed3c75ba4badbf5e1aece5cbc3d976d1f699fa2 (diff)
downloadtcl-213711869322b5aa9b50b4eed31a91f662c058bb.zip
tcl-213711869322b5aa9b50b4eed31a91f662c058bb.tar.gz
tcl-213711869322b5aa9b50b4eed31a91f662c058bb.tar.bz2
Modify registry/dde such that they no longer need to be compiled with -DUNICODE. Also no longer use Tcl_WinTCharToUtf/Tcl_WinUtfToTchar but the unicode conversions functions to do WCHAR <=> UTF-8 conversions.
When compiled with Tcl >= 8.7, use the TIP #548 wchar_t functions in stead for registry/dde. No need to update the registry/dde version numbers (1.3.3 resp. 1.4.1), because those were recentely bumped already, after the Tcl 8.6.9 release.
Diffstat (limited to 'win')
-rw-r--r--win/tclWinDde.c293
-rw-r--r--win/tclWinReg.c155
2 files changed, 259 insertions, 189 deletions
diff --git a/win/tclWinDde.c b/win/tclWinDde.c
index 27ddfc8..6fa9cc2 100644
--- a/win/tclWinDde.c
+++ b/win/tclWinDde.c
@@ -34,7 +34,7 @@ typedef struct RegisteredInterp {
struct RegisteredInterp *nextPtr;
/* The next interp this application knows
* about. */
- TCHAR *name; /* Interpreter's name (malloc-ed). */
+ WCHAR *name; /* Interpreter's name (malloc-ed). */
Tcl_Obj *handlerPtr; /* The server handler command */
Tcl_Interp *interp; /* The interpreter attached to this name. */
} RegisteredInterp;
@@ -81,8 +81,8 @@ static int ddeIsServer = 0;
#define TCL_DDE_VERSION "1.4.1"
#define TCL_DDE_PACKAGE_NAME "dde"
-#define TCL_DDE_SERVICE_NAME TEXT("TclEval")
-#define TCL_DDE_EXECUTE_RESULT TEXT("$TCLEVAL$EXECUTE$RESULT")
+#define TCL_DDE_SERVICE_NAME L"TclEval"
+#define TCL_DDE_EXECUTE_RESULT L"$TCLEVAL$EXECUTE$RESULT"
#define DDE_FLAG_ASYNC 1
#define DDE_FLAG_BINARY 2
@@ -99,24 +99,34 @@ static LRESULT CALLBACK DdeClientWindowProc(HWND hwnd, UINT uMsg,
static int DdeCreateClient(DdeEnumServices *es);
static BOOL CALLBACK DdeEnumWindowsCallback(HWND hwndTarget,
LPARAM lParam);
-static void DdeExitProc(ClientData clientData);
+static void DdeExitProc(void *clientData);
static int DdeGetServicesList(Tcl_Interp *interp,
- const TCHAR *serviceName, const TCHAR *topicName);
+ const WCHAR *serviceName, const WCHAR *topicName);
static HDDEDATA CALLBACK DdeServerProc(UINT uType, UINT uFmt, HCONV hConv,
HSZ ddeTopic, HSZ ddeItem, HDDEDATA hData,
DWORD dwData1, DWORD dwData2);
static LRESULT DdeServicesOnAck(HWND hwnd, WPARAM wParam,
LPARAM lParam);
-static void DeleteProc(ClientData clientData);
+static void DeleteProc(void *clientData);
static Tcl_Obj * ExecuteRemoteObject(RegisteredInterp *riPtr,
Tcl_Obj *ddeObjectPtr);
static int MakeDdeConnection(Tcl_Interp *interp,
- const TCHAR *name, HCONV *ddeConvPtr);
+ const WCHAR *name, HCONV *ddeConvPtr);
static void SetDdeError(Tcl_Interp *interp);
-static int DdeObjCmd(ClientData clientData,
+static int DdeObjCmd(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
+#if (TCL_MAJOR_VERSION < 9) && (TCL_MINOR_VERSION < 7)
+# if TCL_UTF_MAX > 3
+# define Tcl_WCharToUtfDString(a,b,c) Tcl_WinTCharToUtf(a,(b)*sizeof(WCHAR),c)
+# define Tcl_UtfToWCharDString(a,b,c) Tcl_WinUtfToTChar(a,b,c)
+# else
+# define Tcl_WCharToUtfDString Tcl_UniCharToUtfDString
+# define Tcl_UtfToWCharDString Tcl_UtfToUniCharDString
+# endif
+#endif
+
static unsigned char *
getByteArrayFromObj(
Tcl_Obj *objPtr,
@@ -136,8 +146,14 @@ getByteArrayFromObj(
return result;
}
+#ifdef __cplusplus
+extern "C" {
+#endif
DLLEXPORT int Dde_Init(Tcl_Interp *interp);
DLLEXPORT int Dde_SafeInit(Tcl_Interp *interp);
+#ifdef __cplusplus
+}
+#endif
/*
*----------------------------------------------------------------------
@@ -159,13 +175,13 @@ int
Dde_Init(
Tcl_Interp *interp)
{
- if (!Tcl_InitStubs(interp, "8.1", 0)) {
+ if (!Tcl_InitStubs(interp, "8.5-", 0)) {
return TCL_ERROR;
}
Tcl_CreateObjCommand(interp, "dde", DdeObjCmd, NULL, NULL);
Tcl_CreateExitHandler(DdeExitProc, NULL);
- return Tcl_PkgProvide(interp, TCL_DDE_PACKAGE_NAME, TCL_DDE_VERSION);
+ return Tcl_PkgProvideEx(interp, TCL_DDE_PACKAGE_NAME, TCL_DDE_VERSION, NULL);
}
/*
@@ -235,7 +251,7 @@ Initialize(void)
if (ddeInstance == 0) {
Tcl_MutexLock(&ddeMutex);
if (ddeInstance == 0) {
- if (DdeInitialize(&ddeInstance, (PFNCALLBACK) DdeServerProc,
+ if (DdeInitializeW(&ddeInstance, (PFNCALLBACK) DdeServerProc,
CBF_SKIP_REGISTRATIONS | CBF_SKIP_UNREGISTRATIONS
| CBF_FAIL_POKES, 0) != DMLERR_NO_ERROR) {
ddeInstance = 0;
@@ -248,7 +264,7 @@ Initialize(void)
if ((ddeServiceGlobal == 0) && (nameFound != 0)) {
ddeIsServer = 1;
Tcl_CreateExitHandler(DdeExitProc, NULL);
- ddeServiceGlobal = DdeCreateStringHandle(ddeInstance,
+ ddeServiceGlobal = DdeCreateStringHandleW(ddeInstance,
TCL_DDE_SERVICE_NAME, CP_WINUNICODE);
DdeNameService(ddeInstance, ddeServiceGlobal, 0L, DNS_REGISTER);
} else {
@@ -283,10 +299,10 @@ Initialize(void)
*----------------------------------------------------------------------
*/
-static const TCHAR *
+static const WCHAR *
DdeSetServerName(
Tcl_Interp *interp,
- const TCHAR *name, /* The name that will be used to refer to the
+ const WCHAR *name, /* The name that will be used to refer to the
* interpreter in later "send" commands. Must
* be globally unique. */
int flags, /* DDE_FLAG_FORCE or 0 */
@@ -296,7 +312,7 @@ DdeSetServerName(
int suffix, offset;
RegisteredInterp *riPtr, *prevPtr;
Tcl_DString dString;
- const TCHAR *actualName;
+ const WCHAR *actualName;
Tcl_Obj *srvListPtr = NULL, **srvPtrPtr = NULL;
int n, srvCount = 0, lastSuffix, r = TCL_OK;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
@@ -334,7 +350,7 @@ DdeSetServerName(
* current interp, but it doesn't have a name.
*/
- return TEXT("");
+ return L"";
}
/*
@@ -355,8 +371,8 @@ DdeSetServerName(
&srvPtrPtr);
}
if (r != TCL_OK) {
- Tcl_WinUtfToTChar(Tcl_GetStringResult(interp), -1, &dString);
- OutputDebugString((TCHAR *) Tcl_DStringValue(&dString));
+ Tcl_DStringInit(&dString);
+ OutputDebugStringW(Tcl_UtfToWCharDString(Tcl_GetString(Tcl_GetObjResult(interp)), -1, &dString));
Tcl_DStringFree(&dString);
return NULL;
}
@@ -374,14 +390,14 @@ DdeSetServerName(
lastSuffix = suffix;
if (suffix > 1) {
if (suffix == 2) {
- Tcl_DStringAppend(&dString, (char *)name, _tcslen(name) * sizeof(TCHAR));
- Tcl_DStringAppend(&dString, (char *)TEXT(" #"), 2 * sizeof(TCHAR));
+ Tcl_DStringAppend(&dString, (char *)name, wcslen(name) * sizeof(WCHAR));
+ Tcl_DStringAppend(&dString, (char *)L" #", 2 * sizeof(WCHAR));
offset = Tcl_DStringLength(&dString);
- Tcl_DStringSetLength(&dString, offset + sizeof(TCHAR) * TCL_INTEGER_SPACE);
- actualName = (TCHAR *) Tcl_DStringValue(&dString);
+ Tcl_DStringSetLength(&dString, offset + sizeof(WCHAR) * TCL_INTEGER_SPACE);
+ actualName = (WCHAR *) Tcl_DStringValue(&dString);
}
- _sntprintf((TCHAR *) (Tcl_DStringValue(&dString) + offset),
- TCL_INTEGER_SPACE, TEXT("%d"), suffix);
+ _snwprintf((WCHAR *) (Tcl_DStringValue(&dString) + offset),
+ TCL_INTEGER_SPACE, L"%d", suffix);
}
/*
@@ -393,8 +409,9 @@ DdeSetServerName(
Tcl_DString ds;
Tcl_ListObjIndex(interp, srvPtrPtr[n], 1, &namePtr);
- Tcl_WinUtfToTChar(Tcl_GetString(namePtr), -1, &ds);
- if (_tcscmp(actualName, (TCHAR *)Tcl_DStringValue(&ds)) == 0) {
+ Tcl_DStringInit(&ds);
+ Tcl_UtfToWCharDString(Tcl_GetString(namePtr), -1, &ds);
+ if (wcscmp(actualName, (WCHAR *)Tcl_DStringValue(&ds)) == 0) {
suffix++;
Tcl_DStringFree(&ds);
break;
@@ -410,14 +427,14 @@ DdeSetServerName(
riPtr = (RegisteredInterp *) Tcl_Alloc(sizeof(RegisteredInterp));
riPtr->interp = interp;
- riPtr->name = (TCHAR *) Tcl_Alloc((_tcslen(actualName) + 1) * sizeof(TCHAR));
+ riPtr->name = (WCHAR *) Tcl_Alloc((wcslen(actualName) + 1) * sizeof(WCHAR));
riPtr->nextPtr = tsdPtr->interpListPtr;
riPtr->handlerPtr = handlerPtr;
if (riPtr->handlerPtr != NULL) {
Tcl_IncrRefCount(riPtr->handlerPtr);
}
tsdPtr->interpListPtr = riPtr;
- _tcscpy(riPtr->name, actualName);
+ wcscpy(riPtr->name, actualName);
if (Tcl_IsSafe(interp)) {
Tcl_ExposeCommand(interp, "dde", "dde");
@@ -489,8 +506,7 @@ DdeGetRegistrationPtr(
static void
DeleteProc(
- ClientData clientData) /* The interp we are deleting passed as
- * ClientData. */
+ void *clientData) /* The interp we are deleting. */
{
RegisteredInterp *riPtr = (RegisteredInterp *) clientData;
RegisteredInterp *searchPtr, *prevPtr;
@@ -627,18 +643,20 @@ DdeServerProc(
HSZ ddeTopic, HSZ ddeItem, /* String handles. Transaction-type
* dependent. */
HDDEDATA hData, /* DDE data. Transaction-type dependent. */
- DWORD dwData1, DWORD dwData2)
+ DWORD unused1, DWORD unused2)
/* Transaction-dependent data. */
{
Tcl_DString dString;
size_t len;
DWORD dlen;
- TCHAR *utilString;
+ WCHAR *utilString;
Tcl_Obj *ddeObjectPtr;
HDDEDATA ddeReturn = NULL;
RegisteredInterp *riPtr;
Conversation *convPtr, *prevConvPtr;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ (void)unused1;
+ (void)unused2;
switch(uType) {
case XTYP_CONNECT:
@@ -647,16 +665,16 @@ DdeServerProc(
* sure we have a valid topic.
*/
- len = DdeQueryString(ddeInstance, ddeTopic, NULL, 0, CP_WINUNICODE);
+ len = DdeQueryStringW(ddeInstance, ddeTopic, NULL, 0, CP_WINUNICODE);
Tcl_DStringInit(&dString);
- Tcl_DStringSetLength(&dString, (len + 1) * sizeof(TCHAR) - 1);
- utilString = (TCHAR *) Tcl_DStringValue(&dString);
- DdeQueryString(ddeInstance, ddeTopic, utilString, (DWORD) len + 1,
+ Tcl_DStringSetLength(&dString, (len + 1) * sizeof(WCHAR) - 1);
+ utilString = (WCHAR *) Tcl_DStringValue(&dString);
+ DdeQueryStringW(ddeInstance, ddeTopic, utilString, (DWORD) len + 1,
CP_WINUNICODE);
for (riPtr = tsdPtr->interpListPtr; riPtr != NULL;
riPtr = riPtr->nextPtr) {
- if (_tcsicmp(utilString, riPtr->name) == 0) {
+ if (_wcsicmp(utilString, riPtr->name) == 0) {
Tcl_DStringFree(&dString);
return (HDDEDATA) TRUE;
}
@@ -672,15 +690,15 @@ DdeServerProc(
* result to return in an XTYP_REQUEST.
*/
- len = DdeQueryString(ddeInstance, ddeTopic, NULL, 0, CP_WINUNICODE);
+ len = DdeQueryStringW(ddeInstance, ddeTopic, NULL, 0, CP_WINUNICODE);
Tcl_DStringInit(&dString);
- Tcl_DStringSetLength(&dString, (len + 1) * sizeof(TCHAR) - 1);
- utilString = (TCHAR *) Tcl_DStringValue(&dString);
- DdeQueryString(ddeInstance, ddeTopic, utilString, (DWORD) len + 1,
+ Tcl_DStringSetLength(&dString, (len + 1) * sizeof(WCHAR) - 1);
+ utilString = (WCHAR *) Tcl_DStringValue(&dString);
+ DdeQueryStringW(ddeInstance, ddeTopic, utilString, (DWORD) len + 1,
CP_WINUNICODE);
for (riPtr = tsdPtr->interpListPtr; riPtr != NULL;
riPtr = riPtr->nextPtr) {
- if (_tcsicmp(riPtr->name, utilString) == 0) {
+ if (_wcsicmp(riPtr->name, utilString) == 0) {
convPtr = (Conversation *) Tcl_Alloc(sizeof(Conversation));
convPtr->nextPtr = tsdPtr->currentConversations;
convPtr->returnPackagePtr = NULL;
@@ -740,21 +758,22 @@ DdeServerProc(
Tcl_DString dsBuf;
char *returnString;
- len = DdeQueryString(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE);
+ len = DdeQueryStringW(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE);
Tcl_DStringInit(&dString);
Tcl_DStringInit(&dsBuf);
- Tcl_DStringSetLength(&dString, (len + 1) * sizeof(TCHAR) - 1);
- utilString = (TCHAR *) Tcl_DStringValue(&dString);
- DdeQueryString(ddeInstance, ddeItem, utilString, (DWORD) len + 1,
+ Tcl_DStringSetLength(&dString, (len + 1) * sizeof(WCHAR) - 1);
+ utilString = (WCHAR *) Tcl_DStringValue(&dString);
+ DdeQueryStringW(ddeInstance, ddeItem, utilString, (DWORD) len + 1,
CP_WINUNICODE);
- if (_tcsicmp(utilString, TCL_DDE_EXECUTE_RESULT) == 0) {
+ if (_wcsicmp(utilString, TCL_DDE_EXECUTE_RESULT) == 0) {
returnString =
Tcl_GetString(convPtr->returnPackagePtr);
len = convPtr->returnPackagePtr->length;
if (uFmt != CF_TEXT) {
- Tcl_WinUtfToTChar(returnString, len, &dsBuf);
+ Tcl_DStringInit(&dsBuf);
+ Tcl_UtfToWCharDString(returnString, len, &dsBuf);
returnString = Tcl_DStringValue(&dsBuf);
- len = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR) - 1;
+ len = Tcl_DStringLength(&dsBuf) + sizeof(WCHAR) - 1;
}
ddeReturn = DdeCreateDataHandle(ddeInstance, (BYTE *)returnString,
(DWORD) len+1, 0, ddeItem, uFmt, 0);
@@ -765,7 +784,8 @@ DdeServerProc(
Tcl_DString ds;
Tcl_Obj *variableObjPtr;
- Tcl_WinTCharToUtf(utilString, -1, &ds);
+ Tcl_DStringInit(&ds);
+ Tcl_WCharToUtfDString(utilString, wcslen(utilString), &ds);
variableObjPtr = Tcl_GetVar2Ex(
convPtr->riPtr->interp, Tcl_DStringValue(&ds), NULL,
TCL_GLOBAL_ONLY);
@@ -773,9 +793,10 @@ DdeServerProc(
returnString = Tcl_GetString(variableObjPtr);
len = variableObjPtr->length;
if (uFmt != CF_TEXT) {
- Tcl_WinUtfToTChar(returnString, len, &dsBuf);
+ Tcl_DStringInit(&dsBuf);
+ Tcl_UtfToWCharDString(returnString, len, &dsBuf);
returnString = Tcl_DStringValue(&dsBuf);
- len = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR) - 1;
+ len = Tcl_DStringLength(&dsBuf) + sizeof(WCHAR) - 1;
}
ddeReturn = DdeCreateDataHandle(ddeInstance,
(BYTE *)returnString, (DWORD) len+1, 0, ddeItem,
@@ -817,17 +838,19 @@ DdeServerProc(
Tcl_DStringInit(&dString);
Tcl_DStringInit(&ds2);
- len = DdeQueryString(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE);
- Tcl_DStringSetLength(&dString, (len + 1) * sizeof(TCHAR) - 1);
- utilString = (TCHAR *) Tcl_DStringValue(&dString);
- DdeQueryString(ddeInstance, ddeItem, utilString, (DWORD) len + 1,
+ len = DdeQueryStringW(ddeInstance, ddeItem, NULL, 0, CP_WINUNICODE);
+ Tcl_DStringSetLength(&dString, (len + 1) * sizeof(WCHAR) - 1);
+ utilString = (WCHAR *) Tcl_DStringValue(&dString);
+ DdeQueryStringW(ddeInstance, ddeItem, utilString, (DWORD) len + 1,
CP_WINUNICODE);
- Tcl_WinTCharToUtf(utilString, -1, &ds);
- utilString = (TCHAR *) DdeAccessData(hData, &len2);
+ Tcl_DStringInit(&ds);
+ Tcl_WCharToUtfDString(utilString, wcslen(utilString), &ds);
+ utilString = (WCHAR *) DdeAccessData(hData, &len2);
len = len2;
if (uFmt != CF_TEXT) {
- Tcl_WinTCharToUtf(utilString, -1, &ds2);
- utilString = (TCHAR *) Tcl_DStringValue(&ds2);
+ Tcl_DStringInit(&ds2);
+ Tcl_WCharToUtfDString(utilString, wcslen(utilString), &ds2);
+ utilString = (WCHAR *) Tcl_DStringValue(&ds2);
}
variableObjPtr = Tcl_NewStringObj((char *)utilString, -1);
@@ -862,7 +885,7 @@ DdeServerProc(
return (HDDEDATA) DDE_FNOTPROCESSED;
}
- utilString = (TCHAR *) DdeAccessData(hData, &dlen);
+ utilString = (WCHAR *) DdeAccessData(hData, &dlen);
string = (char *) utilString;
if (!dlen) {
/* Empty binary array. */
@@ -877,7 +900,8 @@ DdeServerProc(
/* unicode */
Tcl_DString dsBuf;
- Tcl_WinTCharToUtf(utilString, dlen - sizeof(TCHAR), &dsBuf);
+ Tcl_DStringInit(&dsBuf);
+ Tcl_WCharToUtfDString(utilString, (dlen>>1) - 1, &dsBuf);
ddeObjectPtr = Tcl_NewStringObj(Tcl_DStringValue(&dsBuf),
Tcl_DStringLength(&dsBuf));
Tcl_DStringFree(&dsBuf);
@@ -932,9 +956,9 @@ DdeServerProc(
len = dlen;
for (i = 0, riPtr = tsdPtr->interpListPtr; i < numItems;
i++, riPtr = riPtr->nextPtr) {
- returnPtr[i].hszSvc = DdeCreateStringHandle(ddeInstance,
+ returnPtr[i].hszSvc = DdeCreateStringHandleW(ddeInstance,
TCL_DDE_SERVICE_NAME, CP_WINUNICODE);
- returnPtr[i].hszTopic = DdeCreateStringHandle(ddeInstance,
+ returnPtr[i].hszTopic = DdeCreateStringHandleW(ddeInstance,
riPtr->name, CP_WINUNICODE);
}
returnPtr[i].hszSvc = NULL;
@@ -966,8 +990,9 @@ DdeServerProc(
static void
DdeExitProc(
- ClientData clientData) /* Not used in this handler. */
+ void *dummy) /* Not used. */
{
+ (void)dummy;
DdeNameService(ddeInstance, NULL, 0, DNS_UNREGISTER);
DdeUninitialize(ddeInstance);
ddeInstance = 0;
@@ -993,14 +1018,14 @@ DdeExitProc(
static int
MakeDdeConnection(
Tcl_Interp *interp, /* Used to report errors. */
- const TCHAR *name, /* The connection to use. */
+ const WCHAR *name, /* The connection to use. */
HCONV *ddeConvPtr)
{
HSZ ddeTopic, ddeService;
HCONV ddeConv;
- ddeService = DdeCreateStringHandle(ddeInstance, TCL_DDE_SERVICE_NAME, CP_WINUNICODE);
- ddeTopic = DdeCreateStringHandle(ddeInstance, name, CP_WINUNICODE);
+ ddeService = DdeCreateStringHandleW(ddeInstance, TCL_DDE_SERVICE_NAME, CP_WINUNICODE);
+ ddeTopic = DdeCreateStringHandleW(ddeInstance, name, CP_WINUNICODE);
ddeConv = DdeConnect(ddeInstance, ddeService, ddeTopic, NULL);
DdeFreeStringHandle(ddeInstance, ddeService);
@@ -1010,7 +1035,8 @@ MakeDdeConnection(
if (interp != NULL) {
Tcl_DString dString;
- Tcl_WinTCharToUtf(name, -1, &dString);
+ Tcl_DStringInit(&dString);
+ Tcl_WCharToUtfDString(name, wcslen(name), &dString);
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"no registered server named \"%s\"", Tcl_DStringValue(&dString)));
Tcl_DStringFree(&dString);
@@ -1047,9 +1073,9 @@ static int
DdeCreateClient(
DdeEnumServices *es)
{
- WNDCLASSEX wc;
- static const TCHAR *szDdeClientClassName = TEXT("TclEval client class");
- static const TCHAR *szDdeClientWindowName = TEXT("TclEval client window");
+ WNDCLASSEXW wc;
+ static const WCHAR *szDdeClientClassName = L"TclEval client class";
+ static const WCHAR *szDdeClientWindowName = L"TclEval client window";
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(wc);
@@ -1061,8 +1087,8 @@ DdeCreateClient(
* Register and create the callback window.
*/
- RegisterClassEx(&wc);
- es->hwnd = CreateWindowEx(0, szDdeClientClassName, szDdeClientWindowName,
+ RegisterClassExW(&wc);
+ es->hwnd = CreateWindowExW(0, szDdeClientClassName, szDdeClientWindowName,
WS_POPUP, 0, 0, 0, 0, NULL, NULL, NULL, (LPVOID)es);
return TCL_OK;
}
@@ -1081,16 +1107,16 @@ DdeClientWindowProc(
(DdeEnumServices *) lpcs->lpCreateParams;
#ifdef _WIN64
- SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) es);
+ SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) es);
#else
- SetWindowLong(hwnd, GWL_USERDATA, (LONG) es);
+ SetWindowLongW(hwnd, GWL_USERDATA, (LONG) es);
#endif
return (LRESULT) 0L;
}
case WM_DDE_ACK:
return DdeServicesOnAck(hwnd, wParam, lParam);
default:
- return DefWindowProc(hwnd, uMsg, wParam, lParam);
+ return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}
}
@@ -1104,13 +1130,13 @@ DdeServicesOnAck(
ATOM service = (ATOM)LOWORD(lParam);
ATOM topic = (ATOM)HIWORD(lParam);
DdeEnumServices *es;
- TCHAR sz[255];
+ WCHAR sz[255];
Tcl_DString dString;
#ifdef _WIN64
- es = (DdeEnumServices *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ es = (DdeEnumServices *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
#else
- es = (DdeEnumServices *) GetWindowLong(hwnd, GWL_USERDATA);
+ es = (DdeEnumServices *) GetWindowLongW(hwnd, GWL_USERDATA);
#endif
if (((es->service == (ATOM)0) || (es->service == service))
@@ -1118,12 +1144,14 @@ DdeServicesOnAck(
Tcl_Obj *matchPtr = Tcl_NewListObj(0, NULL);
Tcl_Obj *resultPtr = Tcl_GetObjResult(es->interp);
- GlobalGetAtomName(service, sz, 255);
- Tcl_WinTCharToUtf(sz, -1, &dString);
+ GlobalGetAtomNameW(service, sz, 255);
+ Tcl_DStringInit(&dString);
+ Tcl_WCharToUtfDString(sz, wcslen(sz), &dString);
Tcl_ListObjAppendElement(NULL, matchPtr, Tcl_NewStringObj(Tcl_DStringValue(&dString), -1));
Tcl_DStringFree(&dString);
- GlobalGetAtomName(topic, sz, 255);
- Tcl_WinTCharToUtf(sz, -1, &dString);
+ GlobalGetAtomNameW(topic, sz, 255);
+ Tcl_DStringInit(&dString);
+ Tcl_WCharToUtfDString(sz, wcslen(sz), &dString);
Tcl_ListObjAppendElement(NULL, matchPtr, Tcl_NewStringObj(Tcl_DStringValue(&dString), -1));
Tcl_DStringFree(&dString);
@@ -1151,7 +1179,7 @@ DdeServicesOnAck(
* Tell the server we are no longer interested.
*/
- PostMessage(hwndRemote, WM_DDE_TERMINATE, (WPARAM)hwnd, 0L);
+ PostMessageW(hwndRemote, WM_DDE_TERMINATE, (WPARAM)hwnd, 0L);
return 0L;
}
@@ -1163,7 +1191,7 @@ DdeEnumWindowsCallback(
DWORD_PTR dwResult = 0;
DdeEnumServices *es = (DdeEnumServices *) lParam;
- SendMessageTimeout(hwndTarget, WM_DDE_INITIATE, (WPARAM)es->hwnd,
+ SendMessageTimeoutW(hwndTarget, WM_DDE_INITIATE, (WPARAM)es->hwnd,
MAKELONG(es->service, es->topic), SMTO_ABORTIFHUNG, 1000,
&dwResult);
return TRUE;
@@ -1172,16 +1200,16 @@ DdeEnumWindowsCallback(
static int
DdeGetServicesList(
Tcl_Interp *interp,
- const TCHAR *serviceName,
- const TCHAR *topicName)
+ const WCHAR *serviceName,
+ const WCHAR *topicName)
{
DdeEnumServices es;
es.interp = interp;
es.result = TCL_OK;
es.service = (serviceName == NULL)
- ? (ATOM)0 : GlobalAddAtom(serviceName);
- es.topic = (topicName == NULL) ? (ATOM)0 : GlobalAddAtom(topicName);
+ ? (ATOM)0 : GlobalAddAtomW(serviceName);
+ es.topic = (topicName == NULL) ? (ATOM)0 : GlobalAddAtomW(topicName);
Tcl_ResetResult(interp); /* our list is to be appended to result. */
DdeCreateClient(&es);
@@ -1265,7 +1293,7 @@ SetDdeError(
static int
DdeObjCmd(
- ClientData clientData, /* Used only for deletion */
+ void *dummy, /* Not used. */
Tcl_Interp *interp, /* The interp we are sending from */
int objc, /* Number of arguments */
Tcl_Obj *const *objv) /* The arguments */
@@ -1302,11 +1330,12 @@ DdeObjCmd(
HSZ ddeService = NULL, ddeTopic = NULL, ddeItem = NULL, ddeCookie = NULL;
HDDEDATA ddeData = NULL, ddeItemData = NULL, ddeReturn;
HCONV hConv = NULL;
- const TCHAR *serviceName = NULL, *topicName = NULL;
+ const WCHAR *serviceName = NULL, *topicName = NULL;
const char *string;
DWORD ddeResult;
Tcl_Obj *objPtr, *handlerPtr = NULL;
Tcl_DString serviceBuf, topicBuf, itemBuf;
+ (void)dummy;
/*
* Initialize DDE server/client
@@ -1462,9 +1491,10 @@ DdeObjCmd(
const char *src = Tcl_GetString(objv[firstArg]);
length = objv[firstArg]->length;
- Tcl_WinUtfToTChar(src, length, &serviceBuf);
- serviceName = (TCHAR *) Tcl_DStringValue(&serviceBuf);
- length = Tcl_DStringLength(&serviceBuf) / sizeof(TCHAR);
+ Tcl_DStringInit(&serviceBuf);
+ Tcl_UtfToWCharDString(src, length, &serviceBuf);
+ serviceName = (WCHAR *) Tcl_DStringValue(&serviceBuf);
+ length = Tcl_DStringLength(&serviceBuf) / sizeof(WCHAR);
} else {
length = 0;
}
@@ -1472,7 +1502,7 @@ DdeObjCmd(
if (length == 0) {
serviceName = NULL;
} else if ((index != DDE_SERVERNAME) && (index != DDE_EVAL)) {
- ddeService = DdeCreateStringHandle(ddeInstance, (void *) serviceName,
+ ddeService = DdeCreateStringHandleW(ddeInstance, serviceName,
CP_WINUNICODE);
}
@@ -1480,12 +1510,13 @@ DdeObjCmd(
const char *src = Tcl_GetString(objv[firstArg + 1]);
length = objv[firstArg + 1]->length;
- topicName = Tcl_WinUtfToTChar(src, length, &topicBuf);
- length = Tcl_DStringLength(&topicBuf) / sizeof(TCHAR);
+ Tcl_DStringInit(&topicBuf);
+ topicName = Tcl_UtfToWCharDString(src, length, &topicBuf);
+ length = Tcl_DStringLength(&topicBuf) / sizeof(WCHAR);
if (length == 0) {
topicName = NULL;
} else {
- ddeTopic = DdeCreateStringHandle(ddeInstance, (void *) topicName,
+ ddeTopic = DdeCreateStringHandleW(ddeInstance, topicName,
CP_WINUNICODE);
}
}
@@ -1497,7 +1528,8 @@ DdeObjCmd(
if (serviceName != NULL) {
Tcl_DString dsBuf;
- Tcl_WinTCharToUtf(serviceName, -1, &dsBuf);
+ Tcl_DStringInit(&dsBuf);
+ Tcl_WCharToUtfDString(serviceName, wcslen(serviceName), &dsBuf);
Tcl_SetObjResult(interp, Tcl_NewStringObj(Tcl_DStringValue(&dsBuf),
Tcl_DStringLength(&dsBuf)));
Tcl_DStringFree(&dsBuf);
@@ -1520,9 +1552,10 @@ DdeObjCmd(
src = Tcl_GetString(objv[firstArg + 2]);
dataLength = objv[firstArg + 2]->length;
- dataString = (const TCHAR *)
- Tcl_WinUtfToTChar(src, dataLength, &dsBuf);
- dataLength = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR);
+ Tcl_DStringInit(&dsBuf);
+ dataString =
+ Tcl_UtfToWCharDString(src, dataLength, &dsBuf);
+ dataLength = Tcl_DStringLength(&dsBuf) + sizeof(WCHAR);
}
if (dataLength + 1 < 2) {
@@ -1568,13 +1601,14 @@ DdeObjCmd(
break;
}
case DDE_REQUEST: {
- const TCHAR *itemString;
+ const WCHAR *itemString;
const char *src;
src = Tcl_GetString(objv[firstArg + 2]);
length = objv[firstArg + 2]->length;
- itemString = Tcl_WinUtfToTChar(src, length, &itemBuf);
- length = Tcl_DStringLength(&itemBuf) / sizeof(TCHAR);
+ Tcl_DStringInit(&itemBuf);
+ itemString = Tcl_UtfToWCharDString(src, length, &itemBuf);
+ length = Tcl_DStringLength(&itemBuf) / sizeof(WCHAR);
if (length == 0) {
Tcl_SetObjResult(interp,
@@ -1592,7 +1626,7 @@ DdeObjCmd(
result = TCL_ERROR;
} else {
Tcl_Obj *returnObjPtr;
- ddeItem = DdeCreateStringHandle(ddeInstance, (void *) itemString,
+ ddeItem = DdeCreateStringHandleW(ddeInstance, itemString,
CP_WINUNICODE);
if (ddeItem != NULL) {
ddeData = DdeClientTransaction(NULL, 0, hConv, ddeItem,
@@ -1602,7 +1636,7 @@ DdeObjCmd(
result = TCL_ERROR;
} else {
DWORD tmp;
- TCHAR *dataString = (TCHAR *) DdeAccessData(ddeData, &tmp);
+ WCHAR *dataString = (WCHAR *) DdeAccessData(ddeData, &tmp);
if (flags & DDE_FLAG_BINARY) {
returnObjPtr =
@@ -1610,11 +1644,12 @@ DdeObjCmd(
} else {
Tcl_DString dsBuf;
- if ((tmp >= sizeof(TCHAR))
- && !dataString[tmp / sizeof(TCHAR) - 1]) {
- tmp -= sizeof(TCHAR);
+ if ((tmp >= sizeof(WCHAR))
+ && !dataString[tmp / sizeof(WCHAR) - 1]) {
+ tmp -= sizeof(WCHAR);
}
- Tcl_WinTCharToUtf(dataString, tmp, &dsBuf);
+ Tcl_DStringInit(&dsBuf);
+ Tcl_WCharToUtfDString(dataString, tmp>>1, &dsBuf);
returnObjPtr =
Tcl_NewStringObj(Tcl_DStringValue(&dsBuf),
Tcl_DStringLength(&dsBuf));
@@ -1633,14 +1668,15 @@ DdeObjCmd(
}
case DDE_POKE: {
Tcl_DString dsBuf;
- const TCHAR *itemString;
+ const WCHAR *itemString;
BYTE *dataString;
const char *src;
src = Tcl_GetString(objv[firstArg + 2]);
length = objv[firstArg + 2]->length;
- itemString = Tcl_WinUtfToTChar(src, length, &itemBuf);
- length = Tcl_DStringLength(&itemBuf) / sizeof(TCHAR);
+ Tcl_DStringInit(&itemBuf);
+ itemString = Tcl_UtfToWCharDString(src, length, &itemBuf);
+ length = Tcl_DStringLength(&itemBuf) / sizeof(WCHAR);
if (length == 0) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("cannot have a null item", -1));
@@ -1656,9 +1692,10 @@ DdeObjCmd(
const char *data =
Tcl_GetString(objv[firstArg + 3]);
length = objv[firstArg + 3]->length;
+ Tcl_DStringInit(&dsBuf);
dataString = (BYTE *)
- Tcl_WinUtfToTChar(data, length, &dsBuf);
- length = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR);
+ Tcl_UtfToWCharDString(data, length, &dsBuf);
+ length = Tcl_DStringLength(&dsBuf) + sizeof(WCHAR);
}
hConv = DdeConnect(ddeInstance, ddeService, ddeTopic, NULL);
@@ -1669,7 +1706,7 @@ DdeObjCmd(
SetDdeError(interp);
result = TCL_ERROR;
} else {
- ddeItem = DdeCreateStringHandle(ddeInstance, (void *) itemString,
+ ddeItem = DdeCreateStringHandleW(ddeInstance, itemString,
CP_WINUNICODE);
if (ddeItem != NULL) {
ddeData = DdeClientTransaction(dataString, (DWORD) length,
@@ -1717,7 +1754,7 @@ DdeObjCmd(
for (riPtr = tsdPtr->interpListPtr; riPtr != NULL;
riPtr = riPtr->nextPtr) {
- if (_tcsicmp(serviceName, riPtr->name) == 0) {
+ if (_wcsicmp(serviceName, riPtr->name) == 0) {
break;
}
}
@@ -1820,9 +1857,10 @@ DdeObjCmd(
objPtr = Tcl_ConcatObj(objc, objv);
string = Tcl_GetString(objPtr);
length = objPtr->length;
- Tcl_WinUtfToTChar(string, length, &dsBuf);
+ Tcl_DStringInit(&dsBuf);
+ Tcl_UtfToWCharDString(string, length, &dsBuf);
string = Tcl_DStringValue(&dsBuf);
- length = Tcl_DStringLength(&dsBuf) + sizeof(TCHAR);
+ length = Tcl_DStringLength(&dsBuf) + sizeof(WCHAR);
ddeItemData = DdeCreateDataHandle(ddeInstance, (BYTE *) string,
(DWORD) length, 0, 0, CF_UNICODETEXT, 0);
Tcl_DStringFree(&dsBuf);
@@ -1837,7 +1875,7 @@ DdeObjCmd(
0xFFFFFFFF, hConv, 0,
CF_UNICODETEXT, XTYP_EXECUTE, 30000, NULL);
if (ddeData != 0) {
- ddeCookie = DdeCreateStringHandle(ddeInstance,
+ ddeCookie = DdeCreateStringHandleW(ddeInstance,
TCL_DDE_EXECUTE_RESULT, CP_WINUNICODE);
ddeData = DdeClientTransaction(NULL, 0, hConv, ddeCookie,
CF_UNICODETEXT, XTYP_REQUEST, 30000, NULL);
@@ -1854,7 +1892,7 @@ DdeObjCmd(
if (!(flags & DDE_FLAG_ASYNC)) {
Tcl_Obj *resultPtr;
- TCHAR *ddeDataString;
+ WCHAR *ddeDataString;
/*
* The return handle has a two or four element list in it. The
@@ -1866,12 +1904,13 @@ DdeObjCmd(
*/
length = DdeGetData(ddeData, NULL, 0, 0);
- ddeDataString = (TCHAR *) Tcl_Alloc(length);
+ ddeDataString = (WCHAR *) Tcl_Alloc(length);
DdeGetData(ddeData, (BYTE *) ddeDataString, (DWORD) length, 0);
- if (length > sizeof(TCHAR)) {
- length -= sizeof(TCHAR);
+ if (length > sizeof(WCHAR)) {
+ length -= sizeof(WCHAR);
}
- Tcl_WinTCharToUtf(ddeDataString, length, &dsBuf);
+ Tcl_DStringInit(&dsBuf);
+ Tcl_WCharToUtfDString(ddeDataString, length>>1, &dsBuf);
resultPtr = Tcl_NewStringObj(Tcl_DStringValue(&dsBuf),
Tcl_DStringLength(&dsBuf));
Tcl_DStringFree(&dsBuf);
diff --git a/win/tclWinReg.c b/win/tclWinReg.c
index f93a553..068e5d7 100644
--- a/win/tclWinReg.c
+++ b/win/tclWinReg.c
@@ -94,7 +94,7 @@ static void AppendSystemError(Tcl_Interp *interp, DWORD error);
static int BroadcastValue(Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
static DWORD ConvertDWORD(DWORD type, DWORD value);
-static void DeleteCmd(ClientData clientData);
+static void DeleteCmd(void *clientData);
static int DeleteKey(Tcl_Interp *interp, Tcl_Obj *keyNameObj,
REGSAM mode);
static int DeleteValue(Tcl_Interp *interp, Tcl_Obj *keyNameObj,
@@ -116,14 +116,24 @@ static int ParseKeyName(Tcl_Interp *interp, char *name,
char **hostNamePtr, HKEY *rootKeyPtr,
char **keyNamePtr);
static DWORD RecursiveDeleteKey(HKEY hStartKey,
- const TCHAR * pKeyName, REGSAM mode);
-static int RegistryObjCmd(ClientData clientData,
+ const WCHAR * pKeyName, REGSAM mode);
+static int RegistryObjCmd(void *clientData,
Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[]);
static int SetValue(Tcl_Interp *interp, Tcl_Obj *keyNameObj,
Tcl_Obj *valueNameObj, Tcl_Obj *dataObj,
Tcl_Obj *typeObj, REGSAM mode);
+#if (TCL_MAJOR_VERSION < 9) && (TCL_MINOR_VERSION < 7)
+# if TCL_UTF_MAX > 3
+# define Tcl_WCharToUtfDString(a,b,c) Tcl_WinTCharToUtf(a,(b)*sizeof(WCHAR),c)
+# define Tcl_UtfToWCharDString(a,b,c) Tcl_WinUtfToTChar(a,b,c)
+# else
+# define Tcl_WCharToUtfDString Tcl_UniCharToUtfDString
+# define Tcl_UtfToWCharDString Tcl_UtfToUniCharDString
+# endif
+#endif
+
static unsigned char *
getByteArrayFromObj(
Tcl_Obj *objPtr,
@@ -143,8 +153,14 @@ getByteArrayFromObj(
return result;
}
+#ifdef __cplusplus
+extern "C" {
+#endif
DLLEXPORT int Registry_Init(Tcl_Interp *interp);
DLLEXPORT int Registry_Unload(Tcl_Interp *interp, int flags);
+#ifdef __cplusplus
+}
+#endif
/*
*----------------------------------------------------------------------
@@ -168,14 +184,14 @@ Registry_Init(
{
Tcl_Command cmd;
- if (Tcl_InitStubs(interp, "8.5", 0) == NULL) {
+ if (Tcl_InitStubs(interp, "8.5-", 0) == NULL) {
return TCL_ERROR;
}
cmd = Tcl_CreateObjCommand(interp, "registry", RegistryObjCmd,
interp, DeleteCmd);
Tcl_SetAssocData(interp, REGISTRY_ASSOC_KEY, NULL, cmd);
- return Tcl_PkgProvide(interp, "registry", "1.3.3");
+ return Tcl_PkgProvideEx(interp, "registry", "1.3.3", NULL);
}
/*
@@ -201,6 +217,7 @@ Registry_Unload(
{
Tcl_Command cmd;
Tcl_Obj *objv[3];
+ (void)flags;
/*
* Unregister the registry package. There is no Tcl_PkgForget()
@@ -215,7 +232,7 @@ Registry_Unload(
* Delete the originally registered command.
*/
- cmd = Tcl_GetAssocData(interp, REGISTRY_ASSOC_KEY, NULL);
+ cmd = (Tcl_Command)Tcl_GetAssocData(interp, REGISTRY_ASSOC_KEY, NULL);
if (cmd != NULL) {
Tcl_DeleteCommandFromToken(interp, cmd);
}
@@ -242,9 +259,9 @@ Registry_Unload(
static void
DeleteCmd(
- ClientData clientData)
+ void *clientData)
{
- Tcl_Interp *interp = clientData;
+ Tcl_Interp *interp = (Tcl_Interp *)clientData;
Tcl_SetAssocData(interp, REGISTRY_ASSOC_KEY, NULL, NULL);
}
@@ -267,7 +284,7 @@ DeleteCmd(
static int
RegistryObjCmd(
- ClientData clientData, /* Not used. */
+ void *dummy, /* Not used. */
Tcl_Interp *interp, /* Current interpreter. */
int objc, /* Number of arguments. */
Tcl_Obj *const objv[]) /* Argument values. */
@@ -286,6 +303,7 @@ RegistryObjCmd(
static const char *const modes[] = {
"-32bit", "-64bit", NULL
};
+ (void)dummy;
if (objc < 2) {
wrongArgs:
@@ -415,7 +433,7 @@ DeleteKey(
REGSAM mode) /* Mode flags to pass. */
{
char *tail, *buffer, *hostName, *keyName;
- const TCHAR *nativeTail;
+ const WCHAR *nativeTail;
HKEY rootKey, subkey;
DWORD result;
Tcl_DString buf;
@@ -468,7 +486,8 @@ DeleteKey(
* Now we recursively delete the key and everything below it.
*/
- nativeTail = Tcl_WinUtfToTChar(tail, -1, &buf);
+ Tcl_DStringInit(&buf);
+ nativeTail = Tcl_UtfToWCharDString(tail, -1, &buf);
result = RecursiveDeleteKey(subkey, nativeTail, saveMode);
Tcl_DStringFree(&buf);
@@ -524,8 +543,9 @@ DeleteValue(
}
valueName = Tcl_GetString(valueNameObj);
- Tcl_WinUtfToTChar(valueName, valueNameObj->length, &ds);
- result = RegDeleteValue(key, (const TCHAR *)Tcl_DStringValue(&ds));
+ Tcl_DStringInit(&ds);
+ Tcl_UtfToWCharDString(valueName, valueNameObj->length, &ds);
+ result = RegDeleteValueW(key, (const WCHAR *)Tcl_DStringValue(&ds));
Tcl_DStringFree(&ds);
if (result != ERROR_SUCCESS) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
@@ -568,7 +588,7 @@ GetKeyNames(
{
const char *pattern; /* Pattern being matched against subkeys */
HKEY key; /* Handle to the key being examined */
- TCHAR buffer[MAX_KEY_LENGTH];
+ WCHAR buffer[MAX_KEY_LENGTH];
/* Buffer to hold the subkey name */
DWORD bufSize; /* Size of the buffer */
DWORD index; /* Position of the current subkey */
@@ -599,7 +619,7 @@ GetKeyNames(
resultPtr = Tcl_NewObj();
for (index = 0;; ++index) {
bufSize = MAX_KEY_LENGTH;
- result = RegEnumKeyEx(key, index, buffer, &bufSize,
+ result = RegEnumKeyExW(key, index, buffer, &bufSize,
NULL, NULL, NULL, NULL);
if (result != ERROR_SUCCESS) {
if (result == ERROR_NO_MORE_ITEMS) {
@@ -613,7 +633,8 @@ GetKeyNames(
}
break;
}
- name = Tcl_WinTCharToUtf(buffer, bufSize * sizeof(TCHAR), &ds);
+ Tcl_DStringInit(&ds);
+ name = Tcl_WCharToUtfDString(buffer, bufSize, &ds);
if (pattern && !Tcl_StringMatch(name, pattern)) {
Tcl_DStringFree(&ds);
continue;
@@ -663,7 +684,7 @@ GetType(
DWORD result, type;
Tcl_DString ds;
const char *valueName;
- const TCHAR *nativeValue;
+ const WCHAR *nativeValue;
/*
* Attempt to open the key for reading.
@@ -679,8 +700,9 @@ GetType(
*/
valueName = Tcl_GetString(valueNameObj);
- nativeValue = Tcl_WinUtfToTChar(valueName, valueNameObj->length, &ds);
- result = RegQueryValueEx(key, nativeValue, NULL, &type,
+ Tcl_DStringInit(&ds);
+ nativeValue = Tcl_UtfToWCharDString(valueName, valueNameObj->length, &ds);
+ result = RegQueryValueExW(key, nativeValue, NULL, &type,
NULL, NULL);
Tcl_DStringFree(&ds);
RegCloseKey(key);
@@ -732,7 +754,7 @@ GetValue(
{
HKEY key;
const char *valueName;
- const TCHAR *nativeValue;
+ const WCHAR *nativeValue;
DWORD result, length, type;
Tcl_DString data, buf;
@@ -757,12 +779,13 @@ GetValue(
Tcl_DStringInit(&data);
Tcl_DStringSetLength(&data, TCL_DSTRING_STATIC_SIZE - 1);
- length = TCL_DSTRING_STATIC_SIZE/sizeof(TCHAR) - 1;
+ length = TCL_DSTRING_STATIC_SIZE/sizeof(WCHAR) - 1;
valueName = Tcl_GetString(valueNameObj);
- nativeValue = Tcl_WinUtfToTChar(valueName, valueNameObj->length, &buf);
+ Tcl_DStringInit(&buf);
+ nativeValue = Tcl_UtfToWCharDString(valueName, valueNameObj->length, &buf);
- result = RegQueryValueEx(key, nativeValue, NULL, &type,
+ result = RegQueryValueExW(key, nativeValue, NULL, &type,
(BYTE *) Tcl_DStringValue(&data), &length);
while (result == ERROR_MORE_DATA) {
/*
@@ -771,9 +794,9 @@ GetValue(
* HKEY_PERFORMANCE_DATA
*/
- length = Tcl_DStringLength(&data) * (2 / sizeof(TCHAR));
- Tcl_DStringSetLength(&data, (int) length * sizeof(TCHAR));
- result = RegQueryValueEx(key, nativeValue,
+ length = Tcl_DStringLength(&data) * (2 / sizeof(WCHAR));
+ Tcl_DStringSetLength(&data, (int) length * sizeof(WCHAR));
+ result = RegQueryValueExW(key, nativeValue,
NULL, &type, (BYTE *) Tcl_DStringValue(&data), &length);
}
Tcl_DStringFree(&buf);
@@ -809,13 +832,13 @@ GetValue(
*/
while ((p < end) && *((WCHAR *) p) != 0) {
- WCHAR *wp;
+ WCHAR *wp = (WCHAR *) p;
- Tcl_WinTCharToUtf((TCHAR *) p, -1, &buf);
+ Tcl_DStringInit(&buf);
+ Tcl_WCharToUtfDString(wp, wcslen(wp), &buf);
Tcl_ListObjAppendElement(interp, resultPtr,
Tcl_NewStringObj(Tcl_DStringValue(&buf),
Tcl_DStringLength(&buf)));
- wp = (WCHAR *) p;
while (*wp++ != 0) {/* empty body */}
p = (char *) wp;
@@ -823,7 +846,9 @@ GetValue(
}
Tcl_SetObjResult(interp, resultPtr);
} else if ((type == REG_SZ) || (type == REG_EXPAND_SZ)) {
- Tcl_WinTCharToUtf((TCHAR *) Tcl_DStringValue(&data), -1, &buf);
+ WCHAR *wp = (WCHAR *) Tcl_DStringValue(&data);
+ Tcl_DStringInit(&buf);
+ Tcl_WCharToUtfDString((const WCHAR *)Tcl_DStringValue(&data), wcslen(wp), &buf);
Tcl_DStringResult(interp, &buf);
} else {
/*
@@ -880,7 +905,7 @@ GetValueNames(
resultPtr = Tcl_NewObj();
Tcl_DStringInit(&buffer);
- Tcl_DStringSetLength(&buffer, (int) (MAX_KEY_LENGTH * sizeof(TCHAR)));
+ Tcl_DStringSetLength(&buffer, (int) (MAX_KEY_LENGTH * sizeof(WCHAR)));
index = 0;
result = TCL_OK;
@@ -897,12 +922,11 @@ GetValueNames(
*/
size = MAX_KEY_LENGTH;
- while (RegEnumValue(key,index, (TCHAR *)Tcl_DStringValue(&buffer),
+ while (RegEnumValueW(key,index, (WCHAR *)Tcl_DStringValue(&buffer),
&size, NULL, NULL, NULL, NULL) == ERROR_SUCCESS) {
- size *= sizeof(TCHAR);
- Tcl_WinTCharToUtf((TCHAR *) Tcl_DStringValue(&buffer), (int) size,
- &ds);
+ Tcl_DStringInit(&ds);
+ Tcl_WCharToUtfDString((const WCHAR *)Tcl_DStringValue(&buffer), size, &ds);
name = Tcl_DStringValue(&ds);
if (!pattern || Tcl_StringMatch(name, pattern)) {
result = Tcl_ListObjAppendElement(interp, resultPtr,
@@ -1008,8 +1032,9 @@ OpenSubKey(
*/
if (hostName) {
- hostName = (char *) Tcl_WinUtfToTChar(hostName, -1, &buf);
- result = RegConnectRegistry((TCHAR *)hostName, rootKey,
+ Tcl_DStringInit(&buf);
+ hostName = (char *) Tcl_UtfToWCharDString(hostName, -1, &buf);
+ result = RegConnectRegistryW((WCHAR *)hostName, rootKey,
&rootKey);
Tcl_DStringFree(&buf);
if (result != ERROR_SUCCESS) {
@@ -1023,12 +1048,13 @@ OpenSubKey(
*/
if (keyName) {
- keyName = (char *) Tcl_WinUtfToTChar(keyName, -1, &buf);
+ Tcl_DStringInit(&buf);
+ keyName = (char *) Tcl_UtfToWCharDString(keyName, -1, &buf);
}
if (flags & REG_CREATE) {
DWORD create;
- result = RegCreateKeyEx(rootKey, (TCHAR *)keyName, 0, NULL,
+ result = RegCreateKeyExW(rootKey, (WCHAR *)keyName, 0, NULL,
REG_OPTION_NON_VOLATILE, mode, NULL, keyPtr, &create);
} else if (rootKey == HKEY_PERFORMANCE_DATA) {
/*
@@ -1039,7 +1065,7 @@ OpenSubKey(
*keyPtr = HKEY_PERFORMANCE_DATA;
result = ERROR_SUCCESS;
} else {
- result = RegOpenKeyEx(rootKey, (TCHAR *)keyName, 0, mode,
+ result = RegOpenKeyExW(rootKey, (WCHAR *)keyName, 0, mode,
keyPtr);
}
if (keyName) {
@@ -1159,7 +1185,7 @@ ParseKeyName(
static DWORD
RecursiveDeleteKey(
HKEY startKey, /* Parent of key to be deleted. */
- const TCHAR *keyName, /* Name of key to be deleted in external
+ const WCHAR *keyName, /* Name of key to be deleted in external
* encoding, not UTF. */
REGSAM mode) /* Mode flags to pass. */
{
@@ -1168,7 +1194,7 @@ RecursiveDeleteKey(
HKEY hKey;
REGSAM saveMode = mode;
static int checkExProc = 0;
- static FARPROC regDeleteKeyExProc = NULL;
+ static LSTATUS (* regDeleteKeyExProc) (HKEY, LPCWSTR, REGSAM, DWORD) = (LSTATUS (*) (HKEY, LPCWSTR, REGSAM, DWORD)) NULL;
/*
* Do not allow NULL or empty key name.
@@ -1179,13 +1205,13 @@ RecursiveDeleteKey(
}
mode |= KEY_ENUMERATE_SUB_KEYS | DELETE | KEY_QUERY_VALUE;
- result = RegOpenKeyEx(startKey, keyName, 0, mode, &hKey);
+ result = RegOpenKeyExW(startKey, keyName, 0, mode, &hKey);
if (result != ERROR_SUCCESS) {
return result;
}
Tcl_DStringInit(&subkey);
- Tcl_DStringSetLength(&subkey, (int) (MAX_KEY_LENGTH * sizeof(TCHAR)));
+ Tcl_DStringSetLength(&subkey, (int) (MAX_KEY_LENGTH * sizeof(WCHAR)));
mode = saveMode;
while (result == ERROR_SUCCESS) {
@@ -1194,7 +1220,7 @@ RecursiveDeleteKey(
*/
size = MAX_KEY_LENGTH;
- result = RegEnumKeyEx(hKey, 0, (TCHAR *)Tcl_DStringValue(&subkey),
+ result = RegEnumKeyExW(hKey, 0, (WCHAR *)Tcl_DStringValue(&subkey),
&size, NULL, NULL, NULL, NULL);
if (result == ERROR_NO_MORE_ITEMS) {
/*
@@ -1207,19 +1233,19 @@ RecursiveDeleteKey(
HMODULE handle;
checkExProc = 1;
- handle = GetModuleHandle(TEXT("ADVAPI32"));
- regDeleteKeyExProc = (FARPROC)
+ handle = GetModuleHandleW(L"ADVAPI32");
+ regDeleteKeyExProc = (LSTATUS (*) (HKEY, LPCWSTR, REGSAM, DWORD))
GetProcAddress(handle, "RegDeleteKeyExW");
}
if (mode && regDeleteKeyExProc) {
result = regDeleteKeyExProc(startKey, keyName, mode, 0);
} else {
- result = RegDeleteKey(startKey, keyName);
+ result = RegDeleteKeyW(startKey, keyName);
}
break;
} else if (result == ERROR_SUCCESS) {
result = RecursiveDeleteKey(hKey,
- (const TCHAR *) Tcl_DStringValue(&subkey), mode);
+ (const WCHAR *) Tcl_DStringValue(&subkey), mode);
}
}
Tcl_DStringFree(&subkey);
@@ -1275,7 +1301,8 @@ SetValue(
}
valueName = Tcl_GetString(valueNameObj);
- valueName = (char *) Tcl_WinUtfToTChar(valueName, valueNameObj->length, &nameBuf);
+ Tcl_DStringInit(&nameBuf);
+ valueName = (char *) Tcl_UtfToWCharDString(valueName, valueNameObj->length, &nameBuf);
if (type == REG_DWORD || type == REG_DWORD_BIG_ENDIAN) {
int value;
@@ -1287,7 +1314,7 @@ SetValue(
}
value = ConvertDWORD((DWORD) type, (DWORD) value);
- result = RegSetValueEx(key, (TCHAR *) valueName, 0,
+ result = RegSetValueExW(key, (WCHAR *) valueName, 0,
(DWORD) type, (BYTE *) &value, sizeof(DWORD));
} else if (type == REG_MULTI_SZ) {
Tcl_DString data, buf;
@@ -1319,9 +1346,10 @@ SetValue(
Tcl_DStringAppend(&data, "", 1); /* NUL-terminated string */
}
- Tcl_WinUtfToTChar(Tcl_DStringValue(&data), Tcl_DStringLength(&data)+1,
+ Tcl_DStringInit(&buf);
+ Tcl_UtfToWCharDString(Tcl_DStringValue(&data), Tcl_DStringLength(&data)+1,
&buf);
- result = RegSetValueEx(key, (TCHAR *) valueName, 0,
+ result = RegSetValueExW(key, (WCHAR *) valueName, 0,
(DWORD) type, (BYTE *) Tcl_DStringValue(&buf),
(DWORD) Tcl_DStringLength(&buf));
Tcl_DStringFree(&data);
@@ -1330,7 +1358,8 @@ SetValue(
Tcl_DString buf;
const char *data = Tcl_GetString(dataObj);
- data = (char *) Tcl_WinUtfToTChar(data, dataObj->length, &buf);
+ Tcl_DStringInit(&buf);
+ data = (char *) Tcl_UtfToWCharDString(data, dataObj->length, &buf);
/*
* Include the null in the length, padding if needed for WCHAR.
@@ -1338,7 +1367,7 @@ SetValue(
Tcl_DStringSetLength(&buf, Tcl_DStringLength(&buf)+1);
- result = RegSetValueEx(key, (TCHAR *) valueName, 0,
+ result = RegSetValueExW(key, (WCHAR *) valueName, 0,
(DWORD) type, (BYTE *) data, (DWORD) Tcl_DStringLength(&buf) + 1);
Tcl_DStringFree(&buf);
} else {
@@ -1350,7 +1379,7 @@ SetValue(
*/
data = (BYTE *) getByteArrayFromObj(dataObj, &bytelength);
- result = RegSetValueEx(key, (TCHAR *) valueName, 0,
+ result = RegSetValueExW(key, (WCHAR *) valueName, 0,
(DWORD) type, data, (DWORD) bytelength);
}
@@ -1410,7 +1439,8 @@ BroadcastValue(
}
str = Tcl_GetString(objv[0]);
- wstr = (WCHAR *) Tcl_WinUtfToTChar(str, objv[0]->length, &ds);
+ Tcl_DStringInit(&ds);
+ wstr = Tcl_UtfToWCharDString(str, objv[0]->length, &ds);
if (Tcl_DStringLength(&ds) == 0) {
wstr = NULL;
}
@@ -1419,7 +1449,7 @@ BroadcastValue(
* Use the ignore the result.
*/
- result = SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE,
+ result = SendMessageTimeoutW(HWND_BROADCAST, WM_SETTINGCHANGE,
(WPARAM) 0, (LPARAM) wstr, SMTO_ABORTIFHUNG, (UINT) timeout, &sendResult);
Tcl_DStringFree(&ds);
@@ -1454,7 +1484,7 @@ AppendSystemError(
DWORD error) /* Result code from error. */
{
int length;
- TCHAR *tMsgPtr, **tMsgPtrPtr = &tMsgPtr;
+ WCHAR *tMsgPtr, **tMsgPtrPtr = &tMsgPtr;
const char *msg;
char id[TCL_INTEGER_SPACE], msgBuf[24 + TCL_INTEGER_SPACE];
Tcl_DString ds;
@@ -1463,9 +1493,9 @@ AppendSystemError(
if (Tcl_IsShared(resultPtr)) {
resultPtr = Tcl_DuplicateObj(resultPtr);
}
- length = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
+ length = FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, error,
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (TCHAR *) tMsgPtrPtr,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (WCHAR *) tMsgPtrPtr,
0, NULL);
if (length == 0) {
sprintf(msgBuf, "unknown error: %ld", error);
@@ -1473,7 +1503,8 @@ AppendSystemError(
} else {
char *msgPtr;
- Tcl_WinTCharToUtf(tMsgPtr, -1, &ds);
+ Tcl_DStringInit(&ds);
+ Tcl_WCharToUtfDString(tMsgPtr, wcslen(tMsgPtr), &ds);
LocalFree(tMsgPtr);
msgPtr = Tcl_DStringValue(&ds);