将 zlib 与 Visual Studio 2010 结合使用
我尝试制作一个简单的演示程序,使用 zlib 来压缩和压缩解压缩文件,但是当我链接该文件时,Visual Studio 2010 链接器给了我这个错误:
错误 2 错误 LNK1313:检测到 ijw/native 模块;无法与纯模块链接
当我尝试将 /clr:pure 更改为 /clr 时。程序编译并运行,但给了我一个运行时错误: “应用程序无法正确启动(0xc000007b)。单击“确定”关闭应用程序。”
这是我到目前为止在气球提示中获取 zlib 版本的代码:
String^ info = gcnew String(reinterpret_cast<const char*>(zlibVersion()));
notify->ShowBalloonTip(20000, "Zlib Version", info, ToolTipIcon::Info );
你能帮我弄清楚 zlib 发生了什么以及错误是什么。谢谢
I tried to make a simple demo program that use zlib to compress & decompress files, but when I link the file, Visual Studio 2010 linker gave me this error:
Error 2 error LNK1313: ijw/native module detected; cannot link with pure modules
When I tried to change /clr:pure to just /clr. the program compiles and runs, but gave me a run time error:
"The application was unable to start correctly(0xc000007b). Click OK to close the application."
This is my code so far for just getting zlib version in balloon tip:
String^ info = gcnew String(reinterpret_cast<const char*>(zlibVersion()));
notify->ShowBalloonTip(20000, "Zlib Version", info, ToolTipIcon::Info );
Can you help me figure out what happened to zlib and what is that error. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的目标是 CLR,我强烈建议使用本机(对于 CLR)Zipping/Zlib 库,例如 DotNetZip,而不是试图硬塞一个本地库来做你想做的事。
我不是 C++/CLI 专家,所以这可能完全错误,但我相信
String^ info = gcnew String(reinterpret_cast(zlibVersion()));
结果未定义的行为。原因是
System::String
构造函数需要一个System::Char
对象数组,而不是 C++ 的char
数据类型。System::Char
是两个字节宽,char
是单字节宽(System::String
支持 Unicode;zlib 不支持)。 (无论如何,reinterpret_cast
是一个主要的危险信号 - 为什么在这里使用该转换?)此外,错误 0x7B 是
(0xC 在那里可能是因为它是 NTSTATUS 代码)如果您使用的是 Zlib 的动态链接版本,请确保该 DLL 可供您的程序在某处打开。
If you're targeting the CLR I strongly recommend using a native (to the CLR) Zipping/Zlib library, such as DotNetZip, rather than trying to shoehorn a native library into doing what you want.
I'm not a C++/CLI expert, so this might be entirely wrong, but I believe
String^ info = gcnew String(reinterpret_cast<const char*>(zlibVersion()));
results in undefined behavior. The reason is that the
System::String
constructor expects an array ofSystem::Char
objects, not C++'schar
data type.System::Char
is two bytes wide,char
is a single byte wide (System::String
supports Unicode; zlib does not). (In any case,reinterpret_cast
is a major red flag -- why are you using that cast here?)Also, error 0x7B is
(The 0xC is there probably because it's an NTSTATUS code) Make sure that if you're using the dynamically linked version of Zlib that the DLL is available for your program to open somewhere.