S
scottelloco
Hi,
I currently have a C++ dll that's passing a struct to a C# application.
Everything is working except for the char array member in the struct.
When I look at the values in the C# app when debugging all I see are a
few square "control-type" characters. The way I'm doing this is based
on the MSDN documentation and posts I've seen from users in the group.
The folloing is a sample of my code. I've tried using both CharSet.Auto
and CharSet.UniCode on my struct and function definitions, but receive
the same results either way.
I would appreciate any assitance.
Thanks, -Scott
C++ code
--------------
struct tblProcedure
{
unsigned long ProcedureId;
unsigned long InstitutionId;
char FName[56];
char LName[56];
}
CEDBXML_API bool LoadProcedure(tblProcedure* procedure)
{
procedure->ProcedureId = 810;
procedure->InstitutionId = 2002;
memcpy(procedure->FName, "Michael", sizeof("Michael"));
memcpy(procedure->LName, "Houser", sizeof("Houser"));
}
extern "C"
{
CEDB_API bool LoadProcedure(tblProcedure* tblProc);
}
C# code
---------------
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct tblProcedure
{
public int ProcedureId;
public int AttendingId;
public int InstitutionId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 56)]
public string FName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 56)]
public string LName;
};
[DllImport("CedbXml", CharSet = CharSet.Auto)]
public static extern bool LoadProcedure(ref
CEDBProcedures.tblProcedure Procs);
tblProcedure procobj = new tblProcedure();
CeDbApi.LoadProcedure(ref procobj);
----------------------------------------------
At this point procobj.FName and procobj.LName just basically have a
bunch of garbage in them when I look at the values in the debugger.
I would appreciate any ideas.
Thanks, -Scott
I currently have a C++ dll that's passing a struct to a C# application.
Everything is working except for the char array member in the struct.
When I look at the values in the C# app when debugging all I see are a
few square "control-type" characters. The way I'm doing this is based
on the MSDN documentation and posts I've seen from users in the group.
The folloing is a sample of my code. I've tried using both CharSet.Auto
and CharSet.UniCode on my struct and function definitions, but receive
the same results either way.
I would appreciate any assitance.
Thanks, -Scott
C++ code
--------------
struct tblProcedure
{
unsigned long ProcedureId;
unsigned long InstitutionId;
char FName[56];
char LName[56];
}
CEDBXML_API bool LoadProcedure(tblProcedure* procedure)
{
procedure->ProcedureId = 810;
procedure->InstitutionId = 2002;
memcpy(procedure->FName, "Michael", sizeof("Michael"));
memcpy(procedure->LName, "Houser", sizeof("Houser"));
}
extern "C"
{
CEDB_API bool LoadProcedure(tblProcedure* tblProc);
}
C# code
---------------
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct tblProcedure
{
public int ProcedureId;
public int AttendingId;
public int InstitutionId;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 56)]
public string FName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 56)]
public string LName;
};
[DllImport("CedbXml", CharSet = CharSet.Auto)]
public static extern bool LoadProcedure(ref
CEDBProcedures.tblProcedure Procs);
tblProcedure procobj = new tblProcedure();
CeDbApi.LoadProcedure(ref procobj);
----------------------------------------------
At this point procobj.FName and procobj.LName just basically have a
bunch of garbage in them when I look at the values in the debugger.
I would appreciate any ideas.
Thanks, -Scott