Please help me understand how to put a translated MUI string from RegLoadMUIString into a message box.

Hello, in the following code, a RegLoadNUIString is performed for a registry value, and I would like to know which parameter holds the translated string returned, so that I can put that value into a message box for display purposes.

Here is the code - which works - I just don't know enough to figure out what holds the returned value from the function call to RegLoadMUIString - so that I can just for the moment throw its value into a message box.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace FormTest001
    public partial class Form1 : Form
        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, EntryPoint = "RegOpenKeyExW", CallingConvention = CallingConvention.StdCall)]
        public static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey, int ulOptions, int samDesired, out UIntPtr phkResult);

        [DllImport("advapi32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, EntryPoint = "RegLoadMUIStringW", CallingConvention = CallingConvention.StdCall)]
        internal static extern int RegLoadMUIString(UIntPtr hKey, string pszValue, StringBuilder pszOutBuf, int cbOutBuf, out int pcbData, uint Flags, string pszDirectory);

        [DllImport("advapi32.dll", ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
        public static extern int RegCloseKey(UIntPtr hKey);

        public static UIntPtr HKEY_LOCAL_MACHINE = new UIntPtr(0x80000002u);
        public static UIntPtr HKEY_CURRENT_USER = new UIntPtr(0x80000001u);
        public const int READKEY = 131097;

        public Form1()

        private void Form1_Load(object sender, EventArgs e)


        private void button1_Click(object sender, EventArgs e)
            const int BUFFSIZE = 1024;
            UIntPtr key;
            StringBuilder buffer = new StringBuilder(1024);
            int pcbData;

            long result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, @"SYSTEM\CurrentControlSet\Control\Class\{36FC9E60-C465-11CF-8056-444553540000}", 0, READKEY, out key);
            result = RegLoadMUIString(key, "ClassDesc", buffer, BUFFSIZE, out pcbData, 0, null);

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Miguel OzSoftware EngineerCommented:
In your case, the variable buffer (pszOutBuf parameter) will contain the translated string.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robert_e_boneAuthor Commented:
I put in the following code to display that value:

            MessageBox.Show("MUI Value = " + pszOutBuf, "Error",
            MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

And get the following error: The name 'pszOutBuf' does not exist in the current context.
robert_e_boneAuthor Commented:
OK - your comment indicated the field as it is listed in the parameters from the declaration for RegLoadMUIString, and for the code I provided, in the actual call down in my button click code, the corresponding field is called buffer.

It works like a champ with that adjustment - thanks!

Robert Bone
robert_e_boneAuthor Commented:
Thanks SOOOOO much - I am off to flesh this out into the real code needed, based on the solution provided.

A VERY happy newbie - Robert Bone
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.