WNetGetConnection fails in release mode
Veeraraghavan -- veera@hiso.honeywell.soft.net
Thursday, June 06, 1996
Hi Everybody,
Environment : VC++ 1.52 , Windows 3.11
I have an application which needs to find out whether the user is
connected to the server through redirected local network device(for eg
f:). I am calling WNetGetConnection for each drive letter and checking
the second parameter(which is the resourcename) to see whether the user
is connected to the server. The code works fine in debug mode but fails
in release mode. Am i missing something? Do i need to include any
windows libraries for this. This function is exported in mpr.dll under
windows NT. I guess it is exported in User dll under windows. I have
reporduced the code below.Any help is appreciated in advance.
The code below runs fine in debug mode but produces bad pointer
in release mode. Thanks for the help in advance.
CString ServerDir;
ServerPath.MakeUpper();
UINT neterror;
char driveletter='E';
char connectinfo[255];
connectinfo[0]='\0';
if(ServerPath[0]=='\\' && ServerPath[1]=='\\')
{
while(driveletter < 'Z')
{
CString drive=(CString)driveletter+(CString)":";
char *cdriveletter=new _far char[drive.GetLength()+1];
cdriveletter[0]='\0';
strcpy(cdriveletter,drive);
//cdriveletter[strlen(cdriveletter)]='\0';
UINT noofbytes;
int indexofdir;
AfxMessageBox((CString)cdriveletter);
neterror=WNetGetConnection((LPSTR)cdriveletter,(LPSTR)connectinfo,&noofbytes);
delete ( char _far *) cdriveletter;
if(neterror==WN_SUCCESS)
{
CString connectstr=(CString)connectinfo;
connectstr.MakeUpper();
AfxMessageBox(connectstr);
if(connectstr.Find(ServerPath)>=0)
{
CString msg=(CString)"Drive "+drive;
AfxMessageBox(msg);
ServerDir=drive+(CString)"\\";
WriteProfileString(SERVER,DIR,ServerDir);
break;
}
else
if(indexofdir=ServerPath.Find(connectstr)>=0)
{
CString msg=(CString)"Drive
"+drive+ServerPath.Right(ServerPath.GetLength()-connectstr.GetLength()); AfxMessageBox(msg);
ServerDir=drive+ServerPath.Right(ServerPath.GetLength()-connectstr.GetLength());
WriteProfileString(SERVER,DIR,ServerDir);
break;
}
else
{
driveletter++;
continue;
}
}
else
{
delete []cdriveletter;
driveletter++;
continue;
}
}
--
WM_THANKS|WM_REGARDS
Veera
Sr.Software Engineer
____________________________
| Veeraraghavan . S. |
/)| veera@honeywell.soft.net |(\
/ )| Ph :011-91-80-2860356,357 |( \
__( (|____________________________|) )__
((( \ \ > /_) ( \ < / / )))
(\\\ \ \_/ / \ \_/ / ///)
\ / \ /
\ _/ \_ /
/ / \ \
/ / \ \
funduc@sprynet.com
Sunday, June 09, 1996
Casting regular char buffers to CString probably causes some problems. Creating
CString objects in a loop is inefficient. I would do this:
CString ServerDir;
ServerPath.MakeUpper();
UINT neterror;
char driveletter='E';
char connectinfo[255];
connectinfo[0]='\0';
if(ServerPath[0]=='\\' && ServerPath[1]=='\\')
{
CString drive;
CString cdriveletter;
UINT noofbytes;
int indexofdir;
CString connectstr;
CString msg;
while(driveletter < 'Z')
{
drive=driveletter
drive +=":";
cdriveletter = drive;
AfxMessageBox(cdriveletter);
neterror=WNetGetConnection((LPSTR)(LPCSTR)cdriveletter,(LPSTR)connectinfo,&noofb
ytes);
if(neterror==WN_SUCCESS)
{
connectstr=connectinfo;
connectstr.MakeUpper();
AfxMessageBox(connectstr);
if(connectstr.Find(ServerPath)>=0)
{
msg = "Drive " + drive;
AfxMessageBox(msg);
ServerDir = drive + "\\";
WriteProfileString(SERVER,DIR,ServerDir);
break;
}
else
if(indexofdir=ServerPath.Find(connectstr)>=0)
{
msg="Drive " +
drive+ServerPath.Right(ServerPath.GetLength()-connectstr.GetLength());
AfxMessageBox(msg);
ServerDir=drive+ServerPath.Right(ServerPath.GetLength()-connectstr.GetLength());
WriteProfileString(SERVER,DIR,ServerDir);
break;
}
else
{
driveletter++;
continue;
}
}
else
{
driveletter++;
continue;
}
}
On Thu, 06 Jun 1996, Veeraraghavan wrote:
>Hi Everybody,
>
> Environment : VC++ 1.52 , Windows 3.11
>
> I have an application which needs to find out whether the user is
>connected to the server through redirected local network device(for eg
>f:). I am calling WNetGetConnection for each drive letter and checking
>the second parameter(which is the resourcename) to see whether the user
>is connected to the server. The code works fine in debug mode but fails
>in release mode. Am i missing something? Do i need to include any
>windows libraries for this. This function is exported in mpr.dll under
>windows NT. I guess it is exported in User dll under windows. I have
>reporduced the code below.Any help is appreciated in advance.
>
> The code below runs fine in debug mode but produces bad pointer
>in release mode. Thanks for the help in advance.
>
>
>--
>WM_THANKS|WM_REGARDS
>
>Veera
>Sr.Software Engineer
> ____________________________
> | Veeraraghavan . S. |
> /)| veera@honeywell.soft.net |(\
> / )| Ph :011-91-80-2860356,357 |( \
> __( (|____________________________|) )__
> ((( \ \ > /_) ( \ < / / )))
> (\\\ \ \_/ / \ \_/ / ///)
> \ / \ /
> \ _/ \_ /
> / / \ \
> / / \ \
>
>
Mike Funduc
Funduc Software Inc.
funduc@sprynet.com
102372.2530@compuserve.com
http://home.sprynet.com/sprynet/funduc
http://ourworld.compuserve.com/homepages/funduc
| Вернуться в корень Архива
|