Skip to content

Commit 4bb3d1b

Browse files
author
moethu
committed
fixing tostring #9
1 parent 64766b2 commit 4bb3d1b

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

SketchUp/SketchUpNET/SketchUpNET/SketchUpNET.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ namespace SketchUpNET
120120
/// </summary>
121121
bool LoadModel(System::String^ filename, bool includeMeshes)
122122
{
123-
msclr::interop::marshal_context oMarshalContext;
124-
125-
const char* path = oMarshalContext.marshal_as<const char*>(filename);
123+
const char* path = Utilities::ToString(filename);
126124

127125
SUInitialize();
128126

@@ -237,8 +235,7 @@ namespace SketchUpNET
237235

238236
bool SaveAs(System::String^ filename, SKPVersion version, System::String^ newFilename)
239237
{
240-
msclr::interop::marshal_context oMarshalContext;
241-
const char* path = oMarshalContext.marshal_as<const char*>(filename);
238+
const char* path = Utilities::ToString(filename);
242239
SUInitialize();
243240

244241
SUModelRef model = SU_INVALID;
@@ -291,9 +288,7 @@ namespace SketchUpNET
291288
/// </summary>
292289
bool AppendToModel(System::String^ filename)
293290
{
294-
msclr::interop::marshal_context oMarshalContext;
295-
296-
const char* path = oMarshalContext.marshal_as<const char*>(filename);
291+
const char* path = Utilities::ToString(filename);
297292

298293
SUInitialize();
299294

SketchUp/SketchUpNET/SketchUpNET/Utilities.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,16 @@ namespace SketchUpNET
6565
return gcnew System::String(name_utf8, 0, name_length, System::Text::Encoding::UTF8);
6666
}
6767

68-
static const char* ToString(System::String^ name)
68+
static const char* ToString(System::String^ value)
6969
{
70-
return (const char*)(System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(name)).ToPointer();
70+
array<unsigned char>^ bytes = System::Text::Encoding::UTF8->GetBytes(value);
71+
char* result = new char[bytes->Length + 1];
72+
result[bytes->Length] = 0;
73+
int i = 0;
74+
for each(unsigned char c in bytes) {
75+
result[i++] = c;
76+
}
77+
return result;
7178
}
7279

7380

0 commit comments

Comments
 (0)