Problem Description
For example, when calling the SendInkLevelQuery method below, PrinterContextNativeRuntimeComponent.dll causes an Access Violatuon exception. Please confirm this issue.
https://github.com/microsoft/print-oem-samples/blob/master/PrinterContextNativeRuntimeComponent/PrintHelper.cpp#L132-L136
Investigation / Cause of Problem
You will be able to observe the AV at callstack below. The issue was happened in IUnknown::Release method of IPrintQueue object, because the reference counter has alredy been zero when Release was invoked.
PrinterContextNativeRuntimeComponent.dll!Microsoft::WRL::ComPtr::InternalRelease() line 176 C++
PrinterContextNativeRuntimeComponent.dll!Microsoft::WRL::ComPtr::~ComPtr() line 232 C++
PrinterContextNativeRuntimeComponent.dll!PrinterContextNativeRuntimeComponent::Printing::PrinterExtension::PrinterQueueEventHelperEventArgs::~PrinterQueueEventHelperEventArgs() C++
PrinterContextNativeRuntimeComponent.dll!PrinterContextNativeRuntimeComponent::Printing::PrinterExtension::PrinterQueueEventHelperEventArgs::[Platform::Object]::__abi_Release() C++
PrinterContextNativeRuntimeComponent.dll!__abi_winrt_ptr_dtor(const volatile Platform::Object ^ const __objArg) line 400 C++
PrinterContextNativeRuntimeComponent.dll!PrinterContextNativeRuntimeComponent::Printing::PrinterExtension::PrinterQueueEventHelperCallback::OnBidiResponseReceived(wchar_t * bstrResponse, HRESULT hrStatus) line 59 C++
PrinterContextNativeRuntimeComponent.dll!PrinterContextNativeRuntimeComponent::Printing::PrinterExtension::PrinterQueueEventHelperCallback::Invoke(long dispIdMember, const _GUID & riid, unsigned long lcid, unsigned short wFlags, tagDISPPARAMS * pDispParams, tagVARIANT * pVarResult, tagEXCEPINFO * pExcepInfo, unsigned int * puArgErr) line 128 C++
oleaut32.dll!00007fffe9c3aba4() unknown
oleaut32.dll!00007fffe9c39d50() unknown
rpcrt4.dll!00007fffe94942fb() unknown
combase.dll!00007fffe8bf99f2() unknown
oleaut32.dll!00007fffe9bb3410() unknown
combase.dll!00007fffe8bee1a3() unknown
combase.dll!00007fffe8bedf94() unknown
combase.dll!00007fffe8bfd246() unknown
combase.dll!00007fffe8b9a3a5() unknown
combase.dll!00007fffe8bfceab() unknown
combase.dll!00007fffe8bc6ee0() unknown
combase.dll!00007fffe8bc67c1() unknown
combase.dll!00007fffe8bcf6cd() unknown
combase.dll!00007fffe8bce0dd() unknown
combase.dll!00007fffe8bcfebe() unknown
combase.dll!00007fffe8bcf896() unknown
Windows.UI.dll!00007fffdb6c509c() unknown
Windows.UI.dll!00007fffdb6c4edb() unknown
Windows.UI.Xaml.dll!00007fffda7c4f00() unknown
Windows.UI.Xaml.dll!00007fffda7c4e9f() unknown
twinapi.appcore.dll!00007fffe4964c2a() unknown
twinapi.appcore.dll!00007fffe4937a66() unknown
SHCore.dll!00007fffe95dc315() unknown
kernel32.dll!00007fffe89c7974() unknown
ntdll.dll!00007fffea2da271() unknown
Value Name Type
◢ temp 0x000001cc5dae1150 {...} IPrinterQueue *
◢ IDispatch {...} IDispatch
◢ IUnknown {...} IUnknown
__vfptr 0x0000000000000000 {???, ???, ???} void * *
Workaround
To avoild the AV, I added m_printerQueue->AddRef() methodimmediately after the Attach in the PrinterQueueEventHelperEventArgs.
|
PrinterQueueEventHelperEventArgs::PrinterQueueEventHelperEventArgs(Object^ printerQueue, String^ str, int hresult) |
|
{ |
|
if (printerQueue == nullptr) |
|
{ |
|
throw ref new InvalidArgumentException(); |
|
} |
|
|
|
m_printerQueueEventHR = hresult; |
|
IPrinterQueue* qtmp = (IPrinterQueue*)(void*)printerQueue; |
|
m_printerQueue.Attach(qtmp); |
|
m_printerQueueEventResponse = str; |
m_printerQueueEventHR = hresult;
IPrinterQueue* qtmp = (IPrinterQueue*)(void*)printerQueue;
m_printerQueue.Attach(qtmp);
m_printerQueue->AddRef(); // Workaround
m_printerQueueEventResponse = str;