472,142 Members | 1,152 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,142 software developers and data experts.

getting info from Active Directory

Hello,

I have written a program that gets information from Active Directory. This
is the function I'm using:

void ADSysGetUserName(IADsADSystemInfo * pSys, char * data) {
HRESULT hr;
BSTR bstr;
hr = pSys->get_UserName(&bstr);
if (SUCCEEDED(hr)) {
sprintf((char*)data, "%S", bstr);
}
SysFreeString(bstr);
}

I call it using:

char temp[500];
ADSysGetComputerName(pSys, temp);

The problem I'm getting is that when a user's name contains special
characters (such as éèöü ...) and I'm getting it, it modifies those
characters. In the table below, you can see that Düvoçréè (just a test name)
is returned as D³voşrÜŞ. The values in the left column are the correct ASCII
values.
68 D D
252 ³ ü
118 v v
111 o o
231 ş ç
114 r r
233 Ú é
232 Ş è
I was always under the impression that a char could also handle these
special characters. Does anyone know what is wrong here? Should I use
another type. Could anyone provide me with an example?

Thanks in advance,

WiWa
Jul 22 '05 #1
1 3323

"WIWA" <wi**@yahoo.com.au> wrote in message
news:41***********************@news.skynet.be...
Hello,

I have written a program that gets information from Active Directory. This
is the function I'm using:

void ADSysGetUserName(IADsADSystemInfo * pSys, char * data) {
HRESULT hr;
BSTR bstr;
hr = pSys->get_UserName(&bstr);
if (SUCCEEDED(hr)) {
sprintf((char*)data, "%S", bstr);
}
SysFreeString(bstr);
}

I call it using:

char temp[500];
ADSysGetComputerName(pSys, temp);

The problem I'm getting is that when a user's name contains special
characters (such as ihv| ...) and I'm getting it, it modifies those
characters. In the table below, you can see that D|vogrih (just a test
name) is returned as D3vo~r\^. The values in the left column are the
correct ASCII values.
68 D D
252 3 |
118 v v
111 o o
231 ~ g
114 r r
233 Z i
232 ^ h
I was always under the impression that a char could also handle these
special characters. Does anyone know what is wrong here? Should I use
another type. Could anyone provide me with an example?

Thanks in advance,

WiWa


Are the values changing, or are they correct but your display of them as
text (using printf) is incorrect? Run it in a debugger and see whether you
get the correct values. Also,you'll probably want to use unsigned char for
whatever it is they get stored in, since you've got values that are greater
than 127. (And I have no idea what a BSTR is... nor any of that other
stuff. Looks like Microsoft-specific stuff. If you have problems specific
to Microsoft, you might want to ask in one of their newsgroups.)

-Howard
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Buddy Ackerman | last post: by
reply views Thread by Kenneth Keeley | last post: by
1 post views Thread by dhnriverside | last post: by
9 posts views Thread by =?Utf-8?B?RGVubmlz?= | last post: by
11 posts views Thread by Armin Zingler | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.