C#调用haskell遭遇Attempted to read or write protected memory
2014-05-05 12:17
603 查看
1. Haskell的代码如下:
上面的代码中readMarkdown与writeHtmlString是pandoc中的函数,newString的作用是将String转换为IO CString。
2. C语言的代码如下:
上面的代码是dll的调用入口。
3. ghc编译出来的头文件如下:
4. C#调用代码如下:
5. 运行C#代码之后,出现错误:
An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
对应的中文错误信息:
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
6. 而在ghci中执行直接执行haskell代码能得到正确的结果:
被这个“Attempted to read or write protected memory. ”问题困扰了很长时间,一直未找到解决方法。
【更新】
后来找到了解决方法,详见:困扰多日的C#调用Haskell问题竟然是Windows的一个坑
上面的代码中readMarkdown与writeHtmlString是pandoc中的函数,newString的作用是将String转换为IO CString。
2. C语言的代码如下:
上面的代码是dll的调用入口。
3. ghc编译出来的头文件如下:
4. C#调用代码如下:
class Native { [DllImport("libpandoc", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)] public static extern IntPtr markdownToHtml(byte[] markdown); } public class Processor { public string Process(string text) { var intPtr = Native.markdownToHtml(System.Text.Encoding.UTF8.GetBytes(text)); var html = Marshal.PtrToStringAnsi(intPtr); return html; } }
5. 运行C#代码之后,出现错误:
An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
对应的中文错误信息:
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
6. 而在ghci中执行直接执行haskell代码能得到正确的结果:
被这个“Attempted to read or write protected memory. ”问题困扰了很长时间,一直未找到解决方法。
【更新】
后来找到了解决方法,详见:困扰多日的C#调用Haskell问题竟然是Windows的一个坑
相关文章推荐
- c# 传递Null的string值导致的调用C++的dll报错 Attempted to read or write protected memory.
- System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
- System.AccessViolationException: Attempted to read or write protected memory This is often an indication that other memory is corrupt
- Message: Attempted to read or write protected memory. This is often an indication that other memory
- 关于accessviolationexception. Attempted to read or write protected memory. This is often an indication that other memory is corrup
- Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
- Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
- System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt".
- attempt to write a readonly database错误的解决(C#,SQLite) ..
- window从linux服务器上下载东西报错:security violation: remote host attempted to write to a '.' or '..' path!
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- attempt to write a readonly database错误的解决(C#,SQLite)
- C#操作SQLite 报错 (Attempt to write a read-only database)
- Configure file like format of ini and read data from ini file or write data to ini file
- c#操作sqlite时出现attempt to write a readonly database错误的解决方法
- IAR中出现 Failed to write memory at 0x866E: SWIM PROG error [42008]: Attempt to write to protected area
- Reading or Writing to Another Processes Memory in C# z
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- ubuntu无法启动,出现attempt to read or write outside of disk hd0错误
- Use Haskell ByteString to Read/Write File