Results 1 to 3 of 3

Thread: [RESOLVED] SysAllocString

  1. #1

    Thread Starter
    New Member cristinuccia's Avatar
    Join Date
    Jul 2013
    Location
    Italy
    Posts
    9

    Resolved [RESOLVED] SysAllocString

    Hi all,

    Code:
    BSTR tmp = SysAllocString(L"Hello world");
    It works! But

    Code:
    char mystr[] = "Hello world";
    BSTR tmp = SysAllocString(mystr);
    Does not compile. Any hint?

    Thanks,

    Cristina

  2. #2

    Thread Starter
    New Member cristinuccia's Avatar
    Join Date
    Jul 2013
    Location
    Italy
    Posts
    9

    [SOLVED] Re: SysAllocString

    Finally, I solved as follows:

    Code:
    string str="Hello World";
    int wslen = ::MultiByteToWideChar(CP_ACP, 0 /* no flags */,
                                          str.data(), str.length(),
                                          NULL, 0);
    BSTR wsdata = ::SysAllocStringLen(NULL, wslen);
    ::MultiByteToWideChar(CP_ACP, 0 /* no flags */,
                              str.data(), str.length(),
                              wsdata, wslen);
    
    BSTR tmp = SysAllocString(wsdata);

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: [SOLVED] Re: SysAllocString

    Thread moved from the 'VB6 and Earlier' forum to the 'C and C++' forum

    Quote Originally Posted by cristinuccia View Post
    Finally, I solved as follows:
    As you now have it sorted out, could you please do us a little favour, and mark the thread as Resolved?
    (this saves time reading for those of us who like to answer questions, and also helps those who search to find answers)

    You can do it by clicking on "Thread tools" just above the first post in this thread, then "Mark thread resolved". (like various other features of this site, you need JavaScript enabled in your browser for this to work).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width