【发布时间】:2022-01-20 22:48:27
【问题描述】:
int main(int argc, char **argv)
{
FreeConsole();
// Cannot construct mq here, it might fail
// Declaring it here like `ipc::message_queue mq;`
// throws some weird error given below
try
{
ipc::message_queue mq(ipc::open_only, g_szPipeName);
mq.send(g_szMsgReady, sizeof(g_szMsgReady) + 1, 0);
}
catch (const ipc::interprocess_exception &ex)
{
MessageBox(nullptr, TEXT("This process is not meant to be used directly, yet ;)"), nullptr, MB_OK);
exit(-1);
}
// How to use `mq` here?
return 0;
}
当我声明message_queue时抛出错误:
Error (active) E0330
"boost::interprocess::message_queue_t<VoidPointer>::message_queue_t() [with VoidPointer=boost::interprocess::offset_ptr<void, ptrdiff_t, uintptr_t, 0Ui64>]" (declared at line 71 of "C:\dev\vcpkg\installed\\x64-windows\include\boost/interprocess/ipc/message_queue.hpp") is inaccessible
我已经通过vcpkg 安装了整个boost v1.77.0 库。似乎嵌套的try/catch 块是唯一的解决方案。
【问题讨论】:
-
g_szPipeName是否已经创建,即不为空? -
@kiner_shah 它是一个
constexpr我在一个头文件中定义的,这个文件是Main.cpp,g_szPipeName是在Main.h中定义的