1
0

main.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <windows.h>
  2. #include <stdio.h>
  3. extern int lib();
  4. struct x
  5. {
  6. const char *txt;
  7. };
  8. int main(int argc, char** argv)
  9. {
  10. int ret = 1;
  11. fprintf(stdout, "CTEST_FULL_OUTPUT (Avoid ctest truncation of output)\n");
  12. #ifdef CMAKE_RCDEFINE
  13. fprintf(stdout, "CMAKE_RCDEFINE defined\n");
  14. #endif
  15. #ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
  16. // Expect CMAKE_RCDEFINE to preprocess to exactly test.txt
  17. x test;
  18. test.txt = "*exactly* test.txt";
  19. fprintf(stdout, "CMAKE_RCDEFINE_NO_QUOTED_STRINGS defined\n");
  20. fprintf(stdout, "CMAKE_RCDEFINE is %s, and is *not* a string constant\n",
  21. CMAKE_RCDEFINE);
  22. #else
  23. // Expect CMAKE_RCDEFINE to be a string:
  24. fprintf(stdout, "CMAKE_RCDEFINE='%s', and is a string constant\n",
  25. CMAKE_RCDEFINE);
  26. #endif
  27. HRSRC hello = ::FindResource(NULL, MAKEINTRESOURCE(1025), "TEXTFILE");
  28. if(hello)
  29. {
  30. fprintf(stdout, "FindResource worked\n");
  31. HGLOBAL hgbl = ::LoadResource(NULL, hello);
  32. int datasize = (int) ::SizeofResource(NULL, hello);
  33. if(hgbl && datasize>0)
  34. {
  35. fprintf(stdout, "LoadResource worked\n");
  36. fprintf(stdout, "SizeofResource returned datasize='%d'\n", datasize);
  37. void *data = ::LockResource(hgbl);
  38. if (data)
  39. {
  40. fprintf(stdout, "LockResource worked\n");
  41. char *str = (char *) malloc(datasize+4);
  42. if (str)
  43. {
  44. memcpy(str, data, datasize);
  45. str[datasize] = 'E';
  46. str[datasize+1] = 'O';
  47. str[datasize+2] = 'R';
  48. str[datasize+3] = 0;
  49. fprintf(stdout, "str='%s'\n", str);
  50. free(str);
  51. ret = 0;
  52. #ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
  53. fprintf(stdout, "LoadString skipped\n");
  54. #else
  55. char buf[256];
  56. if (::LoadString(NULL, 1026, buf, sizeof(buf)) > 0)
  57. {
  58. fprintf(stdout, "LoadString worked\n");
  59. fprintf(stdout, "buf='%s'\n", buf);
  60. }
  61. else
  62. {
  63. fprintf(stdout, "LoadString failed\n");
  64. ret = 1;
  65. }
  66. #endif
  67. }
  68. }
  69. }
  70. }
  71. return ret + lib();
  72. }