I'm still trying to solve the problem that I am facing, the first part was that I apparently needed to call WNetAddConnection2 to use CreateFile to open the file through a network share.
Having done this, now I get the message ERROR_BAD_NET_NAME from the WNet call ... 2.
A remote resource is a mapped network folder on a Windows network (the client where we are is Windows XP). The network resource should be connected at startup, but it would probably be bad to assume that, of course. The folder maps to local Z: I can receive, read, write and delete files from the destination folder on the computer using Explorer.
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 (&nr, NULL, NULL, CONNECT_TEMPORARY); //... return fHandle; }
I think the problem is that I cannot use Z:\Documents\somefile.txt , but rather I should use the \\ DOMAIN \ PATH \ FOLDER notation. If so, how do I programmatically receive this information so that I can provide it as input? I misunderstood that I can convert the file name to \\\\Z\\Documents\\somefile.txt ? If so, is there a resource for doing this, or should I parse the string myself?
c ++ file-io winapi networking
Stephen
source share