main.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <stdio.h>
  2. #include <windows.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. fprintf(stdout, "FindResource worked\n");
  30. HGLOBAL hgbl = ::LoadResource(NULL, hello);
  31. int datasize = (int)::SizeofResource(NULL, hello);
  32. if (hgbl && datasize > 0) {
  33. fprintf(stdout, "LoadResource worked\n");
  34. fprintf(stdout, "SizeofResource returned datasize='%d'\n", datasize);
  35. void* data = ::LockResource(hgbl);
  36. if (data) {
  37. fprintf(stdout, "LockResource worked\n");
  38. char* str = (char*)malloc(datasize + 4);
  39. if (str) {
  40. memcpy(str, data, datasize);
  41. str[datasize] = 'E';
  42. str[datasize + 1] = 'O';
  43. str[datasize + 2] = 'R';
  44. str[datasize + 3] = 0;
  45. fprintf(stdout, "str='%s'\n", str);
  46. free(str);
  47. ret = 0;
  48. #ifdef CMAKE_RCDEFINE_NO_QUOTED_STRINGS
  49. fprintf(stdout, "LoadString skipped\n");
  50. #else
  51. char buf[256];
  52. if (::LoadString(NULL, 1026, buf, sizeof(buf)) > 0) {
  53. fprintf(stdout, "LoadString worked\n");
  54. fprintf(stdout, "buf='%s'\n", buf);
  55. } else {
  56. fprintf(stdout, "LoadString failed\n");
  57. ret = 1;
  58. }
  59. #endif
  60. }
  61. }
  62. }
  63. }
  64. return ret + lib();
  65. }