Guest User

Untitled

a guest
Jul 20th, 2017
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3.  
  4. typedef int (*isattyFunc)(int fd);
  5.  
  6. int main()
  7. {
  8.     HMODULE cygwin;
  9.     isattyFunc isatty;
  10.     int isattyResult;
  11.     LPWCH env;
  12.     wchar_t *envPtr;
  13.  
  14.     AddDllDirectory(L"c:\\unix\\bin");
  15.  
  16.     env = GetEnvironmentStringsW();
  17.     for (envPtr = env; *envPtr != '\0'; envPtr += wcslen(envPtr) + 1) {
  18.         _putws(envPtr);
  19.     }
  20.  
  21.     cygwin = LoadLibraryExW(L"cygwin1.dll", NULL, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);
  22.     if (cygwin == NULL) {
  23.         printf("No cygwin1.dll found in known paths: %d\n", GetLastError());
  24.         return 0;
  25.     }
  26.  
  27.     isatty = (isattyFunc)GetProcAddress(cygwin, "isatty");
  28.     if (isatty == NULL) {
  29.         printf("No isatty() function exported by cygwin1.dll.\n");
  30.         return 0;
  31.     }
  32.  
  33.     fflush(stdout);
  34.  
  35.     isattyResult = isatty(1);
  36.     printf("isatty() result: %d\n", isattyResult);
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment