YOU CAN CODE!

 

With The Case Of UCanCode.net  Release The Power OF  Visual C++ !   HomeProducts | PurchaseSupport | Downloads  
Download Evaluation
Pricing & Purchase?
E-XD++Visual C++/ MFC Products
Overview
Features Tour 
Electronic Form Solution
Visualization & HMI Solution
Power system HMI Solution
CAD Drawing and Printing Solution

Bar code labeling Solution
Workflow Solution

Coal industry HMI Solution
Instrumentation Gauge Solution

Report Printing Solution
Graphical modeling Solution
GIS mapping solution

Visio graphics solution
Industrial control SCADA &HMI Solution
BPM business process Solution

Industrial monitoring Solution
Flowchart and diagramming Solution
Organization Diagram Solution

Graphic editor Source Code
UML drawing editor Source Code
Map Diagramming Solution

Architectural Graphic Drawing Solution
Request Evaluation
Purchase
ActiveX COM Products
Overview
Download
Purchase
Technical Support
  General Q & A
Discussion Board
Contact Us

Links

Get Ready to Unleash the Power of UCanCode .NET


UCanCode Software focuses on general application software development. We provide complete solution for developers. No matter you want to develop a simple database workflow application, or an large flow/diagram based system, our product will provide a complete solution for you. Our product had been used by hundreds of top companies around the world!

"100% source code provided! Free you from not daring to use components because of unable to master the key technology of components!"


GetDeviceType and _splitpath with lstrlen and lstrcat

 
 
This subroutine handles GetDeviceType when you have an arbitrary path. There are three problems with the GetDeviceType API: (1) if you have a path which contains a file name, it returns the error code DRIVE_NO_ROOT_DIR; (2) it works differently on Windows NT and Windows 95; (3) if you pass it a string that contains a name like "\\.\d\" it does not recognize the local drive. This code fixes these problems. It strips back the name until it has either a drive letter (C:, for example), or a network path name (\\ prefix). It discards any file name portion. It also handles paths that do not contain a drive or UNC name. The program knows how to compensate for the fact that Windows 95 and Windows NT _splitpath parse differently.

GetDriveType("C:") returns DRIVE_FIXED on NT 4.0 and DRIVE_NO_ROOT_DIR on Win95.

GetDriveType("C:\") returns DRIVE_FIXED on both systems.

The sample application, the GetDriveType Explorer, allows you to test this subroutine by typing in a test string. As each character is typed, you see the result of calling GetDriveType with the current string, the result of a _splitpath operation on the path, and the "cooked" result of applying getDriveType (note the initial lowercase letter).

For concisesness, the comments have been removed from the version below. They appear in the full source in the download.

UINT getDriveType(LPCTSTR fullpath)
    {
     TCHAR drv[_MAX_PATH];
     TCHAR path[_MAX_PATH];
     TCHAR filename[_MAX_PATH];
     TCHAR ext[_MAX_PATH];

    
_splitpath(fullpath, drv, path, filename, ext);
     if(
lstrlen(drv) != 0)
        { /* drv */
         lstrcat(drv, _T("\\"));
         return GetDriveType(drv);
        } /* drv */
     else
        { /* what else? */
         if(path[0] != _T('\\') ||
            (lstrlen(path) > 2 && path[0] == _T('\\') &&
                path[1] != _T('\\')))
            return
GetDriveType(NULL);

         UINT result =
GetDriveType(path);
         if(result == DRIVE_NO_ROOT_DIR &&
            lstrlen(path) >= 4 && path[0] == _T('\\') && path[1] == _T('\\')
                              && path[2] == _T('.') && path[3] == _T('\\'))
            { /* \\. */
             if(
lstrlen(path) == 4)
               
lstrcat(path, filename);
             LPTSTR p = &path[4];
             LPTSTR b = strchr(p, _T('\\'));
             if(b != NULL)
                { /* logical drive */
                 *b++ = _T(':');
                 *b++ = _T('\\');
                 *b = _T('\0');
                } /* logical drive */
             else
                lstrcat(p, _T(":\\"));

             return
GetDriveType(p);
            } /* \\. */

         if(lstrlen(path) < 2 || path[0] != _T('\\') || path[1] != _T('\\'))
            return result;

         return
GetDriveType(path);
        } /* what else? */
           
    }
 

 

Copyright ?1998-2009 UCanCode.Net Software , all rights reserved.
Other product and company names herein may be the trademarks of their respective owners.

Please direct your questions or comments to webmaster@ucancode.net