diff --git a/EdiabasLib/Api32/ApiDll.cpp b/EdiabasLib/Api32/ApiDll.cpp index c5b1045d3..e5d138d71 100644 --- a/EdiabasLib/Api32/ApiDll.cpp +++ b/EdiabasLib/Api32/ApiDll.cpp @@ -254,6 +254,7 @@ static String ^ ConvertCString(const char far *string) { return String::Empty; } + array^ bytes = gcnew array(length); pin_ptr p = &bytes[0]; memcpy(p, string, length); @@ -266,20 +267,26 @@ static array ^ ConvertNetString(String ^string, char far *buf, int bufsize { return nullptr; } + if (string == nullptr) { buf[0] = 0; return nullptr; } - array ^ bytes = Ediabas::ApiInternal::Encoding->GetBytes(string); - int length = min(bytes->Length, bufsize - 1); - if (length > 0) + + array ^ bytesEncode = Ediabas::ApiInternal::Encoding->GetBytes(string); + int length = min(bytesEncode->Length, bufsize - 1); + array^ bytesResult = gcnew array(length + 1); + for (size_t i = 0; i < length; i++) { - pin_ptr p = &bytes[0]; - memcpy_s(buf, bufsize, p, length); + bytesResult[i] = bytesEncode[i]; } - buf[length] = 0; - return bytes; + bytesResult[length] = 0; + + pin_ptr p = &bytesResult[0]; + memcpy_s(buf, bufsize, p, bytesResult->Length); + + return bytesResult; } #ifdef __cplusplus