getting info from Active Directory

W

WIWA

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
 
H

Howard

WIWA said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top