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