PInvokeStackImbalance ——带有 offreg.dll 的 C# (windows ddk7)

发布于 2024-08-26 06:32:23 字数 1700 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独患者 2024-09-02 06:32:23

您需要在托管签名中添加一个参数以匹配本机签名。

[DllImport("offreg.dll", CharSet = CharSet.Auto, EntryPoint = "ORCreateHive", SetLastError=true, CallingConvention = CallingConvention.StdCall)]
public static extern uint ORCreateHive2(out IntPtr notUsed);

另外,考虑到密钥作为输出参数返回,您的代码应如下所示

IntPtr myHandle;
uint ret = ORCreateHive2(out myHandle);
if ( ret == 0 ) { 
  return myHandle;
} else {
  // Error ...
}

You need to add a parameter in your managed signature to match the native one.

[DllImport("offreg.dll", CharSet = CharSet.Auto, EntryPoint = "ORCreateHive", SetLastError=true, CallingConvention = CallingConvention.StdCall)]
public static extern uint ORCreateHive2(out IntPtr notUsed);

Also given that the key is returned as an out parameter, your code should read as follows

IntPtr myHandle;
uint ret = ORCreateHive2(out myHandle);
if ( ret == 0 ) { 
  return myHandle;
} else {
  // Error ...
}
旧伤慢歌 2024-09-02 06:32:23

将其更改为

extern int ORCreateHive (out IntPtr phkResult);

Change it to

extern int ORCreateHive (out IntPtr phkResult);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文