在 IIS7 中从 ASP.NET 调用非托管代码
我将 ASP.NET 中的 DLL 称为用 C++ 编写的 DLL。 当在 IIS 7 中运行它时,池 (w3wp.exe) 崩溃并打开“即时调试窗口”。
我做了很多跟踪,发现调用任何具有“输出字符串”参数(或返回字符串值)的函数(在非托管 DLL 中)时会发生崩溃。
我在网上看到很多人的 DLL(C、Delphi、VB6)都有这个问题。但没有答案。所以我打电话给专家!
我如何调用这些函数以便 IIS 7 正确处理它?
卡斯萨卡尔
I call a DLL in ASP.NET a DLL that is written in C++.
When running it into IIS 7, The pool (w3wp.exe) crash and the "just in time debugging window" open.
I do many tracing and I found that crash happen when calling any function (in the unmanaged DLLs) that have a "out string" parameter (or return a string value).
I saw on the web than many people have this problem with their DLL (C, Delphi, VB6). But no answer. so I call experts!
How can I call these functions so IIS 7 process it without error ?
cas sakal
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该使用
StringBuilder
作为互操作字符串输出参数:You should use
StringBuilder
for interop string output parameters:这也许是不可能的。 COM提供了接口规范,但并不能保证调用者能够正确使用该接口。除非 COM 对象公开可由 COM 子系统自动封送的方法(例如:自动化兼容),否则您可能无法使用它们。可以轻松编写无法在进程外直接访问或由 C++ 以外的任何语言访问的 C++ COM 对象。
您也许可以编写一些自定义封送代码以使其工作,但我不认为它会直接工作。如果类型足够简单/直接,可能有一些内置的元帅属性可以使其工作;不过我对这方面的知识不是很了解,所以希望其他人可以提供帮助。
It may not be possible. COM provides an interface specification, but not a guarantee that the caller be able to use the interface correctly. Unless the COM object exposes methods which are automatically marshalable by the COM subsystem (eg: automation compatible), you may not be able to use them. It's easily possible to write a C++ COM object which cannot be directly accessed out-of-process, or by any language other than C++.
You may be able to write some custom marshaling code to make it work, but I wouldn't assume it will work directly. If the types are simple/direct enough, there may be some built-in marshal attributes to make it work; I don't have a lot of knowledge in this area, though, so hopefully other people can help out.