"Proper" way to Interop with Unmanaged Dll
- From: bvbone69@xxxxxxxxx
- Date: 10 Oct 2005 10:59:14 -0700
Hi... I have the following (and many more) functions I need to use
MC_STATUS MC_Register_Application(int* ApplicationID, char* AEtitle);
I'm trying to access this function from c#, from my reading I have come
up with 2 possible ways to do this by creating a managed c++ wrapper...
//////////////////////////////////////////////////////////////
// 1)
__gc public class CMergeInterop
{
[DllImport("mc3adv.dll")]
static MC_STATUS MC_Register_Application(Int32* ApplicationID,
[MarshalAs(UnmanagedType::LPStr)]String* AEtitle);
}
//////////////////////////////////////////////////////////////
// 2)
#pragma unmanaged
[DllImport("mc3adv.dll")]
extern MC_STATUS MC_Register_Application(int* ApplicationID, char*
AEtitle);
#pragma managed
__gc public class CMergeInterop
{
tatic MC_STATUS MC_Register_Application(Int32* ApplicationID, String*
AEtitle)
{
IntPtr aParam1;
aParam1 = Marshal::AllocHGlobal(sizeof(int*));
IntPtr aString;
aString = Marshal::StringToHGlobalAuto(AEtitle);
MC_STATUS eStatus =
::MC_Register_Application((int*)aParam1.ToPointer(),
(char*)aString.ToPointer());
*ApplicationID = (int)(aParam1);
Marshal::FreeHGlobal(aParam1);
Marshal::FreeHGlobal(aString);
return eStatus;
}
}
or
//////////////////////////////////////////////////////////////
// 3) some other way
Which is the (A) Preferred Way (B) Correct Way (C) Most Efficient Way
Thanks
bv
.
- Prev by Date: COM Object Property not accessible
- Next by Date: Re: using PIA'S at the time of deployment
- Previous by thread: COM Object Property not accessible
- Next by thread: side by side assemblies under same IIS process load wrong unmanaged dll
- Index(es):