BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: Mapping a network drive on Windows and Linux

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API)
View previous topic :: View next topic  
Author Message
Michael Gillen
Guest





PostPosted: Mon Jan 30, 2006 1:47 pm    Post subject: Re: Mapping a network drive on Windows and Linux Reply with quote



Bono wrote:

Quote:
I'm writing a CLX (multiplatform) Application and I need to connect to a
remote network
machine (I know the IP address).
Does anybody know how can I map a network drive? Is it going to work on both
(windows and linux) platforms?

This snippet of code works mapping to a network drive - Windows or Samba.

// We can map via IP address or system name
if(CbxUseIP->Checked)
RemoteName = "\\"+EdtIpAddress->Text+AnsiString(ShareName);
else
RemoteName = "\\"+EdtComputerName->Text+AnsiString(ShareName);
// An avilable drive letter was selected
AnsiString DriveName = CbxAvailDrives->Text.c_str();
NETRESOURCE nr;
DWORD dwFlags;
ZeroMemory(&nr, sizeof(nr));
nr.dwType = RESOURCETYPE_DISK;
nr.lpLocalName = DriveName.c_str();
nr.lpRemoteName = RemoteName.c_str();
dwFlags = NULL;
if(CbxRemember->Checked)
dwFlags = dwFlags | CONNECT_UPDATE_PROFILE;

Screen->Cursor = crHourGlass;
int rc;
rc = WNetAddConnection2(&nr,EdtPasswd->Text.c_str(), EdtUserName->Text.c_str(), dwFlags);
Screen->Cursor = crDefault;
if(rc != NO_ERROR)
{
// A special message for this
if(rc == ERROR_BAD_NETPATH)
MessageDlg("The network path cannot be found.", mtError, TMsgDlgButtons() << mbOK, 0);
else
GetLastErrorStr( rc );
return false;
}

--
-Michael Gillen

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Native API) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.