重新定义OpenGL示例中的WinMain错误
Redefinition of WinMain Error in OpenGL example
我正试图通过这个例子与OpenGL取得联系:
#include <windows.h>
#include <GL/GL.h>
#pragma comment (lib, "opengl32.lib")
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
{
MSG msg = {0};
WNDCLASS wc = {0};
wc.lpfnWndProc = WndProc;
wc.hInstance = hInstance;
wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND);
wc.lpszClassName = L"oglversionchecksample";
wc.style = CS_OWNDC;
if( !RegisterClass(&wc) )
return 1;
CreateWindowW(wc.lpszClassName,L"openglversioncheck",WS_OVERLAPPEDWINDOW|WS_VISIBLE,0,0,640,480,0,0,hInstance,0);
while( GetMessage( &msg, NULL, 0, 0 ) > 0 )
DispatchMessage( &msg );
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
{
PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags
PFD_TYPE_RGBA, //The kind of framebuffer. RGBA or palette.
32, //Colordepth of the framebuffer.
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24, //Number of bits for the depthbuffer
8, //Number of bits for the stencilbuffer
0, //Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};
HDC ourWindowHandleToDeviceContext = GetDC(hWnd);
int letWindowsChooseThisPixelFormat;
letWindowsChooseThisPixelFormat = ChoosePixelFormat(ourWindowHandleToDeviceContext, &pfd);
SetPixelFormat(ourWindowHandleToDeviceContext,letWindowsChooseThisPixelFormat, &pfd);
HGLRC ourOpenGLRenderingContext = wglCreateContext(ourWindowHandleToDeviceContext);
wglMakeCurrent (ourWindowHandleToDeviceContext, ourOpenGLRenderingContext);
MessageBoxA(0,(char*)glGetString(GL_VERSION), "OPENGL VERSION",0);
wglDeleteContext(ourOpenGLRenderingContext);
PostQuitMessage(0);
}
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
我正在使用最新版本的Code::Blocks (v13.12)与MinGW-TDM-GCC-4.8.1
在链接器设置中,我链接了libopengl32。a,我使用了MinGW发行版中的windows.h和gl -头文件。
但是我得到这个错误:
main.cpp|4|warning: ignoring #pragma comment [-Wunknown-pragmas]|
main.cpp|8|error: 'int WinMain' redeclared as different kind of symbol|
codeblocksmingwincludewinbase.h|1251|error: previous declaration of 'int WinMain(HINSTANCE, HINSTANCE, LPSTR, int)'|
main.cpp|8|error: '__in' was not declared in this scope|
main.cpp|8|error: '__in_opt' was not declared in this scope|
main.cpp|8|error: '__in_opt' was not declared in this scope|
main.cpp|8|error: '__in' was not declared in this scope|
我错过什么了吗?或者这个例子只在使用Visual Studio时有效(就像pragma看起来的那样)?
编辑
我把所有的东西都剪掉了(没有opengl的东西),只有win header和它的WinMain,有同样的错误。
然后我用它的标准main(见这里)替换了WinMain
int main()
{
HINSTANCE hInstance = GetModuleHandle( NULL );
HINSTANCE hPrevInstance = 0;
LPSTR lpCmdLine = NULL;
int nShowCmd = 0;
...same as before
return 0;
}
和它编译后没有错误,我也链接到libgdi32。,但是它只显示一个空命令提示符。
编辑2
我删除了宽字符串(L""
和CreateWindowW
到CreateWindow
),现在它工作了..
我猜mingw不喜欢所有MSVC特定的东西,删除#pragma comment
和所有__in
等。我认为,既然mingw不能解决那些它不能匹配WinMain
与它所拥有的定义和失败。基本上把开头改写成这样:
#include <windows.h>
#include <GL/GL.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- boost::进程间消息队列引发错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- QT在错误的班级中寻找空位
- vector.resize()中的分配错误
- 代码在main()中运行,但在函数中出现错误
- 释放错误后堆使用
- (C++)分析树以计算返回错误值的简单算术表达式
- Project Euler问题4的错误解决方案
- "未定义对'WinMain@16'的引用"gcc 编辑器中的错误
- 我无法弄清楚"对Winmain@16错误的未定义引用"
- 链接器错误:切换到unicode生成给出:未解析的外部符号WinMain
- 二叉树无法编译:错误'WinMain@16'
- 尝试使用类文件,出现"undefined reference to `WinMain@16'"错误
- c++代码块错误:对SDL_PollEvent和WinMain@16的未定义引用
- LNK2019:使用WinMain时,在函数__tmaincrtstartup中引用的未解析的外部符号_main错误
- 重新定义OpenGL示例中的WinMain错误
- SFML 和 VS2013 - WinMain/main 链接器错误