PInvokeStackImbalance ——带有 offreg.dll 的 C# (windows ddk7)
我正在尝试使用 windows ddk 7 包中提供的 offreg.dll 在内存中创建脱机注册表。
您可以在此处找到有关 offreg.dll 的更多信息: MSDN
目前,在尝试创建配置单元时使用 ORCreateHive,我收到以下错误:
“托管调试助手‘PInvokeStackImbalance’已检测到问题。这可能是因为托管 PInvoke 签名与非托管目标签名不匹配。请检查 PInvoke 签名的调用约定和参数是否与目标非托管签名。”
这是包含 ORCreateHive 的 offreg.h 文件:
typedef PVOID ORHKEY;
typedef ORHKEY *PORHKEY;
VOID
ORAPI
ORGetVersion(
__out PDWORD pdwMajorVersion,
__out PDWORD pdwMinorVersion
);
DWORD
ORAPI
OROpenHive (
__in PCWSTR lpHivePath,
__out PORHKEY phkResult
);
DWORD
ORAPI
ORCreateHive (
__out PORHKEY phkResult
);
DWORD
ORAPI
ORCloseHive (
__in ORHKEY Handle
);
以下是我的 C# 代码,尝试调用 .dll 并创建指针以供将来使用。
using System.Runtime.InteropServices;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("offreg.dll", CharSet = CharSet.Auto, EntryPoint = "ORCreateHive", SetLastError=true, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr ORCreateHive2();
private void button1_Click(object sender, EventArgs e)
{
try
{
IntPtr myHandle = ORCreateHive2();
}
catch (Exception r)
{
MessageBox.Show(r.ToString());
}
}
}
}
我已经能够创建过去使用 user32.dll、icmp.dll 等指针没有问题。但是,我在使用 offreg.dll 时却没有这样的运气。
谢谢。
I am trying to create an offline registry in memory using the offreg.dll provided in the windows ddk 7 package.
You can find out more information on the offreg.dll here:
MSDN
Currently, while attempted to create the hive using ORCreateHive, I receive the following error:
"Managed Debugging Assistant 'PInvokeStackImbalance' has detected a problem. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."
Here is the offreg.h file containing ORCreateHive:
typedef PVOID ORHKEY;
typedef ORHKEY *PORHKEY;
VOID
ORAPI
ORGetVersion(
__out PDWORD pdwMajorVersion,
__out PDWORD pdwMinorVersion
);
DWORD
ORAPI
OROpenHive (
__in PCWSTR lpHivePath,
__out PORHKEY phkResult
);
DWORD
ORAPI
ORCreateHive (
__out PORHKEY phkResult
);
DWORD
ORAPI
ORCloseHive (
__in ORHKEY Handle
);
The following is my C# code attempting to call the .dll and create the pointer for future use.
using System.Runtime.InteropServices;
namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("offreg.dll", CharSet = CharSet.Auto, EntryPoint = "ORCreateHive", SetLastError=true, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr ORCreateHive2();
private void button1_Click(object sender, EventArgs e)
{
try
{
IntPtr myHandle = ORCreateHive2();
}
catch (Exception r)
{
MessageBox.Show(r.ToString());
}
}
}
}
I have been able to create pointers in the past with no issue utilizing user32.dll, icmp.dll, etc. However, I am having no such luck with offreg.dll.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在托管签名中添加一个参数以匹配本机签名。
另外,考虑到密钥作为输出参数返回,您的代码应如下所示
You need to add a parameter in your managed signature to match the native one.
Also given that the key is returned as an out parameter, your code should read as follows
将其更改为
Change it to