#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; }