Member Avatar for kisky84

Hi all!

I'm trying to implement a small program to test an API I've been provided, and since it's my first approach to C++ under Windows, I could use some help.

I have this type definition:

typedef struct
{
    const WCHAR* streetAddress;
    const WCHAR* city;
    const WCHAR* state;
    const WCHAR* country;
    const WCHAR* postalCode;
} QueSelectAddressType

So, now, I want to create a variable of this type and fill in the different fields. If I try

QueSelectAddressType address;

address.streetAddress = "Albareda 23";
...

VC++ complains because left part is WCHAR* and right one is char*. If I cast it:

address.streetAddress = (WCHAR*) "Albareda 23";

VC++ doesn't complain, but it doesn't work later when I pass it to a function which requires this type of parameter.


Googling for a solution, I've read something about mbtowc() and mbstowcs() , but I don't really get how to use them, so if any of you can help me... thanks in advance.

you can not typecase char* to wchar_t* because wchar_t is a different data type, under MS-Windows its a short, but under *nix its a long integer.

For string literals there is a macro in tchar.h address.streetAddress = _TEXT("Albareda 23");

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.