I have a struct in C file as shown below
struct Parameter{
char param1[20];
char param2[20];
}
and also a function in C file which takes this struct as parameter along with char* as another parameter as shown below
extern "C" __declspec(dllexport) void GetValue(char* opt,struct Parameter param);
void GetValue(char* opt, struct Parameter params)
{
printf("%s", params->param1);
}
I want to call it from my C# application using marshalling. I have created a similar struct in C#
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class Parameters
{
public string Param1 { get; set; }
public string Param1 { get; set; }
}
and calling it in C# using the below method
[DllImport(@"C:\Test\CTestDll.dll",CallingConvention = CallingConvention.Cdecl,CharSet=CharSet.Ansi)]
public static extern void GetValue([MarshalAs(UnmanagedType.LPStr)]StringBuilder sbOut, [MarshalAs(UnmanagedType.LPStruct)]Parameters sbIn);
but the result which is a print statement is printing null.I am not very good in C programming. Kindly help me to sort it out. Where I am wrong, Is it in the C function or marshalling from C#