Hopefully fix a crash bug related to #32, #37 and #44

This commit is contained in:
Paddy Xu
2017-07-27 23:36:30 +03:00
parent 3fb18391df
commit 2204f27b01
5 changed files with 47 additions and 23 deletions

View File

@@ -111,7 +111,7 @@ void DOpus::ParseXmlBuffer(PWCHAR buffer)
void DOpus::PrepareMessageWindow() void DOpus::PrepareMessageWindow()
{ {
WNDCLASSEX wx = {'\0'}; WNDCLASSEX wx = {sizeof wx};
wx.cbSize = sizeof(WNDCLASSEX); wx.cbSize = sizeof(WNDCLASSEX);
wx.lpfnWndProc = msgWindowProc; wx.lpfnWndProc = msgWindowProc;
wx.lpszClassName = MSGWINDOW_CLASS; wx.lpszClassName = MSGWINDOW_CLASS;

View File

@@ -42,7 +42,7 @@ void HelperMethods::GetSelectedInternal(CComQIPtr<IWebBrowserApp> pwba, PWCHAR b
void HelperMethods::ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer) void HelperMethods::ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer)
{ {
FORMATETC formatetc; FORMATETC formatetc;
STGMEDIUM medium; STGMEDIUM medium = {sizeof medium};
formatetc.cfFormat = CF_HDROP; formatetc.cfFormat = CF_HDROP;
formatetc.ptd = nullptr; formatetc.ptd = nullptr;

View File

@@ -106,12 +106,12 @@ void Shell32::getSelectedFromExplorer(PWCHAR buffer)
for (auto i = 0; i < count; i++) for (auto i = 0; i < count; i++)
{ {
VARIANT vi; VARIANT vi;
VariantInit(&vi);
V_VT(&vi) = VT_I4; V_VT(&vi) = VT_I4;
V_I4(&vi) = i; V_I4(&vi) = i;
CComPtr<IDispatch> pdisp; CComPtr<IDispatch> pdisp;
// ReSharper disable once CppSomeObjectMembersMightNotBeInitialized if (S_OK != psw->Item(vi, &pdisp))
if (FAILED(psw->Item(vi, &pdisp)))
continue; continue;
CComQIPtr<IWebBrowserApp> pwba; CComQIPtr<IWebBrowserApp> pwba;
@@ -139,7 +139,8 @@ void Shell32::getSelectedFromDesktop(PWCHAR buffer)
if (FAILED(psw.CoCreateInstance(CLSID_ShellWindows))) if (FAILED(psw.CoCreateInstance(CLSID_ShellWindows)))
return; return;
VARIANT pvarLoc = {VT_EMPTY}; VARIANT pvarLoc;
VariantInit(&pvarLoc);
long phwnd; long phwnd;
if (FAILED(psw->FindWindowSW(&pvarLoc, &pvarLoc, SWC_DESKTOP, &phwnd, SWFO_NEEDDISPATCH, reinterpret_cast<IDispatch**>(&pwba)))) if (FAILED(psw->FindWindowSW(&pvarLoc, &pvarLoc, SWC_DESKTOP, &phwnd, SWFO_NEEDDISPATCH, reinterpret_cast<IDispatch**>(&pwba))))
return; return;

View File

@@ -51,7 +51,7 @@ bool WoW64HookHelper::Launch()
auto p = wcsrchr(fullPath, L'\\'); auto p = wcsrchr(fullPath, L'\\');
memcpy(p, HELPER_FILE, wcslen(HELPER_FILE) * sizeof WCHAR); memcpy(p, HELPER_FILE, wcslen(HELPER_FILE) * sizeof WCHAR);
STARTUPINFO si = {'\0'}; STARTUPINFO si = {sizeof si};
PROCESS_INFORMATION pi = {nullptr}; PROCESS_INFORMATION pi = {nullptr};
si.cb = sizeof si; si.cb = sizeof si;
@@ -70,9 +70,9 @@ void WoW64HookHelper::createJob()
hJob = CreateJobObject(nullptr, nullptr); hJob = CreateJobObject(nullptr, nullptr);
JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation = {'\0'}; JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation = {sizeof BasicLimitInformation};
BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
JOBOBJECT_EXTENDED_LIMIT_INFORMATION lpJobObjectInfo = {'\0'}; JOBOBJECT_EXTENDED_LIMIT_INFORMATION lpJobObjectInfo = {sizeof lpJobObjectInfo};
lpJobObjectInfo.BasicLimitInformation = BasicLimitInformation; lpJobObjectInfo.BasicLimitInformation = BasicLimitInformation;
SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &lpJobObjectInfo, sizeof JOBOBJECT_EXTENDED_LIMIT_INFORMATION); SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &lpJobObjectInfo, sizeof JOBOBJECT_EXTENDED_LIMIT_INFORMATION);

View File

@@ -15,6 +15,8 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -23,7 +25,7 @@ namespace QuickLook.NativeMethods
{ {
internal static class QuickLook internal static class QuickLook
{ {
private const int MaxPath = 260; private const int MaxPath = 8192;
[DllImport("QuickLook.Native32.dll", EntryPoint = "Init", [DllImport("QuickLook.Native32.dll", EntryPoint = "Init",
CallingConvention = CallingConvention.Cdecl)] CallingConvention = CallingConvention.Cdecl)]
@@ -51,30 +53,51 @@ namespace QuickLook.NativeMethods
internal static void Init() internal static void Init()
{ {
if (App.Is64Bit) try
Init_64(); {
else if (App.Is64Bit)
Init_32(); Init_64();
else
Init_32();
}
catch (Exception e)
{
Debug.WriteLine(e);
}
} }
internal static FocusedWindowType GetFocusedWindowType() internal static FocusedWindowType GetFocusedWindowType()
{ {
return App.Is64Bit ? GetFocusedWindowTypeNative_64() : GetFocusedWindowTypeNative_32(); try
{
return App.Is64Bit ? GetFocusedWindowTypeNative_64() : GetFocusedWindowTypeNative_32();
}
catch (Exception e)
{
Debug.WriteLine(e);
return FocusedWindowType.Invalid;
}
} }
internal static string GetCurrentSelection() internal static string GetCurrentSelection()
{ {
StringBuilder sb = null; StringBuilder sb = null;
// communicate with COM in a separate thread try
Task.Run(() =>
{ {
sb = new StringBuilder(MaxPath); // communicate with COM in a separate thread
if (App.Is64Bit) Task.Run(() =>
GetCurrentSelectionNative_64(sb); {
else sb = new StringBuilder(MaxPath);
GetCurrentSelectionNative_32(sb); if (App.Is64Bit)
}).Wait(); GetCurrentSelectionNative_64(sb);
else
GetCurrentSelectionNative_32(sb);
}).Wait();
}
catch (Exception e)
{
Debug.WriteLine(e);
}
return sb?.ToString() ?? string.Empty; return sb?.ToString() ?? string.Empty;
} }