• 硬链接


     

    #include <windows.h>
    #include <string.h>
    #include <stdio.h>
    
    typedef BOOL (__stdcall *pCreateHardLink)(
                                              LPCTSTR lpFileName,
                                              LPCTSTR lpExistingFileName,
                                              LPSECURITY_ATTRIBUTES lpSecurityAttributes
                                              );
    
    int main()
    {
        HMODULE hlib = LoadLibrary("kernel32.dll");
        pCreateHardLink fCreateHardLink = (pCreateHardLink) GetProcAddress(hlib,"CreateHardLinkA"); 
        
        
        LPCTSTR str1 = "C:\1.txt";
        LPCTSTR str2 = "c:\2.txt";
        
        
        //保证2.txt在C盘根目录是存在的
        //且硬盘的分区格式为NTFS
        BOOL b = fCreateHardLink(str1,str2,NULL);
        
        if(b)    {
            HANDLE hFile = CreateFile("c:\1.txt",GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
            
            DWORD dwNum = 0;
            
            char *pszStr = "asdf";
            
            //对1.txt进行写入观察2.txt的内容
            WriteFile(hFile,(LPCTSTR)pszStr,strlen("asdf"),&dwNum,NULL);
            
            CloseHandle(hFile);
            
        }
        else
        {
            printf("%d",GetLastError());
        }
        return 0;
    }


  • 相关阅读:
    个人总结
    团队作业五
    个人项目五:个人回顾
    第二次冲刺
    第一次冲刺
    猜数字1
    随机数
    个人作业
    课后作业1
    作业
  • 原文地址:https://www.cnblogs.com/pangblog/p/3249445.html
Copyright © 2020-2023  润新知