简体   繁体   English

如何从C#应用程序调用COM-DLL?

[英]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.

相关问题 在 C# COM-DLL 项目中使用外部 DLL 进行 MS-Access 使用 - Using external DLL's in C# COM-DLL project for MS-Access usage 调用COM-dll组件后,调试器不会捕获C#异常 - After calling a COM-dll component, C# exceptions are not caught by the debugger 在 C# 应用程序中导入和调用 COM dll - Import and call COM dll in C# application 有没有办法从C#应用程序调用非托管(不是COM)dll? - Is there a way to call an unmanaged (not COM) dll from C# application? 如何从非托管应用程序将数据传递给C#COM DLL - How to pass data to C# COM DLL from unmanaged application 如何使用P / Invoke从64位C#应用程序中调用64位C ++ DLL? - How can I use P/Invoke to call a 64-bit C++ DLL from a 64-bit C# Application? 从Java应用程序调用C#dll - Call C# dll from a Java Application 我可以从 64 位 C# Winforms 应用程序调用 MAPI32.DLL > MAPISendMail 吗? - Can I call MAPI32.DLL > MAPISendMail from a 64-bit C# Winforms application? 如何调用接受来自 C# 的 stringstream 类型参数的 C++ DLL 函数? - How can I call a function of a C++ DLL that accepts a parameter of type stringstream from C#? 通过C#应用程序(使用Skype4COM.dll)从Skype帐户自动调用 - automated call from skype account via C# application (using Skype4COM.dll)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM