Hi there! At first, I would like to say that I don't speak as you british or american people do (I am from Spain!). Well, my name is Jose, and I am a new user! Glad to meet you.
I am posting because I am having some problems while trying to execute a Visual C++ .NET code.
It is a win32 application, and it works with Directx 9. The code is this:
I get 0 errors and 0 warnings, and it executes correctly... ok, it doesn't.
It creates and shows the window, but suddenly (and without having time to see the window's content) it closes, and return to .NET.
I have included the Directx9 SDK Include folder to the VC++ .NET's Include list, and so did I with the LIBRARY folder. I also linked in the Drectx libraries to the project... but I don't see the blue window at all (the code is made to do this! To display a blue window!... But it closes very very fast).
I thought it was a compiler problem, so I installed VC++ 6.0... but it doesn't work.
What can I do?
I hope I have been conclude and precise. And sorry again for my English level!
See you!
I am posting because I am having some problems while trying to execute a Visual C++ .NET code.
It is a win32 application, and it works with Directx 9. The code is this:
Code:
#include <windows.h>
#include <d3d9.h>
//Store handles to the main window and application instance globally.
HINSTANCE hInst; // global handle to hold the application instance
HWND wndHandle; // global variable to hold the window handle
LPDIRECT3D9 pD3D; // the Direct3D object
LPDIRECT3DDEVICE9 pd3dDevice; // the Direct3D device
bool initWindow( HINSTANCE hInstance );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
bool initDirect3D(void);
void render(void);
void cleanUp(void);
//WinMain: Entry point for windows application
int WINAPI
WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR cmdLine, int showCmd)
{
// Initialize the window
if ( !initWindow( hInstance ) )
return false;
// called after creating the window
if ( !initDirect3D( ) )
return false;
// main message loop:
MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message!=WM_QUIT )
{
// Check the message queue
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
else
{
render( );
}
cleanUp();
return (int) msg.wParam;
}
}
/*********************************************************************
* initDirect3D
*********************************************************************/
bool initDirect3D(void)
{
pD3D = NULL;
pd3dDevice = NULL;
// Create the DirectX object
if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
{
return false;
}
// Fill the presentation parameters structure
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferHeight = 480;
d3dpp.BackBufferWidth = 640;
d3dpp.hDeviceWindow = wndHandle;
// Create a default DirectX device
if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
wndHandle,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&pd3dDevice ) ) )
{
return false;
}
return true;
}
/******************************************************************************
* bool initWindow( HINSTANCE hInstance )
* initWindow registers the window class for the application, creates the window
******************************************************************************/
bool initWindow( HINSTANCE hInstance )
{
WNDCLASSEX wcex;
// Fill in the WNDCLASSEX structure. This describes how the window
// will look to the system
wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure
wcex.style = CS_HREDRAW | CS_VREDRAW; // the class style
wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback
wcex.cbClsExtra = 0; // extra bytes to allocate for this class
wcex.cbWndExtra = 0; // extra bytes to allocate for this instance
wcex.hInstance = hInstance; // handle to the application instance
wcex.hIcon = 0; // icon to associate with the application
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);// the default cursor
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background color
wcex.lpszMenuName = NULL; // the resource name for the menu
wcex.lpszClassName = "DirectXExample"; // the class name being created
wcex.hIconSm = 0; // the handle to the small icon
RegisterClassEx(&wcex);
// Create the window
wndHandle = CreateWindow(
"DirectXExample",
"DirectXExample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, // the starting x coordinate
CW_USEDEFAULT, // the starting y coordinate
640, // the pixel width of the window
480, // the pixel height of the window
NULL, // the parent window; NULL for desktop
NULL, // the menu for the application; NULL for
// none
hInstance, // the handle to the application instance
NULL); // no values passed to the window
// Make sure that the window handle that is created is valid
if (!wndHandle)
return false;
// Display the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
/******************************************************************************
* LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
* LPARAM lParam)
* The window procedure
******************************************************************************/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Check any available messages from the queue
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
// Always return the message to the default window
// procedure for further processing
return DefWindowProc(hWnd, message, wParam, lParam);
}
/*********************************************************************
* render
*********************************************************************/
void render(void)
{
// Check to make sure you have a valid Direct3D device
if( NULL == pd3dDevice )
return;// Clear the back buffer to a blue color
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB( 0,0,255 ), 1.0f, 0 );
// Present the back buffer contents to the display
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void cleanUp (void)
{
// Release the device and the Direct3D object
if( pd3dDevice != NULL )
pd3dDevice->Release( );
if( pD3D != NULL )
pD3D->Release( );
}
I get 0 errors and 0 warnings, and it executes correctly... ok, it doesn't.
It creates and shows the window, but suddenly (and without having time to see the window's content) it closes, and return to .NET.
I have included the Directx9 SDK Include folder to the VC++ .NET's Include list, and so did I with the LIBRARY folder. I also linked in the Drectx libraries to the project... but I don't see the blue window at all (the code is made to do this! To display a blue window!... But it closes very very fast).
I thought it was a compiler problem, so I installed VC++ 6.0... but it doesn't work.
What can I do?
I hope I have been conclude and precise. And sorry again for my English level!
See you!