简体   繁体   中英

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.

How can I call a COM-DLL from C# application ?

I have tested with LoadLibrary() but AFAIK this is for Win32 native DLL. Also I'm not sure that CoCreateInstance is called somewhere in LoadLibrary()?

[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

您应该能够简单地将对DLL的引用直接添加到.NET项目中-将创建包装器,并且可以调用将委派给COM组件的包装器方法。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM