Skip to content

Commit

Permalink
Hopefully fix a crash bug related to QL-Win#32, QL-Win#37 and QL-Win#44
Browse files Browse the repository at this point in the history
  • Loading branch information
xupefei committed Jul 27, 2017
1 parent 3fb1839 commit 2204f27
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion QuickLook.Native/QuickLook.Native32/DOpus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void DOpus::ParseXmlBuffer(PWCHAR buffer)

void DOpus::PrepareMessageWindow()
{
WNDCLASSEX wx = {'\0'};
WNDCLASSEX wx = {sizeof wx};
wx.cbSize = sizeof(WNDCLASSEX);
wx.lpfnWndProc = msgWindowProc;
wx.lpszClassName = MSGWINDOW_CLASS;
Expand Down
2 changes: 1 addition & 1 deletion QuickLook.Native/QuickLook.Native32/HelperMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void HelperMethods::GetSelectedInternal(CComQIPtr<IWebBrowserApp> pwba, PWCHAR b
void HelperMethods::ObtainFirstItem(CComPtr<IDataObject> dao, PWCHAR buffer)
{
FORMATETC formatetc;
STGMEDIUM medium;
STGMEDIUM medium = {sizeof medium};

formatetc.cfFormat = CF_HDROP;
formatetc.ptd = nullptr;
Expand Down
7 changes: 4 additions & 3 deletions QuickLook.Native/QuickLook.Native32/Shell32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ void Shell32::getSelectedFromExplorer(PWCHAR buffer)
for (auto i = 0; i < count; i++)
{
VARIANT vi;
VariantInit(&vi);
V_VT(&vi) = VT_I4;
V_I4(&vi) = i;

CComPtr<IDispatch> pdisp;
// ReSharper disable once CppSomeObjectMembersMightNotBeInitialized
if (FAILED(psw->Item(vi, &pdisp)))
if (S_OK != psw->Item(vi, &pdisp))
continue;

CComQIPtr<IWebBrowserApp> pwba;
Expand Down Expand Up @@ -139,7 +139,8 @@ void Shell32::getSelectedFromDesktop(PWCHAR buffer)
if (FAILED(psw.CoCreateInstance(CLSID_ShellWindows)))
return;

VARIANT pvarLoc = {VT_EMPTY};
VARIANT pvarLoc;
VariantInit(&pvarLoc);
long phwnd;
if (FAILED(psw->FindWindowSW(&pvarLoc, &pvarLoc, SWC_DESKTOP, &phwnd, SWFO_NEEDDISPATCH, reinterpret_cast<IDispatch**>(&pwba))))
return;
Expand Down
6 changes: 3 additions & 3 deletions QuickLook.Native/QuickLook.Native32/WoW64HookHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool WoW64HookHelper::Launch()
auto p = wcsrchr(fullPath, L'\\');
memcpy(p, HELPER_FILE, wcslen(HELPER_FILE) * sizeof WCHAR);

STARTUPINFO si = {'\0'};
STARTUPINFO si = {sizeof si};
PROCESS_INFORMATION pi = {nullptr};
si.cb = sizeof si;

Expand All @@ -70,9 +70,9 @@ void WoW64HookHelper::createJob()

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;
JOBOBJECT_EXTENDED_LIMIT_INFORMATION lpJobObjectInfo = {'\0'};
JOBOBJECT_EXTENDED_LIMIT_INFORMATION lpJobObjectInfo = {sizeof lpJobObjectInfo};
lpJobObjectInfo.BasicLimitInformation = BasicLimitInformation;

SetInformationJobObject(hJob, JobObjectExtendedLimitInformation, &lpJobObjectInfo, sizeof JOBOBJECT_EXTENDED_LIMIT_INFORMATION);
Expand Down
53 changes: 38 additions & 15 deletions QuickLook/NativeMethods/QuickLook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -23,7 +25,7 @@ namespace QuickLook.NativeMethods
{
internal static class QuickLook
{
private const int MaxPath = 260;
private const int MaxPath = 8192;

[DllImport("QuickLook.Native32.dll", EntryPoint = "Init",
CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -51,30 +53,51 @@ internal static class QuickLook

internal static void Init()
{
if (App.Is64Bit)
Init_64();
else
Init_32();
try
{
if (App.Is64Bit)
Init_64();
else
Init_32();
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}

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()
{
StringBuilder sb = null;
// communicate with COM in a separate thread
Task.Run(() =>
try
{
sb = new StringBuilder(MaxPath);
if (App.Is64Bit)
GetCurrentSelectionNative_64(sb);
else
GetCurrentSelectionNative_32(sb);
}).Wait();

// communicate with COM in a separate thread
Task.Run(() =>
{
sb = new StringBuilder(MaxPath);
if (App.Is64Bit)
GetCurrentSelectionNative_64(sb);
else
GetCurrentSelectionNative_32(sb);
}).Wait();
}
catch (Exception e)
{
Debug.WriteLine(e);
}
return sb?.ToString() ?? string.Empty;
}

Expand Down

0 comments on commit 2204f27

Please sign in to comment.