Posted on 2005-05-03
Last Modified: 2007-11-27
I am having trouble with this. I have searched the other forums, and they have provided me with no help. I was wondering can someone help me, and explain to me how to get this working say using a GUI?

Here's what I have so far:
LPBYTE msg = msgTxbx->Text;
DWORD buflen = 512;
LPCWSTR from = fromTxbx->Text;
LPCWSTR to = toTxbx->Text;
nas = NetMessageBufferSend(sName,      //make server name global

right off the bat I know my LPCWSTR is wrong, I am a very confused on the whole convert thing. I think that is what I need to have explain to me the most.
Question by:fsharer
    LVL 16

    Expert Comment

    'sName', 'to' and 'from' must be wide character strings (Unicode).

    First of all you did not post what are 'msgTxbx' and 'fromTxbx'.
    But I presume that the 'Text' member is just a char string so you need to do a conversion from the multibyte to wide character string using mbstowcs (

    LPCWSTR from, to, sName;

    mbstowcs(from, fromTxBx->Text, strlen(fromTxbx->Text);

    Author Comment

    Sorry, msgTxbx, and fromTxbx, are just message boxes on the GUI. Thanks for the help!

    Author Comment

    I tried the mbstowcs but it gave me these compile errors

    LPCWSTR from;
    mbstowcs(from, fromTxBx->Text, strlen(fromTxbx->Text);

     error C2664: 'mbstowcs' : cannot convert parameter 1 from 'AnonymousSend::LPCWSTR' to 'wchar_t *'
     Conversion loses qualifiers
     error C2664: 'strlen' : cannot convert parameter 1 from 'System::String __gc *' to 'const char *'

    I really dont understand this whole converting issue. can someone send me to a site, or point me to a book, or explain how to do this conversion? Man I have a lot to learn! Thanks

    LVL 16

    Accepted Solution

    I see you're using managed code. So it should be:

    nas = NetMessageBufferSend(sName,     //make server name global

    Author Comment

    I am using both, and it is difficult! For me atleast. The new compile error is

    error C2664: 'AnonymousSend::NetMessageNameAdd' : cannot convert parameter 2 from '__wchar_t  __gc[]' to 'AnonymousSend::LPCWSTR'

    Is there a site or book about conversions, that I can refer too? So I can understand this!

    Author Comment

    After some research, I found some sites, and lead me to this. It seems like it works,  I get no compile errors, or runtime erros.

    __wchar_t  from __gc [] = fromTxbx->Text->ToCharArray();
    LPCWSTR pFrom = (LPCWSTR) &from;

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now