title: How can I resolve a ERROR_BAD_NET_NAME error in a call to WNetAddConnection2?
body: <p>I am still trying to resolve a problem I'm having, <a href="https://stackoverflow.com/q/9587756/759749">the first part of it</a> was that I apparently need to call WNetAddConnection2 in order to use CreateFile to open a file across a network share.</p>
  
  <p>Having done so, I am now receiving an ERROR_BAD_NET_NAME return from the WNet...2 call.</p>
  
  <p>The remote resource is a mapped network folder on a windows network (the client, where we are, is windows xp).  The network resource <em>should</em> be connected on startup, but it'd probably be bad to assume that, of course.  The folder maps to local <code>Z:</code>.  I am able to access, read, write and delete files from the destination folder on the machine using Explorer.</p>
  
  <pre><code>HANDLE initFile ( LPCTSTR iNCfileName ) {
      DWORD dw;
      HANDLE fHandle=NULL;
  
      NETRESOURCE nr = {0}; //new structure for network resource
      nr.dwType = RESOURCETYPE_ANY; //generic resource (any type allowed)
      nr.lpLocalName = NULL; //does not use a device
      // typical iNCfileName is std::string a="Z:\\Documents\\somefile.txt".c_str()
      nr.lpRemoteName = (char*)iNCfileName;
      //"\\\\DOMAIN\\PATH\\FOLDER"; 
      nr.lpProvider = NULL; //no provider
  
      // CONNECT_CURRENT_MEDIA ??
      DWORD ret = WNetAddConnection2 (&amp;nr, NULL, NULL, CONNECT_TEMPORARY); 
  
      //...
  
      return fHandle;
  }
  </code></pre>
  
  <p>I <strong>think</strong> that the problem is I cannot use <code>Z:\Documents\somefile.txt</code> but rather should be using the \\DOMAIN\PATH\FOLDER notation.  If that's the case, how do I programatically obtain that information so that I can provide it as input?  Did I misunderstand the orignal answerer that I can convert the file name to <code>\\\\Z\\Documents\\somefile.txt</code>?  If so is there a resource to perform this or should I parse the string myself?</p>