CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Jan 2009
    Posts
    1

    Problem With Data Execution Prevention (DEB)

    I worte a program using opengl that draws a circle. When I run it on my computer it works fine, but when I try and run it on my friend's computer (vista), the program crashes giving a message relating to DEP.

    My friend tried disabling DEP on the program, but vista didn't like that and wouldn't allow it.

    I have the following files added to additional dependenices of the input page of the linker:

    opengl32.lib glu32.lib


    Heres my code:
    Code:
    //
    // Based from:
    //
    // GLSAMPLE.CPP
    //  by Blaine Hodge
    // http://www.nullterminator.net/opengl32.html
    
    // Includes
    
    #include <windows.h>
    #include <gl/gl.h>
    #include <math.h>
    
    // Function Declarations
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC);
    void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC);
    void DrawCircle(float, float, float);
    void DrawFillCircle(float, float, float);
    
    // WinMain
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
    				   LPSTR lpCmdLine, int iCmdShow)
    {
    	WNDCLASS wc;
    	HWND hWnd;
    	HDC hDC;
    	HGLRC hRC;
    	MSG msg;
    	BOOL quit = FALSE;
    	
    	// register window class
    	wc.style = CS_OWNDC;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    	wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    	wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "GLBase";
    	RegisterClass( &wc );
    	
    	// create main window
    	hWnd = CreateWindow( 
    		"GLBase", "OpenGL Base", 
    		WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
    		0, 0, 512, 512,
    		NULL, NULL, hInstance, NULL );
    	
    	// enable OpenGL for the window
    	EnableOpenGL( hWnd, &hDC, &hRC );
    	
    	// program main loop
    	while ( !quit )
    	{
    		
    		// check for messages
    		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )  )
    		{
    			
    			// handle or dispatch messages
    			if ( msg.message == WM_QUIT ) 
    			{
    				quit = TRUE;
    			} 
    			else 
    			{
    				TranslateMessage( &msg );
    				DispatchMessage( &msg );
    			}
    			
    		} 
    		else 
    		{
    			glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
    			glClear( GL_COLOR_BUFFER_BIT );
    			
    			glPushMatrix();
    
    			//Background - White
    			glColor3f(1.0f, 1.0f, 1.0f);
    			glBegin(GL_QUADS);
    				glVertex2f(-1.0f, 1.0f);
    				glVertex2f(1.0f, 1.0f);
    				glVertex2f(1.0f, -1.0f);
    				glVertex2f(-1.0f, -1.0f);
    			glEnd();
    			
    			//Circle
    			glColor3f(0.0f, 0.0f, 1.0f);
    			DrawFillCircle(0,0,.5);
    
    			glColor3f(0.0f, 0.0f, 0.0f);
    			DrawCircle(0,0,.5);
    
    			glPopMatrix();
    			
    			SwapBuffers( hDC );
    		}
    		
    	}
    	
    	// shutdown OpenGL
    	DisableOpenGL( hWnd, hDC, hRC );
    	
    	// destroy the window explicitly
    	DestroyWindow( hWnd );
    	
    	return msg.wParam;
    	
    }
    
    // Window Procedure
    
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	
    	switch (message)
    	{
    		
    	case WM_CREATE:
    		return 0;
    		
    	case WM_CLOSE:
    		PostQuitMessage( 0 );
    		return 0;
    		
    	case WM_DESTROY:
    		return 0;
    		
    	case WM_KEYDOWN:
    		switch ( wParam )
    		{
    			
    		case VK_ESCAPE:
    			PostQuitMessage(0);
    			return 0;
    			
    		}
    		return 0;
    	
    	default:
    		return DefWindowProc( hWnd, message, wParam, lParam );
    			
    	}
    	
    }
    
    // Enable OpenGL
    
    void EnableOpenGL(HWND hWnd, HDC * hDC, HGLRC * hRC)
    {
    	PIXELFORMATDESCRIPTOR pfd;
    	int format;
    	
    	// get the device context (DC)
    	*hDC = GetDC( hWnd );
    	
    	// set the pixel format for the DC
    	ZeroMemory( &pfd, sizeof( pfd ) );
    	pfd.nSize = sizeof( pfd );
    	pfd.nVersion = 1;
    	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    	pfd.iPixelType = PFD_TYPE_RGBA;
    	pfd.cColorBits = 32;
    	pfd.cDepthBits = 32;
    	pfd.iLayerType = PFD_MAIN_PLANE;
    	format = ChoosePixelFormat( *hDC, &pfd );
    	SetPixelFormat( *hDC, format, &pfd );
    	
    	// create and enable the render context (RC)
    	*hRC = wglCreateContext( *hDC );
    	wglMakeCurrent( *hDC, *hRC );
    	
    }
    
    // Disable OpenGL
    
    void DisableOpenGL(HWND hWnd, HDC hDC, HGLRC hRC)
    {
    	wglMakeCurrent( NULL, NULL );
    	wglDeleteContext( hRC );
    	ReleaseDC( hWnd, hDC );
    }
    
    
    
    ////////////////////
    // Draw Functions //
    ////////////////////
    
    //Circle - http://www.swiftless.com/tutorials/opengl/circle.html
    
    void DrawCircle(float x, float y, float r)
    {
    	glBegin(GL_LINES);
    
    	for (float i = 0.0F; i < 6.28F; i = i + .1)
    	{
    		float X = r * cos(i) + x;
    		float Y = r * sin(i) + y;
    		glVertex2f(X, Y);
    
    		X = r * cos(i + 0.1F) + x;
    		Y = r * sin(i + 0.1F) + y;
    		glVertex2f(X, Y);
    	}
    
    	glEnd();
    }
    
    //Filled Circle
    
    void DrawFillCircle(float x, float y, float r)
    {
    	glBegin(GL_LINES);
    
    	for (float i = 0.0F; i < 3.14F; i = i + .005)
    	{
    		float X = r * cos(i) + x;
    		float Y = r * sin(i) + y;
    		glVertex2f(X, Y);
    
    		X = r * cos(-i) + x;
    		Y = r * sin(-i) + y;
    		glVertex2f(X, Y);
    	}
    
    	glEnd();
    }
    Last edited by ring2ding; January 11th, 2009 at 07:11 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured