B
borewill
I have a dll writtin in native C++ which provide such interface:
typedef struct _PARAM
{
LPWSTR swName;
DWORD dwOptions;
} PARAM,*PPARAM,*LPPARAM;
DLLEXPORT BOOL CALLBACK Function(LPPARAM pData);
Call as:
PARAM ParamsArray[]={
{L"Anna",202},
{L"John",324},
{L"Doe",4094},
{L"etc..",3003},
{NULL,0}
};
Function((PPARAM)&ParamsArray);
How to call this native dll from managed C# code?
How to easy init array of such params in C# and correctly send it to
dll function?
I created C# class
namespace test
{
class NativeDll
{
[StructLayout(LayoutKind.Sequential)]
public struct PARAM
{
[MarshalAs(UnmanagedType.LPStr)]
public String swName;
public uint dwOptions;
};
[DllImport("Easymovedll.dll", CallingConvention =
CallingConvention.Winapi,
CharSet=CharSet.Unicode,EntryPoint="_Function")]
public static extern bool Function(ref PARAM[] PPARAM);
}
}
Calling in C#:
using test;
NativeDll.PARAM[] ParamsArray=new NativeDll.PARAM[2];
PARAM[0].swName="john";
PARAM[0].dwOptions=2093;
PARAM[1].swName=null;
PARAM[1].dwOptions=0;
NativeDll.Function(ref ParamsArray);
But this is not give me correct array is I want. What I doing wrong?
typedef struct _PARAM
{
LPWSTR swName;
DWORD dwOptions;
} PARAM,*PPARAM,*LPPARAM;
DLLEXPORT BOOL CALLBACK Function(LPPARAM pData);
Call as:
PARAM ParamsArray[]={
{L"Anna",202},
{L"John",324},
{L"Doe",4094},
{L"etc..",3003},
{NULL,0}
};
Function((PPARAM)&ParamsArray);
How to call this native dll from managed C# code?
How to easy init array of such params in C# and correctly send it to
dll function?
I created C# class
namespace test
{
class NativeDll
{
[StructLayout(LayoutKind.Sequential)]
public struct PARAM
{
[MarshalAs(UnmanagedType.LPStr)]
public String swName;
public uint dwOptions;
};
[DllImport("Easymovedll.dll", CallingConvention =
CallingConvention.Winapi,
CharSet=CharSet.Unicode,EntryPoint="_Function")]
public static extern bool Function(ref PARAM[] PPARAM);
}
}
Calling in C#:
using test;
NativeDll.PARAM[] ParamsArray=new NativeDll.PARAM[2];
PARAM[0].swName="john";
PARAM[0].dwOptions=2093;
PARAM[1].swName=null;
PARAM[1].dwOptions=0;
NativeDll.Function(ref ParamsArray);
But this is not give me correct array is I want. What I doing wrong?