Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7681207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T18:17:22+00:00 2026-05-31T18:17:22+00:00

After getting a struct from C# to C++ using C++/CLI: public value struct SampleObject

  • 0

After getting a struct from C# to C++ using C++/CLI:

public value struct SampleObject
{   
    LPWSTR a;    
};

I want to print its instance:

printf(sampleObject->a);

but I got this error:

Error 1 error C2664: ‘printf’ : cannot convert parameter 1 from
‘LPWSTR’ to ‘const char *’

How can I convert from LPWSTR to char*?

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T18:17:23+00:00Added an answer on May 31, 2026 at 6:17 pm

    Don’t convert.

    Use wprintf instead of printf:

    • wprintf

    See the examples which explains how to use it.

    Alternatively, you can use std::wcout as:

    wchar_t *wstr1= L"string";
    LPWSTR   wstr2= L"string"; //same as above
    std::wcout << wstr1 << L", " << wstr2;
    

    Similarly, use functions which are designed for wide-char, and forget the idea of converting wchar_t to char, as it may loss data.

    Have a look at the functions which deal with wide-char here:

    • Unicode in Visual C++
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The below textbox is printing the value of the phone number after getting it
After getting a helpful answer here , I have run into yet another problem:
In the below code how to remove the hyperlink after getting the innerHTML :
Update: Ok, after getting past the fact that I did not have MSDTC set
I have designed one sign-up form,in this form after getting all necessary values I
I recently started reading about ASP.net MVC and after getting excited about the concept,
I'm trying to implement ZXing barcode scanner into my program. After getting the scanned
After reading Getting Good With Git, I've learnt how to use Git, but not
I have a following structered DOM result, getting after a POST event: <root> <config>
Our team is currently using some ported code from an old architecture to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.