CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #3
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: WNetAddConnection2 returns error 1200

    Quote Originally Posted by NastyaG View Post

    What is my mistake? How can I solve this problem?
    Your mistake is that you think that casting ANSI string to LPWSTR would miraculously turn it to Unicode string. But the trick just won't work, because what you do is making compiler believe the string is wide string. While it's realy not.

    Quite a standard mistake for beginner who does not understand C pointers.

    And yes, about how to solve... You either provide wide string literal (this is what 2kaud advised), or explicitly tranlate string to the required encoding. E.g. using CString class:

    Code:
    CString name = "folder";
    nr.lpLocalName = name.GetBuffer();
    Oh! And you'd better get to habit of zeroing structures you're not going to initialize in every member.
    Code:
    NETRESOURCE nr = {0};
    Just to avoid passing garbage.
    Last edited by Igor Vartanov; September 11th, 2016 at 02:45 PM.
    Best regards,
    Igor

Tags for this Thread

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

Featured