[英]How can I call a COM-DLL from C# application?
Hi I have a COM DLL implemented in ATL and now I want to develop a test exe in C# to test the features. 嗨,我有一个用ATL实现的COM DLL,现在我想用C#开发一个测试exe来测试功能。
How can I call a COM-DLL from C# application ? 如何从C#应用程序调用COM-DLL?
I have tested with LoadLibrary() but AFAIK this is for Win32 native DLL. 我已经使用LoadLibrary()进行了测试,但是AFAIK这是针对Win32本机DLL的。 Also I'm not sure that CoCreateInstance is called somewhere in LoadLibrary()?
另外我不确定在LoadLibrary()中的某个地方调用了CoCreateInstance吗?
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
static extern IntPtr LoadLibrary(string lpFileName);
private int LoadDLL()
{
dllPath = lblDllPath.Text;
int i_hmod = 0;
IntPtr hMod = LoadLibrary(dllPath);
i_hmod = hMod.ToInt32();
if (i_hmod > 0)
{
txtOutput.Text += "Dll successfully loaded\r\n";
}
else
{
txtOutput.Text += "LoadLibrary failed\r\n";
}
return i_hmod;
}
Thnx 日Thnx
您应该能够简单地将对DLL的引用直接添加到.NET项目中-将创建包装器,并且可以调用将委派给COM组件的包装器方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.