Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: Meta en 13 Marzo 2017, 06:35 am



Título: No encuentra la laibrería estandar en Visual C++
Publicado por: Meta en 13 Marzo 2017, 06:35 am
Hola:

Estoy usando el nuevo Visual C++ 2017 con Win32. He probado este ejemplo que puedes ver en este enlace.

https://msdn.microsoft.com/es-es/library/bb384843.aspx

El código de ejemplo que viene completo al final del documento, si funciona muy bien para Visual Stduio Community 2015, no da ningún problema. Este mismo código me da problemas con Visual Studuio Community 2017.

Código
  1. // GT_HelloWorldWin32.cpp
  2. // compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c
  3.  
  4. #include <windows.h>
  5. #include <stdlib.h>
  6. #include <string.h>
  7. #include <tchar.h>
  8.  
  9. // Global variables
  10.  
  11. // The main window class name.
  12. static TCHAR szWindowClass[] = _T("win32app");
  13.  
  14. // The string that appears in the application's title bar.
  15. static TCHAR szTitle[] = _T("Formulario");
  16.  
  17. HINSTANCE hInst;
  18.  
  19. // Forward declarations of functions included in this code module:
  20. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  21.  
  22. int WINAPI WinMain(HINSTANCE hInstance,
  23. HINSTANCE hPrevInstance,
  24. LPSTR lpCmdLine,
  25. int nCmdShow)
  26. {
  27. WNDCLASSEX wcex;
  28.  
  29. wcex.cbSize = sizeof(WNDCLASSEX);
  30. wcex.style = CS_HREDRAW | CS_VREDRAW;
  31. wcex.lpfnWndProc = WndProc;
  32. wcex.cbClsExtra = 0;
  33. wcex.cbWndExtra = 0;
  34. wcex.hInstance = hInstance;
  35. wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  36. wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
  37. wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  38. wcex.lpszMenuName = NULL;
  39. wcex.lpszClassName = szWindowClass;
  40. wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  41.  
  42. if (!RegisterClassEx(&wcex))
  43. {
  44. MessageBox(NULL,
  45. _T("Call to RegisterClassEx failed!"),
  46. _T("Win32 Guided Tour"),
  47. NULL);
  48.  
  49. return 1;
  50. }
  51.  
  52. hInst = hInstance; // Store instance handle in our global variable
  53.  
  54.   // The parameters to CreateWindow explained:
  55.   // szWindowClass: the name of the application
  56.   // szTitle: the text that appears in the title bar
  57.   // WS_OVERLAPPEDWINDOW: the type of window to create
  58.   // CW_USEDEFAULT, CW_USEDEFAULT: initial position (x, y)
  59.   // 500, 100: initial size (width, length)
  60.   // NULL: the parent of this window
  61.   // NULL: this application does not have a menu bar
  62.   // hInstance: the first parameter from WinMain
  63.   // NULL: not used in this application
  64. HWND hWnd = CreateWindow(
  65. szWindowClass,
  66. szTitle,
  67. WS_OVERLAPPEDWINDOW,
  68. CW_USEDEFAULT, CW_USEDEFAULT,
  69. 300, 300,
  70. NULL,
  71. NULL,
  72. hInstance,
  73. NULL
  74. );
  75.  
  76. if (!hWnd)
  77. {
  78. MessageBox(NULL,
  79. _T("Call to CreateWindow failed!"),
  80. _T("Win32 Guided Tour"),
  81. NULL);
  82.  
  83. return 1;
  84. }
  85.  
  86. // The parameters to ShowWindow explained:
  87. // hWnd: the value returned from CreateWindow
  88. // nCmdShow: the fourth parameter from WinMain
  89. ShowWindow(hWnd,
  90. nCmdShow);
  91. UpdateWindow(hWnd);
  92.  
  93. // Main message loop:
  94. MSG msg;
  95. while (GetMessage(&msg, NULL, 0, 0))
  96. {
  97. TranslateMessage(&msg);
  98. DispatchMessage(&msg);
  99. }
  100.  
  101. return (int)msg.wParam;
  102. }
  103.  
  104. //
  105. //  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
  106. //
  107. //  PURPOSE:  Processes messages for the main window.
  108. //
  109. //  WM_PAINT    - Paint the main window
  110. //  WM_DESTROY  - post a quit message and return
  111. //
  112. //
  113. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  114. {
  115. PAINTSTRUCT ps;
  116. HDC hdc;
  117. TCHAR greeting[] = _T("Visual C++ 2017 Win32");
  118.  
  119. switch (message)
  120. {
  121. case WM_PAINT:
  122. hdc = BeginPaint(hWnd, &ps);
  123.  
  124. // Here your application is laid out.
  125. // For this introduction, we just print out "Hello, World!"
  126. // in the top left corner.
  127. TextOut(hdc,
  128. 55, 105,
  129. greeting, _tcslen(greeting));
  130. // End application-specific layout section.
  131.  
  132. EndPaint(hWnd, &ps);
  133. break;
  134. case WM_DESTROY:
  135. PostQuitMessage(0);
  136. break;
  137. default:
  138. return DefWindowProc(hWnd, message, wParam, lParam);
  139. break;
  140. }
  141.  
  142. return 0;
  143. }

El error que me da es este:

Gravedad    Código    Descripción    Proyecto    Archivo    Línea    Estado suprimido
Error    C1010    final de archivo inesperado al buscar la directiva de encabezado precompilado. Compruebe si olvidó agregar '#include "stdafx.h"' al código fuente?    Proyecto_Win32    c:\users\usuario\documents\visual studio 2017\projects\proyecto_win32\proyecto_win32\mensaje_texto.cpp    145   


Si pongo arriba dicho #include "stdafx.h" me marca como error, como que no lo encuentra.

¿Alguna idea?

Saludos.


Título: Re: No encuentra la laibrería estandar en Visual C++
Publicado por: ivancea96 en 13 Marzo 2017, 10:15 am
Cuando creas un proyecto de C++ con Visual Studio, tienes una opción que es "Encabezado precompilado". Si la activas, te genera ese y otros archivos.
No sé cómo creatse el proyecto, pero puedes crearlo de nuevo con esa opción activada.


Título: Re: No encuentra la laibrería estandar en Visual C++
Publicado por: Meta en 13 Marzo 2017, 13:22 pm
Hola:

Lo creé siguiendo este turorial desde la página 41. La versión 2015 me funciona a la primera, pero en el 2017 no.

https://www.slideshare.net/Metaconta2/formulario-windows-con-visual-c

Saludos.


Título: Re: No encuentra la laibrería estandar en Visual C++
Publicado por: ivancea96 en 13 Marzo 2017, 13:24 pm
En cualquier caso, lo dicho. Al crear el proyecto, fíjate en que el checkbox esté marcado.


Título: Re: No encuentra la laibrería estandar en Visual C++
Publicado por: Meta en 13 Marzo 2017, 14:11 pm
Hola:

Cierto, menudo despiesta.

Versión 2017.
https://es.slideshare.net/Metaconta2/formulario-windows-con-visual-c-2017


Gracias por la ayuda mi muy distinguido amigo.