[已解决]从C#运行时错误中调用ATL dll [英] [Solved]calling ATL dll from C# Runtime Error
问题描述
我有一个本机C ++ dll和一个虚拟类("mycert").我有一个ATL dll项目,我将本机dll包含到ATL中,并为"mycert"创建了一个接口.在mycert接口中,我有功能:
i have a native C++ dll and a virtual class("mycert") in it.I have an ATL dll project and i included the native dll into the ATL and create an interface for the ''mycert'' .In mycert interface i have a function :
STDMETHODIMP Cmycert::setSignature(BYTE* data, SHORT size)
{
cert = new mycert();
ByteArray* barray = new ByteArray();
for(int i=0;i<size;i++)
(*barray)[i] = data[i];
ASN1BitString* bitString = new ASN1BitString();
bitString->setValue(*barray);
cert->setSignature(bitString);
return S_OK;
}
在一个C#项目中,我包含ATL dll并调用上面的函数:
and in a c# project i include the ATL dll and call the above function:
byte[] data = new byte[3];
data[0] = 4;
data[1] = 6;
data[2] = 8;
mycertClass obj = new mycertClass();
obj.setSignature(ref data[0], 3);
当我运行此代码时,它给出以下错误:
运行时错误!
程序:
... dio 2008 \ Projects \ myApplication \ myApplication \ bin \ Debug \ myApplication.vshost.exe
该应用程序已请求运行时以一种异常方式终止它.
请与应用程序的支持团队联系以获取更多信息."
我的本机c ++ dll除了"mycert"以外,还有许多其他类,它们不是虚拟的,我可以对它们成功地执行相同的操作,只有mycert类会导致此错误.我是否缺少有关虚拟类的内容?
您能帮我吗?
when i run this code, it gives the following error:
"Runtime Error!
Program:
...dio 2008\Projects\myApplication\myApplication\bin\Debug\myApplication.vshost.exe
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application''s support team for more information."
my native c++ dll has lots of classes other than ''mycert'' and they are not virtual, i can do the same operations on them successfully ,only mycert class cause this error. Am I missing something about virtual classes?
Can you help me please?
推荐答案
您可以调用函数吗?
如果仅返回S_OK
? :)
Can you call your function
if it returnsS_OK
only ? :)
是的,我可以称之为.我正在调用其他接口的功能,但仅此接口不起作用.
yes i can call it. I am calling the functions of the other interfaces but only this interface doesn''t work.
好的,这不只是一点点的:)
你能解释一下
吗 为什么需要new mycert()
或您想在职能中拥有什么? :)
OK, it is not just a bit :)
Could you explain
why do you need anew mycert()
or what would you like to have in your function ? :)
这篇关于[已解决]从C#运行时错误中调用ATL dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!