开发者

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


You should be able to simply add a reference to the DLL directly to the .NET project - a wrapper will be created and you can call the wrapper methods that will be delegated to the COM component.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜