我有三个申请。
Feeder
- 创建一个boost::interprocess
共享内存对象并填充它。 Feeder
是基于Qt的。Gui
- 有很多按钮和文本框,可以从中创建结构化配置。 Gui
是基于Qt的。User
- 读取由Gui
创建的配置并连接到由Feeder
填充的共享内存,然后执行计算。 User
是一个控制台C ++,没有Qt。问题是一旦Feeder
填充共享内存,Gui
CAN就可以访问它,而User
无法Gui
和User
使用用于读取共享内存的相同代码。两年前,使用Qt 4.X这很好用,今天我在Qt 5.1.1。 - 我不知道是否与Qt版本有关联。
仅为了说明,代码片段是
Feeder
this->mem = new shared_memory_object(create_only, "tickChartSize", read_write);
this->mem ->truncate(sizeof(unsigned int));
mapped_region region( *this->mem, read_write);
*((unsigned int))region.get_address()) = this->size();
Gui
+ User
shared_memory_object *mem = new shared_memory_object(open_only, "tickChartSize", read_only);
this->u = (void*)new mapped_region( *mem, read_only ); // works in Gui, throws in User
我进入了强化代码,发现了Gui
和User
之间的差异,就在User
- 在{_ 1楼}中的第459行投放
//Obtain mapping size if user provides 0 size
if(size == 0){
offset_t mapping_size;
THIS --> if(!winapi::get_file_mapping_size(native_mapping_handle, mapping_size)){
error_info err = winapi::get_last_error();
throw interprocess_exception(err);
}
//This can throw
priv_size_from_mapping_size(mapping_size, offset, page_offset, size);
}
winapi::get_file_mapping_size
来电完成后,mapping_size
中的Gui
为8,而User
中的err
为 -3689348814741910324 。有关错误的唯一信息是err.m_ec = system_error(1)
结构,但是{{1}},即此消息没有提供太多帮助。
构建信息:
非常感谢有关此主题的任何帮助。
丹尼尔
编辑 - 解决方案
尽管我最初的VS项目没有任何明显的错误,但重新创建项目使得这个错误的行为消失了。感谢所有观众。
答案 0 :(得分:1)
win32实现继续使用NtQuerySection来获取映射的大小:
inline bool get_file_mapping_size(void *file_mapping_hnd, __int64 &size)
{
NtQuerySection_t pNtQuerySection =
(NtQuerySection_t)dll_func::get(dll_func::NtQuerySection);
//Obtain file name
interprocess_section_basic_information info;
unsigned long ntstatus =
pNtQuerySection(file_mapping_hnd, section_basic_information, &info, sizeof(info), 0);
size = info.section_size;
return !ntstatus;
}
Windows上的错误代码1表示ERROR_INVALID_FUNCTION
。这意味着此 undocumented function from ntdll.dll 无法访问,或者无法与传递的特定句柄file_mapping_hnd
一起使用。
也许,有了这些信息,您可以在Boost邮件列表中找到原因或询问它