?
Solved

Convert ansi string to unicode string?

Posted on 2005-03-05
2
Medium Priority
?
1,117 Views
Last Modified: 2013-11-20
Hi,

I have a win32 console app. All I need to do is convert a command line argument to a unicode string, but it seems to always fail.
For instance:

int main(int argc, _TCHAR* argv[])
{
    // Copy argv[1] into a unicode string.
    wchar_t wcMyUnicodeString[MAX_PATH];
    MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, argv[1], (int)strlen(argv[1]), wcMyUnicodeString, MAX_PATH);

    // This prints out just fine.
    fwprintf(stdout, wcMyUnicodeString);

    // Now I want to pass it to this interface:
    pInterface->SetApplicationName(wcMyUnicodeString);
}

but it always fails at SetApplicationName()!!!!! It works just fine if I use a unicode literal such as:

SetApplicationName(L"some name");

SetApplicationName() takes a LPCWSTR as its only parameter, is this not compatible with my w_chart? I thought it would be the same as the literal string I preceded with the capital L?

Please help me.
0
Comment
Question by:minnirok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 13467494
Actually, that should work. Would

wsprintfW(wcMyUnicodeString,L"%S", argv[1]);

help?

0
 
LVL 7

Author Comment

by:minnirok
ID: 13467512
That's it!

Thanks again jkr. Once I get some free time, I'll have read up what its actual malfunction was!
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question