IsDirectory和IsDots的用法,及extern与extern"C" 的困惑。

MFC类CFileFind执行本地文件查找

假设,现在在指定路径下有如下图1文件:

图  1 指定路径下包含的文件

 

(1)IsDirectory(),表明当前查找到的文件是类型为目录的文件;

 1 CString pathStr=getenv("UGII_USER_DIR");
 2 pathStr=pathStr+"\\userDefine\\*.*";   // 查找文件的路径
 3 
 4 
 5 CFileFind finder;
 6 BOOL fileFind=finder.FindFile(str);
 7 int rowIndex=0;
 8 
 9 while(fileFind)
10 {
11     if(finder.IsDirectory())
12     {
13        CString fileName=seek.GetFileName();
14        m_ObjectList.InsertItem(rowIndex,fileName); //将查找到的文件列表显示
15        rowIndex++;
16     }
17     
18 }

遍历结果如图2所示:

图  2 IsDirectory遍历结果

 

(2)IsDots表明当前查找到的是 “." 或者 "..",而这两个东西虽然是目录,但是一个表明这个目录本身,一个代表上层目录(但是根目录下面..也是本身)。

1         if (seek.IsDots())
2         {
3             CString fileName=seek.GetFileName();
4             m_ObjectList.InsertItem(rowIndex,fileName);
5             rowIndex++;
6         }

遍历结果如图3所示:

图  3 IsDots遍历结果

对比:

IsDirectory判断是否为目录,IsDots判断是否为点

每个目录下都有缺省的两个目录,名称分别为'.'和'..',分别代表上一层目录和本层目录。因此,当我们在遍历目录下文件时,需要过滤掉这两个缺省目录。

 

(3)如果我们要遍历的是路径下的非目录文件则可以,如下使用:

        if (!seek.IsDirectory())
        {
            CString fileName=seek.GetFileName();
            m_ObjectList.InsertItem(rowIndex,fileName);
            rowIndex++;
        }

遍历结果如图4所示:

图  4 非目录遍历结果

—————————————————————————————————

extern 与 extern ”C" 的困惑

在做UG二次开发的时候,如下两种用法

(1)这样当然是没问题的

 1 //入口主函数
 2 extern "C" DllExport void ufsta( char *param, int *returnCode, int rlen )
 3 {
 4     int errorCode = UF_initialize();
 5     if ( 0 == errorCode )
 6     {
 7         UF_MB_add_actions(action_table);
 8         errorCode = UF_terminate();
 9     }
10 }

 

(2)之前这样用,成功,但是今天这样测试,怎么也无法注册上菜单(编译都没问题)

 1 //入口主函数
 2 extern DllExport void ufsta( char *param, int *returnCode, int rlen )
 3 {
 4     int errorCode = UF_initialize();
 5     if ( 0 == errorCode )
 6     {
 7         UF_MB_add_actions(action_table);
 8         errorCode = UF_terminate();
 9     }
10 }

在这里:http://blog.chinaunix.net/uid-21411227-id-1826909.html,看了extern ”C" 的详细用法,但是还是没弄明白为什么,第二种,之前可以成功注册到UG菜单,今儿却不行了,C与C++还是太复杂,希望我慢慢就懂了…

posted @ 2013-01-01 19:05  liaohuming  阅读(2583)  评论(0编辑  收藏  举报