1

I created a COM C++ and register it in the Windows system.

Now, If I'm creatine a C++ application and would like to load it and call the function objects, I'm using the CoCreateInstance function.

What should I do instead that if I want to create .NET (C#) application and load the COM C++?

Thanks

1 Answer 1

4

Assuming you are using Visual Studio:
Right click on your project, then select "Add Reference". In the following dialog, just select the Tab "COM". There you can select your COM library, Visual Studio will take care of creating an Interop assembly and you can start using your library from C#.

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

7 Comments

What if the DLL is registered before in the System by using the regsvr32 program and registered in the registry. Is there another way to load it dynamically?
@Moti The COM tab shows you those Dlls. If you reference one, it will be loaded automatically if it is registered on the current system.
I'm trying to understand... If I'm writing a program in C# with VS and then take this application and try to run the application in another PC which the COM is not found or the COM is registered in diffrent path than the first PC has, what will be happened? Thanks
@Moti It shouldn't matter where the COM dll is located, that's why it is registered. If the COM library is not installed at all, you will most probably get an exception when trying to use the COM types for the first time. Don't know right now which exception it will be, but you can try it.
I created a COM DLL in C++. Then I created new C# application and try to add the dll, but got error: "A reference to file.dll could not be added". Please advise. Thanks
|

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.