Programming Tips - How can I programatically make a symbolic link?

Date: 2015apr3 Language: C/C++ Platform: win32 Q. How can I programatically make a symbolic link? A.
BOOL IsDir(LPCWSTR szDir) { DWORD dwAttrib; if ((dwAttrib = GetFileAttributes(szDir)) == 0xFFFFFFFF) return FALSE; return (dwAttrib & FILE_ATTRIBUTE_DIRECTORY); } BOOL MakeSymLink(szSrc, szTarget) { DWORD flags = IsDir(szTarget) ? SYMBOLIC_LINK_FLAG_DIRECTORY : SYMBOLIC_LINK_FLAG_FILE; if (!CreateSymbolicLink(szSrc, szTarget, flags)) { DWORD dwError = GetLastError(); fprintf(stderr, "Could not make symbolic link because %d\n", dwError); return FALSE; } return TRUE; }