RegLoadMUIString Vista P-Invoke [英] RegLoadMUIString Vista P-Invoke

查看:147
本文介绍了RegLoadMUIString Vista P-Invoke的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我正试图以显示友好的

格式从注册表中获取MUI字符串。从我读过的,字符串格式如下:

a ?? @ [path] \dllname,-strIDa ??是MUI字符串并通过RegLoadMUIString API调用接收特殊处理。


这就是我提出来的电话:

[DllImport(" advapi32.dll")]

内部静态extern long RegLoadMUIString(IntPtr hKey,string pszValue,

StringBuilder pszOutBuf,int cbOutBuf,out int pcbData,uint标志,字符串

pszDirectory);


我正在使用指向打开的注册表项的有效指针调用此函数,

传入适当的值键(pszValue),其中MUI格式为

字符串。当我检查输出缓冲区(pszOutBuf)时,它总是一个空的

字符串。


有没有人能够让这个电话工作?我在网上找不到任何例子




谢谢,

-bp

Hello,
I''m trying to get an MUI string out of the registry in display friendly
format. From what I''ve read, strings in the following format:
a??@[path]\dllname,-strIDa?? are MUI strings and receive special handling via
the RegLoadMUIString API call.

This is what I have come up with for the call:
[DllImport("advapi32.dll")]
internal static extern long RegLoadMUIString(IntPtr hKey, string pszValue,
StringBuilder pszOutBuf, int cbOutBuf, out int pcbData, uint Flags, string
pszDirectory);

I''m calling this function with a valid pointer to an open registry key,
passing in the appropriate value key (pszValue) which has the MUI formatted
string. When I check the output buffer (pszOutBuf) it''s always an empty
string.

Has anyone been able to get this call to work? I cannot find any examples
on the web.

thanks,
-bp

推荐答案

下面是完整的代码:

使用System;

使用System.Collections.Generic;

使用System.Text;

使用System.Runtime.InteropServices;

使用Microsoft.Win32;


namespace ConsoleApplication2

{

class program

{

[DllImport(" advapi32.dll")]

public static extern long RegOpenKeyEx(IntPtr hKey,string

lpSubKey,int ulOptions,int samDesired,out IntPtr phkResult);


[DllImport(" advapi32.dll")]

内部静态extern long RegLoadMUIString(IntPtr hKey,string

pszValue,StringBuilder pszOutBuf,int cbOutBuf,out int pcbData,uint标志,

string pszDirectory);


[DllImport(" advapi32.dll")]

public static extern int RegCl oseKey(IntPtr hKey);

static void Main(string [] args)

{

try

{

//注意:测试Vista MUI注册表字符串


//注意:指向HKEYLM的指针

IntPtr localMachine = new

IntPtr((long)unchecked((int)0x80000002));


//注意:regKey将包含指向开放注册表的指针

key

IntPtr regKey;


int pcbData = 0;


//注意:打开一个具有KEY_READ访问权限的设备密钥。

RegOpenKeyEx(localMachine,

@" SYSTEM \ CurrentControlSet \Control\Class \ {36FC9 E60-C465-11CF- 8056-444553540000}",0,0x20019,out regKey);


//注意:构建输出缓冲区引用

StringBuilder lptStr = new StringBuilder( 1024);


//注意:ClassDesc包含MUI格式的字符串

RegLoadMUIString(regKey," ClassDesc",lptStr,1024,out

pcbData,0,nu ll);


//注意:关闭钥匙

RegCloseKey(regKey);


//注意:输出值到控制台

Console.WriteLine(" Reg key:" + regKey.ToString());

Console.WriteLine(" LPTSTR:" + lptStr.ToString());

Console.WriteLine(" PCBDATA: " + pcbData.ToString());

Console.ReadLine();

}

catch(exception ex)

{

Console.WriteLine(" Exception:" + ex.Message);

Console.ReadLine();

}

}

}

}

" lissbpp"写道:
Below is full code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Microsoft.Win32;

namespace ConsoleApplication2
{
class Program
{
[DllImport("advapi32.dll")]
public static extern long RegOpenKeyEx(IntPtr hKey, string
lpSubKey,int ulOptions,int samDesired, out IntPtr phkResult);

[DllImport("advapi32.dll")]
internal static extern long RegLoadMUIString(IntPtr hKey, string
pszValue, StringBuilder pszOutBuf, int cbOutBuf, out int pcbData, uint Flags,
string pszDirectory);

[DllImport("advapi32.dll")]
public static extern int RegCloseKey(IntPtr hKey);
static void Main(string[] args)
{
try
{
//NOTE: Testing Vista MUI Registry strings

//NOTE: Pointer to HKEYLM
IntPtr localMachine = new
IntPtr((long)unchecked((int)0x80000002));

//NOTE: regKey will contain the pointer to the open registry
key
IntPtr regKey;

int pcbData = 0;

//NOTE: Open a device key with KEY_READ access rights.
RegOpenKeyEx(localMachine,
@"SYSTEM\CurrentControlSet\Control\Class\{36FC9 E60-C465-11CF-8056-444553540000}", 0, 0x20019, out regKey);

//NOTE: Build the output buffer reference
StringBuilder lptStr = new StringBuilder(1024);

//NOTE: ClassDesc contains the MUI formatted string
RegLoadMUIString(regKey, "ClassDesc", lptStr, 1024, out
pcbData, 0, null);

//NOTE: Close the key
RegCloseKey(regKey);

//NOTE: Output values to console
Console.WriteLine("Reg key : " + regKey.ToString());
Console.WriteLine("LPTSTR : " + lptStr.ToString());
Console.WriteLine("PCBDATA : " + pcbData.ToString());
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("Exception : " + ex.Message);
Console.ReadLine();
}
}
}
}
"lissbpp" wrote:

你好,

我正试图从显示器中获取MUI字符串显示友好

格式。从我读过的,字符串格式如下:

a ?? @ [path] \dllname,-strIDa ??是MUI字符串并通过RegLoadMUIString API调用接收特殊处理。


这就是我提出来的电话:

[DllImport(" advapi32.dll")]

内部静态extern long RegLoadMUIString(IntPtr hKey,string pszValue,

StringBuilder pszOutBuf,int cbOutBuf,out int pcbData,uint标志,字符串

pszDirectory);


我正在使用指向打开的注册表项的有效指针调用此函数,

传入适当的值键(pszValue),其中MUI格式为

字符串。当我检查输出缓冲区(pszOutBuf)时,它总是一个空的

字符串。


有没有人能够让这个电话工作?我在网上找不到任何例子




谢谢,

-bp
Hello,
I''m trying to get an MUI string out of the registry in display friendly
format. From what I''ve read, strings in the following format:
a??@[path]\dllname,-strIDa?? are MUI strings and receive special handling via
the RegLoadMUIString API call.

This is what I have come up with for the call:
[DllImport("advapi32.dll")]
internal static extern long RegLoadMUIString(IntPtr hKey, string pszValue,
StringBuilder pszOutBuf, int cbOutBuf, out int pcbData, uint Flags, string
pszDirectory);

I''m calling this function with a valid pointer to an open registry key,
passing in the appropriate value key (pszValue) which has the MUI formatted
string. When I check the output buffer (pszOutBuf) it''s always an empty
string.

Has anyone been able to get this call to work? I cannot find any examples
on the web.

thanks,
-bp


[DllImport(" advapi32.dll")]
[DllImport("advapi32.dll")]

public static extern long RegOpenKeyEx(IntPtr hKey,string
lpSubKey,int ulOptions,int samDesired,out IntPtr phkResult);


[DllImport(" advapi32.dll")]

内部静态extern long RegLoadMUIString (IntPtr hKey,string
pszValue,StringBuilder pszOutBuf,int cbOutBuf,out int pcbData,uint Flags,
string pszDirectory);
public static extern long RegOpenKeyEx(IntPtr hKey, string
lpSubKey,int ulOptions,int samDesired, out IntPtr phkResult);

[DllImport("advapi32.dll")]
internal static extern long RegLoadMUIString(IntPtr hKey, string
pszValue, StringBuilder pszOutBuf, int cbOutBuf, out int pcbData, uint Flags,
string pszDirectory);



两个函数的返回类型应该是int,而不是long。

Mattias


-

Mattias Sj?gren [C#MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。

The return type for both functions should be int, not long.
Mattias

--
Mattias Sj?gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


将返回类型更改为int对调用结果没有影响。


-brett


" Mattias Sj ?? gren"写道:
Changing the return types to int had no affect on the outcome of the call.

-brett

"Mattias Sj??gren" wrote:

[DllImport(" advapi32.dll")]

public static extern long RegOpenKeyEx (IntPtr hKey,string

lpSubKey,int ulOptions,int samDesired,out IntPtr phkResult);


[DllImport(" advapi32.dll")]

内部静态extern long RegLoadMUIString(IntPtr hKey,string

pszValue,StringBuilder pszOutBuf,int cbOutBuf,out int pcbData,uint Flags,

string pszDirectory );
[DllImport("advapi32.dll")]
public static extern long RegOpenKeyEx(IntPtr hKey, string
lpSubKey,int ulOptions,int samDesired, out IntPtr phkResult);

[DllImport("advapi32.dll")]
internal static extern long RegLoadMUIString(IntPtr hKey, string
pszValue, StringBuilder pszOutBuf, int cbOutBuf, out int pcbData, uint Flags,
string pszDirectory);



两个函数的返回类型应为int,不长。


Mattias


-

Mattias Sj ?? gren [C#MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。


The return type for both functions should be int, not long.
Mattias

--
Mattias Sj??gren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


这篇关于RegLoadMUIString Vista P-Invoke的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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