summaryrefslogtreecommitdiffstats
path: root/win/tkWinInit.c
diff options
context:
space:
mode:
authorashok <ashok>2014-09-13 14:23:33 (GMT)
committerashok <ashok>2014-09-13 14:23:33 (GMT)
commit93218ddaa94d9b9ce6319da38dba137a0c80912c (patch)
treebbe4218a92546c342203268c8224be5ab1ac5e6d /win/tkWinInit.c
parent034144aa3bb40a60ddf23e96380f1bb2a478bbae (diff)
downloadtk-93218ddaa94d9b9ce6319da38dba137a0c80912c.zip
tk-93218ddaa94d9b9ce6319da38dba137a0c80912c.tar.gz
tk-93218ddaa94d9b9ce6319da38dba137a0c80912c.tar.bz2
Implemented more options for new tk_get{Open,Save} file dialogs
Renamed Win32ErrorObj to TkWin32ErrorObj and moved it from tkWinSend.c to be generally available.
Diffstat (limited to 'win/tkWinInit.c')
-rw-r--r--win/tkWinInit.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/win/tkWinInit.c b/win/tkWinInit.c
index 4a327a2..b1b2d6b 100644
--- a/win/tkWinInit.c
+++ b/win/tkWinInit.c
@@ -159,6 +159,57 @@ TkpDisplayWarning(
}
/*
+ * ----------------------------------------------------------------------
+ *
+ * Win32ErrorObj --
+ *
+ * Returns a string object containing text from a COM or Win32 error code
+ *
+ * Results:
+ * A Tcl_Obj containing the Win32 error message.
+ *
+ * Side effects:
+ * Removed the error message from the COM threads error object.
+ *
+ * ----------------------------------------------------------------------
+ */
+
+Tcl_Obj*
+TkWin32ErrorObj(
+ HRESULT hrError)
+{
+ LPTSTR lpBuffer = NULL, p = NULL;
+ TCHAR sBuffer[30];
+ Tcl_Obj* errPtr = NULL;
+
+ FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM
+ | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, (DWORD)hrError,
+ LANG_NEUTRAL, (LPTSTR)&lpBuffer, 0, NULL);
+
+ if (lpBuffer == NULL) {
+ lpBuffer = sBuffer;
+ wsprintf(sBuffer, TEXT("Error Code: %08lX"), hrError);
+ }
+
+ if ((p = _tcsrchr(lpBuffer, TEXT('\r'))) != NULL) {
+ *p = TEXT('\0');
+ }
+
+#ifdef _UNICODE
+ errPtr = Tcl_NewUnicodeObj(lpBuffer, (int)wcslen(lpBuffer));
+#else
+ errPtr = Tcl_NewStringObj(lpBuffer, (int)strlen(lpBuffer));
+#endif /* _UNICODE */
+
+ if (lpBuffer != sBuffer) {
+ LocalFree((HLOCAL)lpBuffer);
+ }
+
+ return errPtr;
+}
+
+
+/*
* Local Variables:
* mode: c
* c-basic-offset: 4