gpt4 book ai didi

C#格式化外部Dll函数参数

转载 作者:行者123 更新时间:2023-11-30 15:50:20 25 4
gpt4 key购买 nike

我还没有找到关于这个主题的好引用。对于这个例子,我们将采用一些我试图移植到 C# 的 C++ 代码。

在 C++ 领域,我们有以下外部库函数的原型(prototype):

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# 中,但这里没有明确的路径。

这是我目前所得到的:

[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)] string pPathFile”...假设这是正确的?

或者,指向“PMAPPING”结构的指针变为“out IntPtr pMapping”……假设这是正确的?

这家伙有什么帮助吗?

最佳答案

I have yet to find a good reference on this topic

Here you go.

奇怪的是,该站点目前已关闭,但它是解决编码问题的非常好的资源。同时,您可以在 http://web.archive.org/web/20080202041852/http://www.pinvoke.net 使用 Archive.net 的 pinvoke.net 存档。

关于C#格式化外部Dll函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/727942/

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