1. Haskell的代码如下:

上面的代码中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#调用haskell遭遇Attempted to read or write protected memory的更多相关文章

  1. c# 传递Null的string值导致的调用C++的dll报错 Attempted to read or write protected memory.

    c# 调用C++的dll报错 Attempted to read or write protected memory:   原因是:c# 传递Null的string值导致的,将Null改为string ...

  2. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt".

    昨天遇到一个比较奇怪的问题,运行VS2010调试程序的时候,总是会报一个错,然后程序就挂掉了:无可用源….,弹出一个窗口提示:System.AccessViolationException: Atte ...

  3. [SQL] - Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 问题之解决

    场景: 使用 Oracle.DataAccess.dll 访问数据库时,OracleDataAdapter 执行失败. 异常: System.AccessViolationException was ...

  4. 困扰多日的C#调用Haskell问题竟然是Windows的一个坑

    最近一直被C#调用Haskell时的“尝试读取或写入受保护的内存”问题所困扰(详见C#调用haskell遭遇Attempted to read or write protected memory,C# ...

  5. 经过实际验证的C#调用Haskell的方法

    [系统环境] Windows Server 2008 R2,Haskell Platform 2013.2.0.0,ghc 7.6.3,cabal 1.16.0 [操作步骤] 1. 安装Windows ...

  6. System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。

    系统debug时出现错误,System.AccessViolationException: 尝试读取或写入受保护的内存.这通常指示其他内存已损坏. Attempted to read or write ...

  7. 要让CLR挂掉的话……

    http://rednaxelafx.iteye.com/blog/460893 (Disclaimer:如果需要转载请先与我联系. 作者:RednaxelaFX -> rednaxelafx. ...

  8. 背水一战 Windows 10 (52) - 控件(集合类): ItemsControl - 自定义 ItemsControl, 自定义 ContentPresenter

    [源码下载] 背水一战 Windows 10 (52) - 控件(集合类): ItemsControl - 自定义 ItemsControl, 自定义 ContentPresenter 作者:weba ...

  9. WinDbg 解决Font.ToLogFont AccessViolationExcetion

    有个程序总是在windows 2003 server 异常退出. 并且,  查看调用栈也肯奇怪, 应该是很正常的调用. 怀疑是堆溢出. 开启heap trace : C:\Program Files\ ...

随机推荐

  1. [Hbase]Hbase章1 Hbase框架及基本概念

    Hbase框架介绍 HBase是一个分布式的.面向列的开源数据库. 不同点: l  和一般的关系数据库不同,hbase是一个适合于非结构化数据存储的数据库. l  Hbase是基于列而不是基于行的模式 ...

  2. 最全面!2019年最新UX设计趋势预测合集

    以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 追逐潮流是每个行业都必做的一件事,对于直接影响数字产品定位和用户感知方式的UX设计也是如此. 不论你 ...

  3. maven打包之后为什么class文件中没有注释了?

    <!--生成doc jar包--> <plugin> <groupId>org.apache.maven.plugins</groupId> <a ...

  4. MVVM中viewmodel的理解

    网上有人写了这段话,我也有同感,特别是第一种用法,很重要,后一种用法,我觉得是把第一种用法加入controller中了. 第一种 “view model” 是 “model for the view” ...

  5. 单片机一种简便的printf调试方案。

    此处引用csdn博客.链接如下. http://blog.csdn.net/cp1300/article/details/7773239 http://blog.csdn.net/aobai219/a ...

  6. 扩展方法(深入理解c#)

    1. 静态类到扩展方法: 许多方法可能都适合转为扩展方法,只要具有以下特征: 1)你想为一个类型添加一些成员: 2)你不需要为类型的实例添加更多的数据: 3)你不能改变类型本身,因为是别人的代码 2. ...

  7. sqlserver的substring详细用法

    SQL 中的 substring 函数是用来截取一个栏位资料中的其中一部分. 例如,我们需要将字符串'abdcsef'中的‘abd’给提取出来,则可用substring 来实现: select sub ...

  8. springboot 容器启动事件

    在springboot 容器启动时,我们需要在启动过程中做一些操作,比如启动容器后,执行某些代码. spring 提供了监听器,我们可以方便的实现这些操作. 在容器启动开始时: package com ...

  9. flex布局中的主轴和侧轴的确定

    1.主轴和侧轴是通过flex-direction确定的 如果flex-direction是row或者row-reverse,那么主轴就是justify-contain 如果flex-direction ...

  10. B-论文一些好的句子

    Due to high design and test costs for real many-core chips, simulators which allow exploring the bes ...