Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions CodeGenDom/NativeCodeGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,26 @@ private static void GeneratePropertyDefinition(StringBuilder sb, NativeClassInfo
WriteLine(sb, " {0}* instance = reinterpret_cast<{0}*>(instanceId);", classInfo.NativeName);
WriteLine(sb, " static {0} localData;", info.NativeType);
WriteLine(sb, " localData = instance->Get{0}();", info.NativeName);
WriteLine(sb, " *data = (void*)&localData;");
WriteLine(sb, " *size = sizeof(localData);");

// need special handling for strings and wide strings here,
// or you'll end up trying to marshal the memory address
// instead of the contents into a managed string downstream
switch(info.NativeType)
{
case "wchar_t*":
WriteLine(sb, " *data = (void*)localData;");
WriteLine(sb, " *size = wcslen(localData);");
break;
case "char*":
WriteLine(sb, " *data = (void*)localData;");
WriteLine(sb, " *size = strlen(localData);");
break;

default:
WriteLine(sb, " *data = (void*)&localData;");
WriteLine(sb, " *size = sizeof(localData);");
break;
}
WriteLine(sb, "}}");
}
}
Expand Down