A
Andreas Kristiansson via DotNetMonster.com
Hi.
I have a problem with sending a struct from managed C# into an unmanaged C
code. I'm getting nullreference exception.
Tried below solution with ref also.
struct in c looks like this:
typedef struct
{
int width;
int height;
int x_adv;
int y_adv;
int bpl;
} iTypeWrapper_Glyph;
function decl in c looks like this:
extern "C" __declspec(dllexport) int iTypeWrapper_GetGlyph(long lUCode,
iTypeWrapper_Glyph* glyph, iTypeWrapper_GlyphMapFmt gmf);
struct in c# looks like this:
[StructLayout (LayoutKind.Sequential)]
internal struct iTypeWrapper_Glyph
{
public int width;
public int height;
public int x_adv;
public int y_adv;
public int bpl;
};
PInvoke decl in C# looks like this:
[DllImport("test.dll", SetLastError=true,CharSet = CharSet.Ansi)]
internal static extern iTypeWrapper_Glyph iTypeWrapper_GetGlyph(long
lUCode, [MarshalAs(UnmanagedType.LPStruct)] iTypeWrapper_Glyph oGlyph
,iTypeWrapper_GlyphMapFmt gmf);
The function call in C# looks like this:
iTypeWrapper_Glyph oGlyphWrapper = new iTypeWrapper_Glyph();
oGlyphWrapper = RasterizerHandler.iTypeWrapper_GetGlyph(80, oGlyphWrapper,
iTypeWrapper_GlyphMapFmt.ITYPE_WRAPPER_BITMAP_DATA);
I want to send a struct pointer into the C function so it can fill the
struct and then I want to use it in C#.
Please help me.
Been sitting with this now for one whole day.
I have a problem with sending a struct from managed C# into an unmanaged C
code. I'm getting nullreference exception.
Tried below solution with ref also.
struct in c looks like this:
typedef struct
{
int width;
int height;
int x_adv;
int y_adv;
int bpl;
} iTypeWrapper_Glyph;
function decl in c looks like this:
extern "C" __declspec(dllexport) int iTypeWrapper_GetGlyph(long lUCode,
iTypeWrapper_Glyph* glyph, iTypeWrapper_GlyphMapFmt gmf);
struct in c# looks like this:
[StructLayout (LayoutKind.Sequential)]
internal struct iTypeWrapper_Glyph
{
public int width;
public int height;
public int x_adv;
public int y_adv;
public int bpl;
};
PInvoke decl in C# looks like this:
[DllImport("test.dll", SetLastError=true,CharSet = CharSet.Ansi)]
internal static extern iTypeWrapper_Glyph iTypeWrapper_GetGlyph(long
lUCode, [MarshalAs(UnmanagedType.LPStruct)] iTypeWrapper_Glyph oGlyph
,iTypeWrapper_GlyphMapFmt gmf);
The function call in C# looks like this:
iTypeWrapper_Glyph oGlyphWrapper = new iTypeWrapper_Glyph();
oGlyphWrapper = RasterizerHandler.iTypeWrapper_GetGlyph(80, oGlyphWrapper,
iTypeWrapper_GlyphMapFmt.ITYPE_WRAPPER_BITMAP_DATA);
I want to send a struct pointer into the C function so it can fill the
struct and then I want to use it in C#.
Please help me.
