我正在尝试将一些MSMQ功能编码为dll(c ++),但遇到了麻烦。本质上,当我调用创建队列时,会引发一个低级异常(参见下面的callstack)。令我感到沮丧的是,这段代码在可执行文件中运行良好,它似乎只是在它处于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;
}