Код: Выделить всё
BL_API BLResult BL_CDECL bl_image_write_to_file(const BLImageCore* self, const char* file_name, const BLImageCodecCore* codec) BL_NOEXCEPT_C;
< /code>
Я получаю < /p>
Неизвестное исключение Type 'System.accessviolationException' произошло в my.dll. < /p>
< /blockquote>
попытка читать или написать защищенную память. Это часто указывает на то, что другая память повреждена. < /P>
< /blockquote>
Мой код: < /p>
internal static class Lib
{
[DllImport(dllPath, CallingConvention = CallingConvention.Cdecl)]
static extern ResultCode bl_image_write_to_file(ref nint image_handle, ref nint path, ref nint codec_handle);
internal static ResultCode ImageWriteToFile(ref nint image_handle, string filepath)
{
nint nullptr = default;
nint marshaledstring = Marshal.StringToHGlobalAnsi(filepath);
// exception thrown here. There is a problem with one of these three parameters.
var result = bl_image_write_to_file(ref image_handle, ref marshaledstring, ref nullptr);
Marshal.FreeHGlobal(marshaledstring);
return result;
}
}
Код: Выделить всё
//! Writes an encoded image to a file specified by `file_name`.
//!
//! Image writer detects the image codec by inspecting the extension of a file passed via `file_name`.
BL_INLINE_NODEBUG BLResult write_to_file(const char* file_name) const noexcept {
return bl_image_write_to_file(this, file_name, nullptr);
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... c-function
Мобильная версия