 #include <stdio.h>
#include <windows.h>

static const char* GetLastErrorText(DWORD dwError)
{
    static char szMsgBuf[256];

    if (!FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM |
			FORMAT_MESSAGE_IGNORE_INSERTS |
			FORMAT_MESSAGE_MAX_WIDTH_MASK,
			NULL, dwError, 0,
			szMsgBuf, sizeof(szMsgBuf), NULL))
	(void)sprintf(szMsgBuf, "Win32 Error %lu", dwError);

  return szMsgBuf;
}

int main(void)
{
  static const char path[] = "C:/Documents and Settings";
  char   jpath[MAX_PATH];
  HANDLE hDir = CreateFile(path, 0,
		FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
		NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

  if (hDir == INVALID_HANDLE_VALUE)
  {
    printf("CreateFile(%s) failed: %s\n",
	   path, GetLastErrorText(GetLastError()));
    return -1;
  }

  if (GetFinalPathNameByHandle(hDir, jpath, sizeof(jpath),
			       FILE_NAME_NORMALIZED) == 0)
  {
    printf("GetFinalPathNameByHandle() failed: %s\n",
	   GetLastErrorText(GetLastError()));
    (void)CloseHandle(hDir);
    return -1;
  }

  (void)CloseHandle(hDir);

  printf("junction: %s\n", jpath);

  return 0;
}
