Home All Groups Group Topic Archive Search About

Get UNICODE folder name using CDO

Author
12 Jun 2009 1:02 AM
David Marcil

I'm extracting information from Exchange using CDO in C++.  Everything works
fine except when I encounter a UNICODE folder name (I've changed my program
to support UNICODE). When I make the call to get the name with the
following, it seems to return the ANSI name.

CString strFolderName = pFolder->GetName().bstrVal;

I found a chart on CDOLive that talks about the MAPI properties (here is a
snippet)

Type    Decimal    Constant                 Hex ID   Accessible Description
         Value                                       with CDO

vbString    8    PT_TSTRING or               001E    Read/Write ANSI String
                 PT_STRING8

At the end of the chart it says "To access most of the string properties in
the Unicode format it is necessary to change the property type from 001E to
001F."

Does anyone know how I can pull the UNICODE string?

Thanks, David
Author
12 Jun 2009 11:56 AM
David Lowndes
>I'm extracting information from Exchange using CDO in C++.  Everything works
>fine except when I encounter a UNICODE folder name (I've changed my program
>to support UNICODE). When I make the call to get the name with the
>following, it seems to return the ANSI name.
>
>CString strFolderName = pFolder->GetName().bstrVal;

Do you have a Unicode application (such that CString is actually
CStringW rather than CStringA)?

Dave
Are all your drivers up to date? click for free checkup

Author
12 Jun 2009 1:00 PM
David Marcil
Yes, I have changed my program to _UNICODE.  I write out the information to
files and it is creating and writing a UNICODE file.

I was using OutlookSpy and noticed that when I look at CDO folder, the name
is ANSI but when I look at the OOM object folder it is UNICDOE.


On 12/06/09 7:56 AM, in article 0ig4359fe3pp8mv9cck4vrgf0htqsj5***@4ax.com,
Show quoteHide quote
"David Lowndes" <DavidL@example.invalid> wrote:

>> I'm extracting information from Exchange using CDO in C++.  Everything works
>> fine except when I encounter a UNICODE folder name (I've changed my program
>> to support UNICODE). When I make the call to get the name with the
>> following, it seems to return the ANSI name.
>>
>> CString strFolderName = pFolder->GetName().bstrVal;
>
> Do you have a Unicode application (such that CString is actually
> CStringW rather than CStringA)?
>
> Dave
Author
12 Jun 2009 4:29 PM
David Lowndes
>Yes, I have changed my program to _UNICODE.  I write out the information to
>files and it is creating and writing a UNICODE file.
>
>I was using OutlookSpy and noticed that when I look at CDO folder, the name
>is ANSI but when I look at the OOM object folder it is UNICDOE.

So, you're saying that even with a Unicode application you have a
problem?
Or, by switching to a Unicode build it's resolved the problem?

Dave
Author
14 Jun 2009 1:34 PM
David Marcil
I am saying that even with the application supporting and compiled for
UNICODE, I am getting back the ANSI representation of the folder name from
CDO.


On 12/06/09 12:29 PM, in article ih0535tum8v7181gk1lna3ge3cpnbh1***@4ax.com,
Show quoteHide quote
"David Lowndes" <DavidL@example.invalid> wrote:

>> Yes, I have changed my program to _UNICODE.  I write out the information to
>> files and it is creating and writing a UNICODE file.
>>
>> I was using OutlookSpy and noticed that when I look at CDO folder, the name
>> is ANSI but when I look at the OOM object folder it is UNICDOE.
>
> So, you're saying that even with a Unicode application you have a
> problem?
> Or, by switching to a Unicode build it's resolved the problem?
>
> Dave
Author
14 Jun 2009 6:42 PM
David Lowndes
>I am saying that even with the application supporting and compiled for
>UNICODE, I am getting back the ANSI representation of the folder name from
>CDO.

OK, then I don't know why. From the line of code you showed and the
fact you have a Unicode build, both the CString and bstrVal would be
Unicode so there should be no loss of information.

Dave
Author
15 Jun 2009 4:41 PM
David Marcil
I'm still not getting a UNICODE string from the calls.  I have tried the
following...

strFolderName = pFolder->GetName().bstrVal;

pFields = pFolder->GetFields() ;
pField = pFields->GetItem( _variant_t( (long)PR_DISPLAY_NAME_W ) );
strUnicodeFolderName = (LPCSTR)(_bstr_t)pField->GetValue().bstrVal;

Both are returning the same strings.  In Visual Studio 6.0 when I step thru
the code I get

CDOFolder::GetName returned {"????1" VT_BSTR}
Field::GetValue returned {"????1" VT_BSTR}
Author
15 Jun 2009 5:19 PM
David Lowndes
>I'm still not getting a UNICODE string from the calls.  I have tried the
>following...
>
>strFolderName = pFolder->GetName().bstrVal;
>
>pFields = pFolder->GetFields() ;
>pField = pFields->GetItem( _variant_t( (long)PR_DISPLAY_NAME_W ) );
>strUnicodeFolderName = (LPCSTR)(_bstr_t)pField->GetValue().bstrVal;

Well the last line is definitely wrong as you're casting things to be
ANSI (MBCS) strings rather than Unicode - get rid of the casts.

>Both are returning the same strings.  In Visual Studio 6.0 when I step thru
>the code I get
>
>CDOFolder::GetName returned {"????1" VT_BSTR}
>Field::GetValue returned {"????1" VT_BSTR}

Ah, IIRC VC6 had an option somewhere that you had to set for the
debugger to display Unicode strings - have you set that?

Dave
Author
15 Jun 2009 8:00 PM
David Marcil
I was playing with the casting.  Previously I did not cast it at all.

I have set the debugger to show Unicode.  I see the string, my issue is that
CDO is returning "????1" as the string (BSTR) for a Japanese folder name.  I
first thought it was the conversion of the BSTR to the Cstring but that is
not the case.  I have tried everything I can find but the problem is with
CDO returning an ANSI string instead of a Unicode string.


On 15/06/09 1:19 PM, in article 6g0d35dji8v007tcqifb0pnarabkv2d***@4ax.com,
Show quoteHide quote
"David Lowndes" <DavidL@example.invalid> wrote:

>> I'm still not getting a UNICODE string from the calls.  I have tried the
>> following...
>>
>> strFolderName = pFolder->GetName().bstrVal;
>>
>> pFields = pFolder->GetFields() ;
>> pField = pFields->GetItem( _variant_t( (long)PR_DISPLAY_NAME_W ) );
>> strUnicodeFolderName = (LPCSTR)(_bstr_t)pField->GetValue().bstrVal;
>
> Well the last line is definitely wrong as you're casting things to be
> ANSI (MBCS) strings rather than Unicode - get rid of the casts.
>
>> Both are returning the same strings.  In Visual Studio 6.0 when I step thru
>> the code I get
>>
>> CDOFolder::GetName returned {"????1" VT_BSTR}
>> Field::GetValue returned {"????1" VT_BSTR}
>
> Ah, IIRC VC6 had an option somewhere that you had to set for the
> debugger to display Unicode strings - have you set that?
>
> Dave
Author
15 Jun 2009 9:09 PM
SvenC
Hi David,

> Yes, I have changed my program to _UNICODE.  I write out the information
> to
> files and it is creating and writing a UNICODE file.

try defining _UNICODE and UNICODE and do a full rebuild

> I was using OutlookSpy and noticed that when I look at CDO folder, the
> name
> is ANSI but when I look at the OOM object folder it is UNICDOE.

Which CDO version do you use? How did you create the C++ wrapper?

>>> CString strFolderName = pFolder->GetName().bstrVal;

What is the function signature of GetName()?

> pFields = pFolder->GetFields() ;
> pField = pFields->GetItem( _variant_t( (long)PR_DISPLAY_NAME_W ) );
> strUnicodeFolderName = (LPCSTR)(_bstr_t)pField->GetValue().bstrVal;

Did the last line compile? If your project is really a Unicode build you
should
never be able to assign an LPCSTR to a CString.

--
SvenC
Author
16 Jun 2009 2:49 AM
David Marcil
I added the UNICODE to the preprocessor definitions (it already had
_UNICODE)...it made no difference.

I am using CDO 1.21.  The program is written in C++ in Visual Studio 6.  I
include the CDO with the following in the header.

#import "Cdo.dll" no_namespace rename("Folder", "CDOFolder")
rename("GetMessage", "CDOGetMessage")

This is the function signature for the GetName on the folder from the
cdo.tlh file.

#pragma implementation_key(114)
inline _variant_t CDOFolder::GetName ( ) {
    VARIANT _result;
    _com_dispatch_propget(this, 0x17, VT_VARIANT, (void*)&_result);
    return _variant_t(_result, false);
}

I casted the Cstring in my many trials and tribulations.  It compiled but I
removed it.  VS 6.0 is telling me the BSTR returned is "????1" for a
Japanese folder name.  I don't understand why even when I request the
PR_DISPLAY_NAME_W I still get the ANSI folder name (I assume it is ANSI).
Another interesting thing is that when I look at the Folder with the CDO in
OutlookSpy, it also has a name of ????1 instead of the Japanese characters.
The OOM folder in OutlookSpy show the name as Japanese chars.

Thanks, David


On 15/06/09 5:09 PM, in article e90JW2f7JHA.5***@TK2MSFTNGP04.phx.gbl,
Show quoteHide quote
"SvenC" <SvenC@nospam.nospam> wrote:

> Hi David,
>
>> Yes, I have changed my program to _UNICODE.  I write out the information
>> to
>> files and it is creating and writing a UNICODE file.
>
> try defining _UNICODE and UNICODE and do a full rebuild
>
>> I was using OutlookSpy and noticed that when I look at CDO folder, the
>> name
>> is ANSI but when I look at the OOM object folder it is UNICDOE.
>
> Which CDO version do you use? How did you create the C++ wrapper?
>
>>>> CString strFolderName = pFolder->GetName().bstrVal;
>
> What is the function signature of GetName()?
>
>> pFields = pFolder->GetFields() ;
>> pField = pFields->GetItem( _variant_t( (long)PR_DISPLAY_NAME_W ) );
>> strUnicodeFolderName = (LPCSTR)(_bstr_t)pField->GetValue().bstrVal;
>
> Did the last line compile? If your project is really a Unicode build you
> should
> never be able to assign an LPCSTR to a CString.
>
> --
> SvenC
>
Author
16 Jun 2009 6:46 AM
SvenC
Hi David,

> I casted the Cstring in my many trials and tribulations.  It compiled but
> I
> removed it.  VS 6.0 is telling me the BSTR returned is "????1" for a
> Japanese folder name.  I don't understand why even when I request the
> PR_DISPLAY_NAME_W I still get the ANSI folder name (I assume it is ANSI).
> Another interesting thing is that when I look at the Folder with the CDO
> in
> OutlookSpy, it also has a name of ????1 instead of the Japanese
> characters.
> The OOM folder in OutlookSpy show the name as Japanese chars.

Could it be that the debugger and OutlookSpy use a font which simply
does not contain the Japanese characters?
Try to save the string into a Unicode text file and open it in notepad or
Word.
You might need to add a BOM (byte order mark) od FF FE at the beginning
of that file to indicate that it is a Unicode file.

--
SvenC
Author
16 Jun 2009 1:43 PM
David Marcil
The application writes out the email into a file.  I've already check to see
if it was just a debugger issue (unfortunately it isn't).  Do I need to do
anything with the SetLocaleIDs before I log in so that CDO knows to return
Unicode?


On 16/06/09 2:46 AM, in article uyEPp4k7JHA.4***@TK2MSFTNGP04.phx.gbl,
Show quoteHide quote
"SvenC" <SvenC@nospam.nospam> wrote:

> Hi David,
>
>> I casted the Cstring in my many trials and tribulations.  It compiled but
>> I
>> removed it.  VS 6.0 is telling me the BSTR returned is "????1" for a
>> Japanese folder name.  I don't understand why even when I request the
>> PR_DISPLAY_NAME_W I still get the ANSI folder name (I assume it is ANSI).
>> Another interesting thing is that when I look at the Folder with the CDO
>> in
>> OutlookSpy, it also has a name of ????1 instead of the Japanese
>> characters.
>> The OOM folder in OutlookSpy show the name as Japanese chars.
>
> Could it be that the debugger and OutlookSpy use a font which simply
> does not contain the Japanese characters?
> Try to save the string into a Unicode text file and open it in notepad or
> Word.
> You might need to add a BOM (byte order mark) od FF FE at the beginning
> of that file to indicate that it is a Unicode file.
>
> --
> SvenC
>
Author
16 Jun 2009 2:48 PM
SvenC
Hi David,

> The application writes out the email into a file.  I've already check to
> see
> if it was just a debugger issue (unfortunately it isn't).  Do I need to do
> anything with the SetLocaleIDs before I log in so that CDO knows to return
> Unicode?

Strange. What kind of store does the folder live in? Is it an Exchange
mailbox or a pst file? What do you see when you use MfcMapi to
view the folder?

--
SvenC
Author
16 Jun 2009 4:21 PM
David Marcil
The folder was originally in a PST file (Unicode) and I copied it to a
mailbox.  I have tried both from the mailbox and from the PST file.  I have
another PST (97-2002 version) that has a folder that will extract the
characters but that is because it was not in Unicode (I assume).

When I open the mailbox with MFCMapi, I get the same ????1 for the folder
name instead of "?$B%U%)%k%@#1?(B"


On 16/06/09 10:48 AM, in article O5MG5Fp7JHA.4***@TK2MSFTNGP06.phx.gbl,
Show quoteHide quote
"SvenC" <SvenC@nospam.nospam> wrote:

> Hi David,
>
>> The application writes out the email into a file.  I've already check to
>> see
>> if it was just a debugger issue (unfortunately it isn't).  Do I need to do
>> anything with the SetLocaleIDs before I log in so that CDO knows to return
>> Unicode?
>
> Strange. What kind of store does the folder live in? Is it an Exchange
> mailbox or a pst file? What do you see when you use MfcMapi to
> view the folder?
>
> --
> SvenC
>
Author
16 Jun 2009 8:21 PM
SvenC
> The folder was originally in a PST file (Unicode) and I copied it to a
> mailbox.

Outlook and OWA show the correct name in their UI, I assume?
Can you create a brand new folder from Outlook with a Unicode
name and see what CDO and MfcMapi return for that?

> When I open the mailbox with MFCMapi, I get the same ????1 for the folder
> name instead of "?$B%U%)%k%@#1?(B"

When you look at the properties of the folder, do you see
PR_DISPLAY_NAME as PT_STRING8 or PT_UNICODE?

--
SvenC
Author
16 Jun 2009 11:56 PM
David Marcil
I thought of that as well.  I created another folder using the Outlook
client with a Unicode name and looked at it with MfcMapi and my program
(CDO) and still do not see Unicode.  PR_DISPLAY_NAME shows as a PT_STRING8.
I do not see any PT_UNICODE properties when I look thru things.  When I look
at it with the Outlook client the name is Unicode.  The server is Exchange
2003.

Does anyone else see ANSI names for Unicode folders when looking at MfcMapi?


On 16/06/09 4:21 PM, in article ug7yJAs7JHA.1***@TK2MSFTNGP04.phx.gbl,
Show quoteHide quote
"SvenC" <SvenC@nospam.nospam> wrote:

>> The folder was originally in a PST file (Unicode) and I copied it to a
>> mailbox.
>
> Outlook and OWA show the correct name in their UI, I assume?
> Can you create a brand new folder from Outlook with a Unicode
> name and see what CDO and MfcMapi return for that?
>
>> When I open the mailbox with MFCMapi, I get the same ????1 for the folder
>> name instead of "?$B%U%)%k%@#1?(B"
>
> When you look at the properties of the folder, do you see
> PR_DISPLAY_NAME as PT_STRING8 or PT_UNICODE?
>
> --
> SvenC
Author
19 Jun 2009 3:06 PM
David Marcil
I have not seen anything posted for my question.  If someone creates a
unicode folder, what do they see with MfcMapi?  I get PT_STRING8 and not
PT_UNICODE and the returned value is not the unicode value.


On 16/06/09 7:56 PM, in article
C65DA95A.87FE%dmarcil@nospam.newsguy.com.invalid, "David Marcil"
<dmarcil@nospam.newsguy.com.invalid> wrote:

Show quoteHide quote
> I thought of that as well.  I created another folder using the Outlook
> client with a Unicode name and looked at it with MfcMapi and my program
> (CDO) and still do not see Unicode.  PR_DISPLAY_NAME shows as a PT_STRING8.
> I do not see any PT_UNICODE properties when I look thru things.  When I look
> at it with the Outlook client the name is Unicode.  The server is Exchange
> 2003.
>
> Does anyone else see ANSI names for Unicode folders when looking at MfcMapi?
>
>
> On 16/06/09 4:21 PM, in article ug7yJAs7JHA.1***@TK2MSFTNGP04.phx.gbl,
> "SvenC" <SvenC@nospam.nospam> wrote:
>
>>> The folder was originally in a PST file (Unicode) and I copied it to a
>>> mailbox.
>>
>> Outlook and OWA show the correct name in their UI, I assume?
>> Can you create a brand new folder from Outlook with a Unicode
>> name and see what CDO and MfcMapi return for that?
>>
>>> When I open the mailbox with MFCMapi, I get the same ????1 for the folder
>>> name instead of "?$B%U%)%k%@#1?(B"
>>
>> When you look at the properties of the folder, do you see
>> PR_DISPLAY_NAME as PT_STRING8 or PT_UNICODE?
>>
>> --
>> SvenC
>
Author
29 Jun 2009 12:26 PM
David Marcil
I still have not found a solution.  Does anyone have anything to add or try?


On 19/06/09 11:06 AM, in article
C66121CC.8CC2%david.mar***@gryphonobject.com, "David Marcil"
<david.mar***@gryphonobject.com> wrote:

Show quoteHide quote
> I have not seen anything posted for my question.  If someone creates a
> unicode folder, what do they see with MfcMapi?  I get PT_STRING8 and not
> PT_UNICODE and the returned value is not the unicode value.
>
>
> On 16/06/09 7:56 PM, in article
> C65DA95A.87FE%dmarcil@nospam.newsguy.com.invalid, "David Marcil"
> <dmarcil@nospam.newsguy.com.invalid> wrote:
>
>> I thought of that as well.  I created another folder using the Outlook
>> client with a Unicode name and looked at it with MfcMapi and my program
>> (CDO) and still do not see Unicode.  PR_DISPLAY_NAME shows as a PT_STRING8.
>> I do not see any PT_UNICODE properties when I look thru things.  When I look
>> at it with the Outlook client the name is Unicode.  The server is Exchange
>> 2003.
>>
>> Does anyone else see ANSI names for Unicode folders when looking at MfcMapi?
>>
>>
>> On 16/06/09 4:21 PM, in article ug7yJAs7JHA.1***@TK2MSFTNGP04.phx.gbl,
>> "SvenC" <SvenC@nospam.nospam> wrote:
>>
>>>> The folder was originally in a PST file (Unicode) and I copied it to a
>>>> mailbox.
>>>
>>> Outlook and OWA show the correct name in their UI, I assume?
>>> Can you create a brand new folder from Outlook with a Unicode
>>> name and see what CDO and MfcMapi return for that?
>>>
>>>> When I open the mailbox with MFCMapi, I get the same ????1 for the folder
>>>> name instead of "?$B%U%)%k%@#1?(B"
>>>
>>> When you look at the properties of the folder, do you see
>>> PR_DISPLAY_NAME as PT_STRING8 or PT_UNICODE?
>>>
>>> --
>>> SvenC
>>
>
Author
29 Jun 2009 1:01 PM
SvenC
Hi David,

> I still have not found a solution.  Does anyone have anything to add or
> try?

You can tell OutlookSpy to always ask for Unicode props. Use
Outlook->Tools->Options -> Outlook Spy -> More options ->
Unicode : Use MAPI_UNICODE.

After you checked that option. Open IMAPIFolder from the OutlookSpy
toolbar and check what PR_DISPLAY_NAME prop you get. In that case
I see PT_UNICODE.

Maybe CDO prevents something. You might need to use the
MAPIOBJECT property to get an IUnknown of the folder and
use that to QueryInterface for IMAPIFolder yourself and use
GetProps on that interface.

--
SvenC

Bookmark and Share