如何從C++ dll調用中讀取C#中的錯誤字符串?如何從指針讀取字符串緩衝區中的C#
//
// PARAMETERS:
// objptr
// Pointer to class instance.
//
// pBuffer
// Pointer to buffer receiving NULL terminated error message string.
// If this value is zero, the function returns the required buffer size, in bytes,
// and makes no use of the pBuffer.
//
// nSize
// Size of receiving buffer.
// If this value is zero, the function returns the required buffer size, in bytes,
// and makes no use of the pBuffer.
//
// RETURN VALUES:
// If pBuffer or nSize is zero, the function returns the required buffer size, in bytes.
// If the function succeeds, the return value is number of bytes copied into pBuffer.
// If function fails return value is 0.
//
extern unsafe int GetError(uint objptr, byte* pBuffer, int nSize);
謝謝!
我用GetError(???,NULL,0)來獲得郵件大小,以創建緩衝區,還努力完善。謝謝! –
您也可以嘗試將byte *更改爲StringBuilder,並通過它來避免不安全的代碼。 –
@Mikael:我該怎麼做? dll方法期望字節* –