C++ 没有返回值使用 C# 的 DLL
使用控制台应用程序,我使用 c++ com dll 来调用函数。
我已添加注册的 DLL 作为项目的引用,然后实例化该对象并调用该函数。 (我应该注意,我没有像其他人那样使用 pinvoke)
结果我应该得到一个字符串,但我只是得到一个空字符串。我可以获得任何形式输出的唯一方法是启用非托管代码的调试,从中我可以看到它正在正确执行并返回结果。
我在 stackoverflow 和其他一些网站上进行了搜索,但找不到任何与此匹配的内容。任何想法我做错了什么或者如何让它返回一个值?
编辑:根据要求,这里是代码 -
COMMODCHECKLib.Modcheck mod = new COMMODCHECKLib.Modcheck();
string output = mod.check("123456");
Using a console application, I'm making use of a c++ com dll to call a function.
I have added the registered DLL as a reference for the project and then I am instantiating the object and calling the function. (I should note that I'm not using pinvoke as some other people seem to be)
I should be getting a string back as a result but I am just getting an empty string. The only way I can get any form of output is by enabling debugging for unmanaged code and from that I can see that it is executing correctly and returning a result.
I have had a search around stackoverflow and a few other sites and can't quite find anything that matches this. Any ideas what I'm doing wrong or how I can get it to return a value?
EDIT: As requested, here is the code -
COMMODCHECKLib.Modcheck mod = new COMMODCHECKLib.Modcheck();
string output = mod.check("123456");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议首先检查问题是否出在 C# 代码或 COM 库中。为此,您可以使用 VB 脚本文件 (.vbs),例如
只需从命令行运行此脚本(输入
test.vbs
)。如果这给出了所需的输出,您至少知道问题出在 C# 方面。
I would suggest to first check, if the problem is within the C# code or the COM library. For that, you can use e.g. a VB-Script file (.vbs) like
Just run this script from the command line (entering
test.vbs
).If this gives the desired output, you know at least, that the problem lies on the C# side.
好吧,DLL 的文档似乎不正确,并给出了 check 函数作为我需要的函数,但事实上有一个名为 checkAllocate 的函数,这是我需要的函数使用。抱歉,伙计们 - 非常感谢您的时间和努力
Well it seems that the documentation for the DLL was incorrect and gave the check function as the one I needed but infact there was a function called checkAllocate which is the one I needed to use. Apologies guys - many thanks for your time and efforts