저는 Glew와 OpenGL 3.2를 win32 컨텍스트에서 코드 블록 (minGW)으로 작업하려고했습니다. 좋은 작은 튜토리얼을 찾았습니다. here'LPCSTR {aka const wchar_t *}'을 'LPCSTR {aka const char *}'로 변환 할 수 없습니다.
코드 블럭에서 glew를 컴파일하는 것이 실제로 가능했다면 튜토리얼을 실행하기 전에 소스 코드를 시도해보고 싶었습니다.
약간의 코드를 수정 한 후 컴파일을 시도하고 이전에 보지 못한 몇 가지 오류가 발생했습니다. 다음과 같이 그들이
|In function 'bool createWindow(LPCWSTR, int, int)':|
|73|error: cannot convert 'LPCWSTR {aka const wchar_t*}' to 'LPCSTR {aka const char*}' in assignment|
|80|error: cannot convert 'LPCWSTR {aka const wchar_t*}' to 'LPCSTR {aka const char*}' for argument '2' to 'HWND__* CreateWindowExA(DWORD, LPCSTR, LPCSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID)'|
|In function 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)':|
|105|warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]|
|110|error: '_TRUNCATE' was not declared in this scope|
|110|error: 'mbstowcs_s' was not declared in this scope|
내 코드는 다른 파일이 있습니다 (텍스트의 벽에 대한 죄송합니다)
include <iostream>
#include <Windows.h>
#ifndef GLEW_STATIC
#define GLEW_STATIC
#endif //GLEW_STATIC
#include <GL/glew.h>
#include <GL/wglew.h>
//using namespace std;
//
//int main()
//{
// cout << "Hello world!" << endl;
// return 0;
//}
#include "opengl_3.h"
OpenGLContext openglContext; // Our OpenGL Context class
bool running = true; // Whether or not the application is currently running
HINSTANCE hInstance; // The HINSTANCE of this application
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Standard window callback
/**
WndProc is a standard method used in Win32 programming for handling Window messages. Here we
handle our window resizing and tell our OpenGLContext the new window size.
*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_SIZE: // If our window is resizing
{
openglContext.reshapeWindow(LOWORD(lParam), HIWORD(lParam)); // Send the new window size to our OpenGLContext
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
break;
}
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
/**
createWindow is going to create our window using Windows API calls. It is then going to
create our OpenGL context on the window and then show our window, making it visible.
*/
bool createWindow(LPCWSTR title, int width, int height) {
WNDCLASS windowClass;
HWND hWnd;
DWORD dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
hInstance = GetModuleHandle(NULL);
windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
windowClass.lpfnWndProc = (WNDPROC) WndProc;
windowClass.cbClsExtra = 0;
windowClass.cbWndExtra = 0;
windowClass.hInstance = hInstance;
windowClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
windowClass.hbrBackground = NULL;
windowClass.lpszMenuName = NULL;
windowClass.lpszClassName = title;
if (!RegisterClass(&windowClass)) {
return false;
}
hWnd = CreateWindowEx(dwExStyle, title, title, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, width, height, NULL, NULL, hInstance, NULL);
openglContext.create30Context(hWnd); // Create our OpenGL context on the given window we just created
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
return true;
}
/**
WinMain is the main entry point for Windows based applications as opposed to 'main' for console
applications. Here we will make the calls to create our window, setup our scene and then
perform our 'infinite' loop which processes messages and renders.
*/
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow) {
MSG msg;
/**
The following 6 lines of code do conversion between char arrays and LPCWSTR variables
which are used in the Windows API.
*/
char *orig = "OpenGL 3 Project"; // Our windows title
size_t origsize = strlen(orig) + 1;
const size_t newsize = 100;
size_t convertedChars = 0;
wchar_t wcstring[newsize];
mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
createWindow(wcstring, 500, 500); // Create our OpenGL window
openglContext.setupScene(); // Setup our OpenGL scene
/**
This is our main loop, it continues for as long as running is true
*/
while (running)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { // If we have a message to process, process it
if (msg.message == WM_QUIT) {
running = false; // Set running to false if we have a message to quit
}
else {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else { // If we don't have a message to process
openglContext.renderScene(); // Render our scene (which also handles swapping of buffers)
}
}
return (int) msg.wParam;
}
하지만 모든 오류는 여기에서이되기 위해 보인다. 필요한 경우 나머지를 게시하십시오.
나는 어떤 인터넷 검색을했기 때문에 오류가 컴파일러에 의해 다중 바이트 (VS2010의 설정)로 설정되지 않았기 때문에 발생했다는 것을 알지 못했습니다. 나는 주변을 둘러 보았고 코드 블럭 (codeblocks)에서 그러한 설정을 찾을 수 없었다. 이 코드는 VS에서만 사용할 수 있습니까? 아니면 내가 놓친 것이 있습니까? 내가 과거에 이것에 대해 많은 논점을 가지고 있기 때문에 그것이 나의 연결과 관련이 있을지도 모른다고 걱정했다. 어떤 도움을 주시면 감사하겠습니다.
트릭을 수행 한 것처럼 보이는 도움에 감사드립니다. 메신저하지만 다른 오류가 점점 "mbstowcs_s (& convertedChars, wcstring, origsize, orig, _TRUNCATE);" 이것은 windows 함수 호출일까요? 그것은 그것이 선언되지 않았다고 말한다. –
@IPhantasmI : 내가 아는 한,'mbstowcs_s'는 VC++ - 특정 적입니다. MinGW를 사용하는 대신 [std :: mbstowcs'] (http://en.cppreference.com/w/cpp/string/multibyte/mbstowcs)를 사용하십시오. – ildjarn
입력 변수를 변경해야합니까? im은 단순히 함수 호출을 당신이 제안한 것을 대체하는 것에서 많은 에러를 얻는 것으로 추측합니다. 나는 Windows api에 대한 많은 경험이 없으므로 변수 변환을 어떻게 수행하고 있는지 정확히 알지 못합니다. –