none
cannot convert parameter 4 from 'const char *' to 'LPCWSTR'_

    Question

  • I get this error:
    cannot convert parameter 4 from 'const char *' to 'LPCWSTR' 

    when I do:

     

    if ( (semaphore = CreateSemaphore(sa,initialCount,maximumCount,sName.c_str())) == NULL)
    {


    }

    sName is passed into this function as :

    string& sName

    How can I solve this?


    Thanks

    Friday, September 25, 2009 1:40 PM

Answers

  • Try with

    wstring& sName
    Friday, September 25, 2009 1:48 PM
  • LearnerMan1234 wrote:
    > I changed my project settings to Use Multibyte Character Set and all is ok.
    >
    > Thanks for your reply.

    Yes, this will work, but not recommended for new coding. The native character
    set of Windows NT4/2000/XP/Vista/7... is 16-bit Unicode. There is usually no
    reason to use 8-bit strings in modern Windows coding.

    David Wilkinson | Visual C++ MVP
    Friday, September 25, 2009 3:54 PM
  • Hello Harry

    The best practice is to either change string& sName to wstring& sName as Belloc suggested, or, if sName has to be declared as string&, call MultiByteToWideChar upon your sName.c_str() to convert the ansi string to Unicode, and pass the Unicode to the CreateSemaphore API.

    Have a nice day!

    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 28, 2009 6:24 AM
    Moderator

All replies

  • Try with

    wstring& sName
    Friday, September 25, 2009 1:48 PM
  • I changed my project settings to Use Multibyte Character Set and all is ok.

    Thanks for your reply.

    Harry
    Friday, September 25, 2009 2:28 PM
  • LearnerMan1234 wrote:
    > I changed my project settings to Use Multibyte Character Set and all is ok.
    >
    > Thanks for your reply.

    Yes, this will work, but not recommended for new coding. The native character
    set of Windows NT4/2000/XP/Vista/7... is 16-bit Unicode. There is usually no
    reason to use 8-bit strings in modern Windows coding.

    David Wilkinson | Visual C++ MVP
    Friday, September 25, 2009 3:54 PM
  • Hello Harry

    The best practice is to either change string& sName to wstring& sName as Belloc suggested, or, if sName has to be declared as string&, call MultiByteToWideChar upon your sName.c_str() to convert the ansi string to Unicode, and pass the Unicode to the CreateSemaphore API.

    Have a nice day!

    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 28, 2009 6:24 AM
    Moderator