-1

I have native c++ dll, header file and lib file. I want to create managed wrapper of it. I do not have source code of dll. How Can I call/used that in C# or C++ Managed code. Here is header file

Thanks, Adil

Adil Fazal
  • 279
  • 4
  • 13
  • Well, i don't see how it is a duplicate, since the referred question is bout using a native C++ dll with C++.net. Here we are talking about using a native C+ dll with C#. – Irwene Jun 10 '15 at 14:24

1 Answers1

1

If you've got the dll's header, you can use DllImport (you can also use it without but i would have been slightly more complicated)

This will allow you to specify a method you'll be able to call in your managed code that will match one of those in the dll.

You'll have a little work to do though, you have to tell the C# compiler which type to use to match the C++ ones

Irwene
  • 2,807
  • 23
  • 48
  • As an added example, i had to create such a wrapper, if you want to have a look : https://github.com/sidewinder94/Logitech-LCD/blob/master/Logitech-LCD/NativeMethods.cs#L97 – Irwene Jun 10 '15 at 13:16
  • Thanks for prompt reply. I am trying DLL Import. Header has class name CBAPSIDLL and method void Version(char *version,int len); I am doing following in C# [DllImport("BAPSIDLL.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Version", CharSet = CharSet.Unicode)] public static extern void Version( [MarshalAs(UnmanagedType.LPStr)]StringBuilder version, int lenght); Getting following error {"Unable to find an entry point named 'Version' in DLL 'BAPSIDLL.dll'.":""} What I am doing wrong? Please tell me – Adil Fazal Jun 10 '15 at 13:39
  • Well, from the error you got, it seems that there is no method named Version in your dll. – Irwene Jun 10 '15 at 14:26