gpt4 book ai didi

c# - 获取错误 "Attempted to read or write protected memory"

转载 作者:太空宇宙 更新时间:2023-11-04 12:21:33 33 4
gpt4 key购买 nike

这是头文件中的内容。

/// Creates a new file geodatabase in the specified location.
/// @param[in] path The location where the geodatabase should be created.
/// @param[out] geodatabase A reference to the newly-created geodatabase.
/// @return A long integer indicating whether the method finished successfully.
EXT_FILEGDB_API long CreateGeodatabase(const std::wstring& path, Geodatabase& geodatabase);

这就是我的 dllimport 的样子。

[DllImport("FileGDBAPI.dll", EntryPoint = "#49", SetLastError=true, CallingConvention=CallingConvention.Winapi)]
public static extern int CreateGeodatabase([MarshalAs(UnmanagedType.LPStr)]string path, ref IntPtr geodatabase);

..这是使用它的代码。

IntPtr Geodatabase = IntPtr.Zero;
FileGDBAPI_wrapper.CreateGeodatabase("c:\temp\testGDB.gdb", ref Geodatabase);

我做错了什么?

最佳答案

我看到两个可能的问题:

  1. C++ 代码使用宽字符串,C# 代码使用 ANSI 字符串
  2. C++ 代码使用的是 std::wstring 类,而不是 c 风格的空终止字符串

我认为不更改 C++ 端的 API 就无法轻松解决第二个问题

关于c# - 获取错误 "Attempted to read or write protected memory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4763953/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com