元帅串到asciiz

时间:2013-12-01 18:50:22

标签: c# visual-studio-2012 pinvoke dllimport

我正在尝试调用需要Asciiz指针的DLL函数:

int doExample(Asciiz* FolderPath, Asciiz* OutputPath, int Flags);

我已尝试使用StringBuilder,但我一直收到有关访问受保护内存的错误。这是我的C#代码:

public class Example
{
  [DllImport("Example.dll", EntryPoint="?doExample@Example@@QADHPYDH0P6A_N0ZZ000@Z")]
        static extern int doExample(StringBuilder folderPath, StringBuilder outputPath, int flags);

  public int do(string folderPath, string outputPath)
  {
    StringBuilder FolderPath = new StringBuilder(folderPath);
    StringBuilder OutputPath = new StringBuilder(outputPath);
    doExample(FolderPath, OutputPath, 0);
  }
}

关于为什么会发生这种情况的任何想法?或者这严格来说是C ++代码中的错误?

编辑:根据评论,这里有更多信息:

  • DLL建立在VS2010上
  • 我正在VS2012中构建C#代码(这里的差异可能导致问题吗?)
  • 我不确切知道DLL中的功能是什么;我在C ++方面的知识非常有限。基本上,它获取一个目录,压缩它并将其输出到一个文件中的输出路径。
  • 我知道EntryPoint中的名称错误;我把一些随机字符放进去;函数名称与实际DLL中的函数名称不同,但参数类型和返回类型是相同的。另外,我从Dependency Walker获得了真正的错位函数名。如果我没有指定EntryPoint,则无法找到该功能。 (我确实有这个DLL的C ++源代码btw)
  • 完整错误是:AccessViolationException未处理:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。

0 个答案:

没有答案