Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating a wrapper for C++ DLL

Status
Not open for further replies.

robUK2

Programmer
Mar 10, 2008
57
TH
Hello,

VS 2008

I have a .Net application that P/Invokes with a DLL written in C++. Everything works, and now I have to create a wrapper, but not sure how to do this.

Does the wrapper need to be created in C#.Net or C++?

In the C++ code is is just some getters and settings that I need information from.

Most Internet sites I have looked at seem too complicated to understand.

I am just looking for a very simple example to get started.

Many thanks,


 
In C#, something like this
Code:
namespace xxx
{
   public sealed class wrapper
   {
      [DLLImport("dllname")]
      private static extern void cppFuncName(int param);

      public void csFuncName (int param)
      {
         cppFuncName (param);
      }
   }
}
 
Hello,

Just to give more information on this. Here is the code below. I want to create a wrapper to have more capacablility between different datatypes, and to make the code more maintainable. The code is just an short example. However, there will be more call backs and functions then this.

I am currently using C#.Net as the front-end and Native C++ for the DLL written in VS 2008.

If anyone can give me a general idea on how to write this, to get me going in the right directions.

I think the code you have given me is something I have done already.

Many thanks,

Code:
// *.hpp File =====================
typedef void (__stdcall *ptrIncomingCall)(int, char*);
MOBILEDLL_API void drvIncomingCall(ptrIncomingCall cb);

// *.cpp File =====================
void drvIncomingCall(ptrIncomingCall cb)
{
        cb(200, "jobBloggs@10.10.10.10");
}

// *.Net File =====================
private  delegate  void IncomingCallDelegate(int callerID, string caller);
         [DllImport("MobileDLL.dll")]
         static extern  void drvIncomingCall(IncomingCallDelegate OnIncomingCall);

void OnIncomingCall(int callerID, string caller)       
{     
     this.label3.Text = callerID.ToString();
      
     byte[] callerBytes = System.Text.UnicodeEncoding.Unicode.GetBytes(caller);
     this.label4.Text = System.Text.Encoding.ASCII.GetString(callerBytes, 0, callerBytes.Length);
}

//Call from .Net 
drvIncomingCall((IncomingCallDelegate)  OnIncomingCall);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top