diff win/edge.cpp @ 2018:663d79f28e46

Win: Fix dw_html_javascript_run() when using embedded IE browser widget. Switched both the Edge and IE modules to use the main UTF8 conversion utils.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 08 Nov 2019 09:49:16 +0000
parents c30f4354966e
children 28809bf17957
line wrap: on
line diff
--- a/win/edge.cpp	Fri Nov 08 07:20:17 2019 +0000
+++ b/win/edge.cpp	Fri Nov 08 09:49:16 2019 +0000
@@ -21,6 +21,12 @@
 
 extern "C" {
 
+	/* Import the character conversion functions from dw.c */
+	LPWSTR _myUTF8toWide(char *utf8string, void *outbuf);
+	char *_myWideToUTF8(LPWSTR widestring, void *outbuf);
+	#define UTF8toWide(a) _myUTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL)
+	#define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL)
+	LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
 	extern HWND DW_HWND_OBJECT;
 	BOOL DW_EDGE_DETECTED = FALSE;
 
@@ -128,7 +134,7 @@
 	 * RETURNS: 0 if success, or non-zero if an error.
 	 */
 
-	int _dw_edge_raw(HWND hwnd, LPCWSTR string)
+	int _dw_edge_raw(HWND hwnd, char *string)
 	{
 		IWebView2WebView* webview;
 
@@ -137,9 +143,9 @@
 		webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
 
 		if (webview)
-			webview->NavigateToString(string);
+			webview->NavigateToString(UTF8toWide(string));
 		else
-			dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(string));
+			dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(UTF8toWide(string)));
 		return DW_ERROR_NONE;
 	}
 
@@ -152,7 +158,7 @@
 	 * RETURNS: 0 if success, or non-zero if an error.
 	 */
 
-	int _dw_edge_url(HWND hwnd, LPCWSTR url)
+	int _dw_edge_url(HWND hwnd, char *url)
 	{
 		IWebView2WebView* webview;
 
@@ -161,17 +167,12 @@
 		webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
 
 		if (webview)
-			webview->Navigate(url);
+			webview->Navigate(UTF8toWide(url));
 		else
-			dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(url));
+			dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(UTF8toWide(url)));
 		return DW_ERROR_NONE;
 	}
 
-	/* These reference functions in dw.c */
-	#define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL)
-	char* _myWideToUTF8(LPWSTR widestring, void* outbuf);
-	LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
-
 	/******************************* dw_edge_javascript_run() ****************************
 	 * Runs a javascript in the specified browser context.
 	 *
@@ -182,7 +183,7 @@
 	 * RETURNS: 0 if success, or non-zero if an error.
 	 */
 
-	int _dw_edge_javascript_run(HWND hwnd, LPCWSTR script, void *scriptdata)
+	int _dw_edge_javascript_run(HWND hwnd, char *script, void *scriptdata)
 	{
 		IWebView2WebView* webview;
 
@@ -191,7 +192,7 @@
 		webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
 
 		if (webview)
-			webview->ExecuteScript(script,
+			webview->ExecuteScript(UTF8toWide(script),
 				Callback<IWebView2ExecuteScriptCompletedHandler>(
 					[hwnd, scriptdata](HRESULT error, PCWSTR result) -> HRESULT
 					{