From 26b6646da62cb02438e2dea817a5084022317993 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Sun, 6 Feb 2022 15:12:54 +0200 Subject: [PATCH] Weather: Made variable local, static compile runtime library in ep_weather_host_stub --- ep_weather_host/ep_weather_host.c | 33 +++++++------------ ep_weather_host/ep_weather_host.h | 1 - .../ep_weather_host_stub.vcxproj | 4 +++ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/ep_weather_host/ep_weather_host.c b/ep_weather_host/ep_weather_host.c index 6dc8557..8a41b84 100644 --- a/ep_weather_host/ep_weather_host.c +++ b/ep_weather_host/ep_weather_host.c @@ -141,13 +141,13 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToProvider(EPWeather* _this) else if (dwProvider == EP_WEATHER_PROVIDER_GOOGLE) { //hr = _this->pCoreWebView2->lpVtbl->Navigate(_this->pCoreWebView2, L"https://google.com"); - _this->wszScriptData = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_HTML_LEN); - if (_this->wszScriptData) + LPWSTR wszScriptData = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_HTML_LEN); + if (wszScriptData) { - swprintf_s(_this->wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_HTML_LEN, L"https://www.google.com/search?hl=%s&q=weather%s%s", _this->wszLanguage, _this->wszTerm[0] ? L" " : L"", _this->wszTerm); + swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_HTML_LEN, L"https://www.google.com/search?hl=%s&q=weather%s%s", _this->wszLanguage, _this->wszTerm[0] ? L" " : L"", _this->wszTerm); if (_this->pCoreWebView2) { - hr = _this->pCoreWebView2->lpVtbl->Navigate(_this->pCoreWebView2, _this->wszScriptData); + hr = _this->pCoreWebView2->lpVtbl->Navigate(_this->pCoreWebView2, wszScriptData); } else { @@ -156,8 +156,8 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToProvider(EPWeather* _this) if (FAILED(hr)) { InterlockedExchange64(&_this->bBrowserBusy, FALSE); - free(_this->wszScriptData); } + free(wszScriptData); } else { @@ -176,30 +176,30 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_ExecuteDataScript(EPWeather* _this) } else if (dwProvider == EP_WEATHER_PROVIDER_GOOGLE) { - _this->wszScriptData = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN); - if (_this->wszScriptData) + LPWSTR wszScriptData = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN); + if (wszScriptData) { LONG64 dwTemperatureUnit = InterlockedAdd64(&_this->dwTemperatureUnit, 0); LONG64 cbx = InterlockedAdd64(&_this->cbx, 0); - swprintf_s(_this->wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, ep_weather_provider_google_script, dwTemperatureUnit == EP_WEATHER_TUNIT_FAHRENHEIT ? L'F' : L'C', cbx, cbx); + swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, ep_weather_provider_google_script, dwTemperatureUnit == EP_WEATHER_TUNIT_FAHRENHEIT ? L'F' : L'C', cbx, cbx); //wprintf(L"%s\n", _this->wszScriptData); if (_this->pCoreWebView2) { - hr = _this->pCoreWebView2->lpVtbl->ExecuteScript(_this->pCoreWebView2, _this->wszScriptData, &EPWeather_ICoreWebView2ExecuteScriptCompletedHandler); + hr = _this->pCoreWebView2->lpVtbl->ExecuteScript(_this->pCoreWebView2, wszScriptData, &EPWeather_ICoreWebView2ExecuteScriptCompletedHandler); } else { - return E_FAIL; + hr = E_FAIL; } if (FAILED(hr)) { InterlockedExchange64(&_this->bBrowserBusy, FALSE); - free(_this->wszScriptData); } + free(wszScriptData); } else { -hr = E_OUTOFMEMORY; + hr = E_OUTOFMEMORY; } } return hr; @@ -310,10 +310,6 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_CallDevToolsProtocolMethodCompleted(ICor HRESULT STDMETHODCALLTYPE ICoreWebView2_NavigationCompleted(ICoreWebView2NavigationCompletedEventHandler* _this2, ICoreWebView2* pCoreWebView2, ICoreWebView2NavigationCompletedEventArgs* pCoreWebView2NavigationCompletedEventArgs) { EPWeather* _this = EPWeather_Instance; // GetWindowLongPtrW(FindWindowW(_T(EPW_WEATHER_CLASSNAME), NULL), GWLP_USERDATA); - if (_this->wszScriptData) - { - free(_this->wszScriptData); - } BOOL bIsSuccess = FALSE; pCoreWebView2NavigationCompletedEventArgs->lpVtbl->get_IsSuccess(pCoreWebView2NavigationCompletedEventArgs, &bIsSuccess); if (bIsSuccess) @@ -361,8 +357,6 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec } else if (!_wcsicmp(pResultObjectAsJson, L"\"run_part_1\"")) { - free(_this->wszScriptData); - _this->wszScriptData = NULL; printf("consent granted\n"); PostMessageW(EPWeather_Instance->hWnd, EP_WEATHER_WM_FETCH_DATA, 0, 0); SetTimer(EPWeather_Instance->hWnd, EP_WEATHER_TIMER_REQUEST_REFRESH, EP_WEATHER_TIMER_REQUEST_REFRESH_DELAY, NULL); @@ -370,9 +364,6 @@ HRESULT STDMETHODCALLTYPE ICoreWebView2_ExecuteScriptCompleted(ICoreWebView2Exec } else { - free(_this->wszScriptData); - _this->wszScriptData = NULL; - //wprintf(L"%s\n", pResultObjectAsJson); epw_Weather_LockData(_this); diff --git a/ep_weather_host/ep_weather_host.h b/ep_weather_host/ep_weather_host.h index ea0d748..3e9f80a 100644 --- a/ep_weather_host/ep_weather_host.h +++ b/ep_weather_host/ep_weather_host.h @@ -68,7 +68,6 @@ typedef interface EPWeather ICoreWebView2* pCoreWebView2; EventRegistrationToken* tkOnNavigationCompleted; EventRegistrationToken* tkOnPermissionRequested; - LPCWSTR wszScriptData; RECT rc; HANDLE hSignalExitMainThread; diff --git a/ep_weather_host_stub/ep_weather_host_stub.vcxproj b/ep_weather_host_stub/ep_weather_host_stub.vcxproj index 550457b..e0f23a5 100644 --- a/ep_weather_host_stub/ep_weather_host_stub.vcxproj +++ b/ep_weather_host_stub/ep_weather_host_stub.vcxproj @@ -92,6 +92,7 @@ true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + MultiThreadedDebug Console @@ -108,6 +109,7 @@ true WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + MultiThreaded Console @@ -124,6 +126,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true + MultiThreadedDebug Console @@ -140,6 +143,7 @@ true NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true + MultiThreaded Console