我正在尝试将一些 MSMQ 功能编码到 dll (c++) 中,但遇到了麻烦。本质上,当我调用创建队列时,会引发低级异常(参见下面的调用堆栈)。令我沮丧的是,这段代码在可执行文件中运行良好,只有在它位于 dll 中时它似乎才会失败。我已经对代码进行了一些清理,并将其包含在下面。
调用栈:
KernelBase.dll!_RaiseException@16() + 0x58 bytes
msvcrt.dll!__CxxThrowException@8() + 0x45 bytes
mqsec.dll!CCancelRpc::Init() + 0xa5 bytes
mqrt.dll!CFreeRPCHandles::Add() + 0x1bc bytes
mqrt.dll!RtpOneTimeThreadInit() + 0x39 bytes
mqrt.dll!_MQCreateQueue@16() + 0x23 bytes
mqoa.dll!CMSMQQueueInfo::Create() + 0xba bytes
代码:
HRESULT CreateQueue()
{
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
CComQIPtr<IMSMQQueueInfo, &IID_IMSMQQueueInfo> ipQueueInfo;
hr = CoCreateInstance(CLSID_MSMQQueueInfo,
NULL,
CLSCTX_SERVER,
IID_IMSMQQueueInfo,
(void**)(&ipQueueInfo.p));
if(hr != S_OK)
return hr;
hr = ipQueueInfo->put_PathName(L".\\private$\\TestQueue");
if(hr != S_OK)
return hr;
VARIANT vtFalse;
VariantInit(&vtFalse);
vtFalse.vt = VT_BOOL;
vtFalse.boolVal = FALSE;
hr = ipQueueInfo->Create(&vtFalse, &vtFalse);
return hr;
}