Use C++ Header file within C#

A

Axel van Lil

Hi!


Sorry if this has been already answered but I've searched the archives
and found nothing.

Our Dev-Team needs to replace an existing C++ written DLL that is
already used by several applications. As we're mainly into Java we've
looked at opportunities to implement these dll functions as java
methods and use a native compiler. Wasn't satisfying (and didn't run
either).

Is it possible to use a c++ header file within C# and create skeleton
C# code from this header file, compile as a dll so that this new c#
written dll could cleanly replace the existing c++ dll? Will existing
(and possibly years old) applications (of which we don't have the
code) recognize the difference or won't they be able to dynamically
load a c# dll???

Thanks in advance!
 
M

M

Hi Axel,

You need to go and have a look at PInvoke for eg:

[DllImport("MyTestDlg.dll", EntryPoint="ShowTxtDlg")]
public extern static void ShowTxtDlg();

If your function returns a LPCTSTR then you need to make sure you
marshal it correctly.

In one particular case I had a function with a load of "out" parameters,
& I had to resort to using Managed C++ to get round the marshalling problems
I was having, but in most cases you can use PInvoke as is.

Probable need to run some sort a script to convert your C++ header file
to a cs file.

Get in touch if you need to know more.

Hope this helps.

Martin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top