How to specify a network path to FindFirstFile API

Sometimes might have used following code snippet to check whether a file existing or not.

WIN32_FIND_DATA fdt;
HANDLE hFile = ::FindFirstFile( _T("C:\\Downloads"),&
fdt);

The above code may succeed if you give a valid local path in your HDD.

Sometimes you may need to check a share in network existing or not. So What would you do? You may write something as follows

//Try with network file path
WIN32_FIND_DATA fdt;
HANDLE hFile = ::FindFirstFile( _T("\\\\writer\\Downloads"),&fdt);

What’s wrong with above code? The code would fail and return error code 0×35(53) (Use GetLastError()).(Error Message: “The network path was not found”)

As per the documentation, giving path of a network share is a bit different.

On network shares, you can use an lpFileName in the form of the following: “\\server\service\*”. However, you cannot use an lpFileName that points to the share itself; for example, “\\server\service” is not valid.

So the following code will work fine for you

WIN32_FIND_DATA fdt;
HANDLE hFile = ::FindFirstFile( _T("\\\\writer\\Downloads\\*"),&fdt);

We have a simple and smart way to check the existance of a file or path with a simple API. As you see below.

//Try with Shell API
if( PathFileExists(_T("\\\\writer\\Downloads") ) )
{
MessageBox( _T( "Succeed to find file" ));
};

Article: Read Environment Strings of Remote process

I’ve written an article at code project. It’s a simple tool to get Environment string information of a remote process. Please have a look at my article. Expecting your valuable feedback

Fix Available for – LNK1000: Internal error during IncrBuildImage (VS 2008)

Some of you might have experienced following Link Error when you are compiling your C++ Project using Visual Studio 2008.

1>Linking…
1>LINK : fatal error LNK1000: Internal error during IncrBuildImage
1>  Version 9.00.21022.08
1>  ExceptionCode            = C0000005
1>  ExceptionFlags           = 00000000
1>  ExceptionAddress         = 02ACCE21
1>  NumberParameters         = 00000002
1>  ExceptionInformation[ 0] = 00000008
1>  ExceptionInformation[ 1] = 02ACCE21
1>CONTEXT:
1>  Eax    = 02ACCE21  Esp    = 0030F270
1>  Ebx    = 40008168  Ebp    = 0030F29C
1>  Ecx    = 0092D670  Esi    = 4005B66C
1>  Edx    = 0030F28C  Edi    = 00E8D6C0
1>  Eip    = 02ACCE21  EFlags = 00010246
1>  SegCs  = 0000001B  SegDs  = 00000023
1>  SegSs  = 00000023  SegEs  = 00000023
1>  SegFs  = 0000003B  SegGs  = 00000000
1>  Dr0    = 00000000  Dr3    = 00000000
1>  Dr1    = 00000000  Dr6    = 00000000
1>  Dr2    = 00000000  Dr7    = 00000000

Visual Studio Team has released patch for this issue. (ExceptionCode            = C0000005 – hmmm Seems some access violations occured inside link.exe)

NOTE THAT CURRENTLY MSFT NOT TESTED THIS FIX WITH OTHER UPDATES. SO INSTALL IT AT YOUR OWN RISKS. READ CAREFULL THE DOCUMENTATION BEFORE INSTALLING

Read KB948127
Download link is provided inside the KB article. I am not posting the download link here as they may update the location later.

Proudly powered by WordPress
Theme: Esquire by Matthew Buchanan.