why do we use Managed C++ wrapper code instead of Platform Invoke (DllImport) when invoking Unmanaged code from Managed code?

  • Thread starter Thread starter aditya satya prakash
  • Start date Start date
A

aditya satya prakash

Guest
Hi All,

I was given a new project and this project has both Managed and Unmanaged code. Here I am seeing managed C++ Class Library that calls unmanaged code.

I know that we can use Platform Invoke (DllImport) to call native DLLs. That should usually be the solution chosen for calling native DLLs from managed code.

Here why do we use Managed C++ code instead of Platform Invoke (DllImport)? Is there any reason for using managed C++ wrapper?

And also I heard that we can use COM code from .NET using RCW (Runtime Callable Wrappers). The RCW, a managed wrapper code, wraps the COM component.

Can we use Platform Invoke (DllImport) instead of Managed C++ code / COM code from .NET using RCW?

To call from Managed to Unmanaged I am using the code like as shown below:

C# (Managed code)

[DllImport("drvutil.dll", CallingConvention = CallingConvention.Cdecl)]
[return:MarshalAs(UnmanagedType.Bool)]
public static extern Boolean IsUPSPresent();


C++ (UnManged Code)

extern "C" {

__declspec(dllexport) BOOL IsUPSPresent();

}

Similarly how to call Managed code from UnManaged code?

could anyone please help me.


Y A S Prakash

Continue reading...
 
Back
Top