C#格式化外部Dll函数参数 [英] C# formatting external Dll function parameters

查看:84
本文介绍了C#格式化外部Dll函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于该主题,我尚未找到很好的参考.在此示例中,我们将使用一些我试图移植到C#的C ++代码.

I have yet to find a good reference on this topic. For this example we will take some C++ code that I'm trying to port over to C#.

在C ++领域中,我们具有以下用于外部库函数的原型:

In C++ land we have the following prototype for an external library function:

extern "C" DWORD EXPORT FILES_GetMemoryMapping(
  PSTR pPathFile,
  PWORD Size,
  PSTR MapName,
  PWORD PacketSize,
  PMAPPING pMapping,
  PBYTE PagesPerSector);

在其中的用法如下:

FILES_GetMemoryMapping((LPSTR)(LPCTSTR)MapFile, &Size, (LPSTR)MapName, &PacketSize, pMapping, &PagePerSector);

现在,我正在尝试将第一行移植到C#,这是我没有明确路径的地方.

Now I'm trying to port the first line over to C# and here is where I'm presented with no clear path.

这是我到目前为止所得到的:

This is what I've got so far:

[DllImport("Files.DLL")]
public static extern uint FILES_GetMemoryMapping(
    [MarshalAs(UnmanagedType.LPStr)]
    string pPathFile,
    out ushort Size,
    [MarshalAs(UnmanagedType.LPStr)]
    string MapName,
    out ushort PacketSize,
    IntPtr pMapping,
    out byte PagesPerSector);

现在的问题是:是否有任何好的指南告诉我,"PSTR pPathFile"应为"[MarshalAs(UnmanagedType.LPStr)]字符串pPathFile" ...假设是正确的?

Now the question is: Is there any good guide out there that tells me a "PSTR pPathFile" should be "[MarshalAs(UnmanagedType.LPStr)] string pPathFile" ... Assuming that is correct?

或者,一个指向"PMAPPING"结构的指针变成"out IntPtr pMapping"……假设正确吗?

Or, a that a pointer to a "PMAPPING" struct becomes a "out IntPtr pMapping" ... assuming that is correct?

对这个家伙有帮助吗?

推荐答案

我还没有找到关于这个主题的很好的参考

I have yet to find a good reference on this topic

您在这里.

奇怪的是,此刻该站点已关闭,但它是解决问题的很好资源.同时,您可以在

Oddly, the site is down at the moment, but it's a very good resource for marshalling problems. In the mean time, you can use Archive.net's archive of pinvoke.net at http://web.archive.org/web/20080202041852/http://www.pinvoke.net

这篇关于C#格式化外部Dll函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆