nicht in 'LPCWSTR {aka const wchar_t*}' zu 'LPCSTR {aka const char*}
Habe ich versucht zu bekommen, Glew und opengl 3.2 arbeiten mit code blocks(minGW) in einer win32-Kontext. fand ich ein nettes kleines tutorial hier
Als ich versucht hatte, um herauszufinden, ob kompilieren von glew in codeblocks tatsächlich möglich war, wollte ich versuchen, die Quelle aus, bevor Sie das tutorial, um zu sehen, ob es funktionieren würde.
nach änderungen im code leicht habe ich versucht zu kompilieren und bekam mehrere Fehler, die ich nie zuvor gesehen. Sie sind wie folgt
|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|
Mein code ist
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;
}
(Sorry für die wall of text)
es gibt auch andere Dateien, die aber alle Fehler, die scheinen immer von hier aus.
ill post den rest, wenn nötig.
Habe ich nicht wirklich gesehen ähnelt diese Fehler also ich habe einige googeln und fand heraus, dass der Fehler verursacht wurde vom compiler nicht auf "multi" eingestellt-byte(eine Einstellung in VS2010). ich habe einige schaut sich um und konnte nicht finden, eine solche Einstellungen in codeblocks. ist dieser code kann nur in VS oder habe ich etwas verpasst? im besorgt, dass es möglicherweise etwas zu tun mit meiner Verlinkung durch mich eine Menge Probleme mit diesem in der Vergangenheit. jede Hilfe würde geschätzt werden.
InformationsquelleAutor I Phantasm I | 2012-08-05
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ändern
CreateWindowEx
zuCreateWindowExW
oder definieren Sie das makroUNICODE
vor einschließlich aller Kopfzeilen.Soweit ich weiß,
mbstowcs_s
ist VC++-spezifisch. Mit MinGW, verwenden Sie einfachstd::mbstowcs
statt.Würden die input-Variablen geändert werden. ich vermute so wie im immer eine Menge von Fehlern ersetzt einfach den Funktionsaufruf an das, was Sie vorgeschlagen. Ich habe nicht viel Erfahrung mit der windows-api, so dass im nicht wirklich sicher, wie genau er leistet die variable Umwandlung.
ist Teil der C-standard, es ist in keiner Weise von Windows-spezifisch. Gehören
<cstdlib>
und ändern z.B.mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
zuconvertedChars = 1 + std::mbstowcs(wcstring, orig, newsize);
. Die Dokumentation fürmbstowcs_s
hier, so können Sie es dagegen mitmbstowcs
.Vielen Dank, Sie haben eine große Hilfe gewesen und haben oben gegangen und darüber hinaus nur die Antwort auf die Frage.
InformationsquelleAutor ildjarn
Habe ich noch nie verwendet minGW, so nehmen Sie dies mit einem riesigen Körnchen Salz. (VS Express ist kostenlos zu benutzen, BTW.)
Unicode/Ascii-Entscheidung ist weitgehend gesteuert durch die UNICODE definieren. Also, wenn du ein #define UNICODE-1, oder möglicherweise passieren, dass in Ihre Compiler-Kommandozeile, es gibt eine gute chance, dass würde Ihr problem lösen.
InformationsquelleAutor Michael