1

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.