After adding the newline control character, the string will look like
"testtesttest abcabc" on the right side.
I can input this style by hand, but when I am using "\r\n" in my C++
code, I can't force the string to add a newline format. The result
will look like "testtesttestabcabc" on the right side.
I don't know why. Am I wrong?
What do you mean by "on the right side" ?
If you double-click on a REG_MULTI_SZ string, it will be displayed correctly
on the multiline control of Regedit.
Actually, I am using the Registry way to replace files while I reboot
my Windows.
-----------
http://support.microsoft.com/kb/181345
-----------
The article said that we need to write the two file path on two lines.
If I write these two file paths on two line with a newline break, my
windows will replace the files while it reboots.
But if I write C++ code to replace files in Registry way, even if I
use "\r\n" to combine these two paths, I still can't get the files
replaced while my computer reboots.
I don't know why......
Actually, I am using the Registry way to replace files while I reboot
I know the reason now. I use wstring to store my paths. But while
using API
LONG WINAPI RegSetValueEx(
__in HKEY hKey,
__in_opt LPCTSTR lpValueName,
__reserved DWORD Reserved,
__in DWORD dwType,
__in_opt const BYTE *lpData,
__in DWORD cbData
);
While I pass my firth parameter, I use following line to change
wstring to const BYTE *
(LPBYTE)value_data.c_str()
So RegSetValueEx automatically convert my BYTE * to wstring again.
What's the right way to convert wstring to BYTE * ?
I know the reason now. I use wstring to store my paths. But while
I think I find the reason, the registry will convert the newline to
unicode NULL. But I still use \r\n in my code. This is the gap.
I use memcpy to convert wstring to BYTE*, is there a better solution?
>On Aug 27, 3:45�pm, Water Lin <water...@ymail.com> wrote:
>> On Aug 27, 2:49�pm, "jerome" <j...@st.com> wrote:
>>
>>
>>
>> > "Water Lin" <water...@ymail.com> a �crit dans le message de news:
I may be able to help if you show a little code. At least the variable
declarations, actual call to RegValueSetEx, string conversions, and
code that shows you the result.
>
>So RegSetValueEx automatically convert my BYTE * to wstring again.
>
>What's the right way to convert wstring to BYTE * ?
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
Useful reading (be sure to read its disclaimer first):
http://catb.org/~esr/faqs/smart-questions.html
Why are you adding newlines? Don't do that, the article doesn't
mention them for a reason.
Check out REG_MULTI_SZ,
http://msdn.microsoft.com/en-us/library/ms724884(VS.85).aspx
The values are separated by null characters and terminated by an empty
string.
--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
An old friend of mine once quoted me an ancient Egyptian blessing:
'God be between you and harm in all the empty places where you must
walk.' -- Sheridan in Babylon 5:"A Distant Star"
|Actually, I am using the Registry way to replace files while I reboot
|my Windows.
|-----------
|http://support.microsoft.com/kb/181345
|-----------
|
|The article said that we need to write the two file path on two lines.
The article does not say to add newlines. It says the REG_MULTI_SZ will
***appear*** on two lines in RegEdit (because that's how RegEdit shows
REG_MULTI_SZs). You need to construct lpData that looks like this:
file1\0file2\0\0 (a REG_MULTI_SZ containing two strings)
Try something like this (there are many other ways):
// room for two file names
WCHAR szValue[2 * MAX_PATH];
// use appropriate strings here:
WCHAR szFile1[MAX_PATH] = L"file1",
szFile2[MAX_PATH] = L"file2";
WCHAR *p = szValue;
DWORD dwValueSize = 0;
// write string1
p += wsprintf(p, L"%s", szFile1);
// get past the terminating NUL
p += 1;
// write string2
p += wsprintf(p, L"%s", szFile2);
// write an extra NUL
*++p = 0;
dwValueSize = (p - szValue + 1) * sizeof(WCHAR);
In the example, dwDataSize will be 26 (bytes, 13 WCHARs). szValue will be
correct for a REG_MULTI_SZ:
file1\0file2\0\0
Now RegSetValueEx(hKey, szName, 0, REG_MULTI_SZ, (BYTE*) szValue, dwValueSize);
--
- Vince
By the way, there is another question from me.
If I have a lot of files I need to replace while the system reboot, in
this case I will have a very long REG_MULTI_SZ type variable.
I don't think this is a good idea to store my file list into Registry
directly. I have no idea how long the list will be.
So, here is my question, can I store the info( like REG_MULTI_SZ) in a
file and put the file path in Registry? So when I reboot the system,
the replacement will carry out according to this file.
On Aug 27, 10:04 pm, "Scott Seligman" <selig...@example.com> wrote:
> Water Lin <water...@ymail.com> wrote:
> >http://support.microsoft.com/kb/181345
>
> >But if I write C++ code to replace files in Registry way, even if I
> >use "\r\n" to combine these two paths, I still can't get the files
> >replaced while my computer reboots.
>
> Why are you adding newlines? Don't do that, the article doesn't
> mention them for a reason.
>
> Check out REG_MULTI_SZ,http://msdn.microsoft.com/en-us/library/ms724884(VS.85).aspx