It is necessary to "wrap" the C ++ based SDK dll / h / lib / xml / exe in COM for use in a C # 2.0 project

I was just handed the SDK from C ++ dll, lib, exe and various .h files. I assume it is for C ++ developers. The sample projects they provide with their documentation are all written in C ++. I can deploy them with Visual Studio 8 (2005) and run them. They monitor the device as advertised. However, the project to be used is in C # .Net 2.0 and this is not possible.

My boss was a C ++ developer and says that I only need to compile it as a COM object and then import the COM object into my C # solution. My boss says that it will take less than an hour for me to "wrap" the SDK as a COM object, even if I don't know how to compile in C ++.

I used COM objects in C # solutions before, once that's done, I can continue from there without issue.

However, I don't know what to do to make a COM object from files with the extension .dll, 1.exe, 1.lib file, 1.xml file and 12.h files. Is there a resource available to tell me what to do to make this happen?

+1


source to share


7 replies


My boss was a C ++ developer and says that I only need to compile it as a COM object and then import the COM object into my C # solution.

This is true, however , compiling it as a COM object is "difficult" (which I mean you can't do that) if it doesn't already implement the COM API (if it doesn't "t then you need to implement COM API before you can create it as a COM object).

There are books (like Essential COM) that explain how to create COM objects with C ++, but these are non-trivial (there might be better books for creating COM objects than Essential COM, as well as better / simpler tools than C ++).

I think you and / or your boss have 3 options:



  • Ask your vendor to provide them to you as COM objects
  • Create a COM API that will wrap the SDK API. Create a COM project (in the language of your choice) that exports this API. Implement these APIs using basic SDK methods. To do this, you may need someone who knows C ++ or is willing to spend a lot, much longer than an "hour" on this project.
  • Forget about using COM; instead create the SDK as a DLL and use PInvoke to call it from .NET code.

My boss says that it doesn't take less than an hour for me to "wrap" the SDK as a COM object, even if I don't know how to compile in C ++.

Based on what you said, I don't know how to do this.

+3


source


Tell your boss if it takes him less than an hour to wrap him up, he should definitely do it: it will be a more efficient use of your time.



I would also suggest ATL (not using attributes), but this is something that might take a while to get right if you're not experiencing.

+1


source


My boss says it should take less than an hour to "wrap" the SDK there as a COM object, even for me without knowledge of C ++ compilation.

This may be true for an experienced C ++ / COM developer, but not for beginners. I find it best to use ATL. Take a look at the MSDN tutorial .

And don't use attributes.

0


source


It doesn't quite answer your question, but ...

One option instead of trying to create a COM object is to use P / Invoke and just call methods in the DLL.

This thread on the MSDN forums describes how to make a DLL to be called using P / Invoke.

Of course, if you need access to an entire class (and make an instance of the specified object), this won't be useful.

0


source


It's good that the code compiles and runs for you. It said it was completely unfair to assume that you can do it in an hour.

You checked what Visual Studio is actually building. It is possible that it is already creating a COM object.

Find out how the code is called. I am assuming you have an .exe that you can run to test your code. Go through this in the VC ++ debugger (it's similar enough to debugging C # code) and try to identify any API calls that match your docs / expectations. This knowledge will be helpful if you try to P / Invoke route.

Something else needs to be considered by SWIG . This is commonly used by Python developers to port C / C ++ code and provides some C # support.

The managed C ++ route is probably more appropriate for experienced C ++ developers because you need to understand a lot about memory allocation for all but the simplest code.

0


source


I (well, really, my leader and I) will first try to use p / Invoke (via the DllImport function for System.Runtime.InteropServices) against the SDK dll provided by the company. I'll let you know how it goes.

0


source


I think you really want / need C ++ / CLI, this way you can just create them directly in the managed assembly. The idea is that you write a pretty basic wrapper that looks like something like C # and C ++ and then does the rest.

-1


source







All Articles