 |
| Visual C++ 2005 For discussion of Visual C++ 2005. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual C++ 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

December 21st, 2008, 03:11 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
No idea what im doing wrong...
OO i like how syntax is colored now. I havent been on these forums in so long. anyways. i decided to get off the stupid computer games and go back to learning how to make them. I have a book titled "Begining DirectX 9" by wendy jones. and i did the first excersize but when i compile it i get told i can not overload winmain and the 2nd error is on line 63 saying "cannot convert parameter two from 'const char[15]' to 'LPCWSTR'
does anyone know what i am doing wrong? this is an empty win32 project done in visual studio 2005 professional edition
// Include windows header
#include<windows.h>
HINSTANCE hInst;
HWND wndHandle;
// Prototypes
bool initWindow( HINSTANCE hInstance );
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
// Entry point
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{
// Init window
if( !initWindow(hInstance))
returnfalse;
// Message loop
MSG msg;
ZeroMemory( &msg, sizeof( msg) );
while( msg.message!=WM_QUIT )
{
// Check the msg queue
while(GetMessage(&msg, wndHandle, 0, 0) )
{
TranslateMessage( &msg );
DispatchMessage( &msg);
}
}
return (int)msg.wParam;
}
bool initWindow( HINSTANCE hInstance )
{
WNDCLASSEX wcex;
// Fill in the wndclassex struct
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
// Create the window
wndHandle = CreateWindow(
"DirectXExample",
"DirectXExample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if(!wndHandle)
returnfalse;
// Display window
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
returntrue;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Check any available msgs
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
|
|

December 22nd, 2008, 01:01 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
|
|
Would help if you'd use the [ code ] ... [ /code ] tags around your code and indent the code so it's readable.
Anyway, I dunno which is your line 63, but I'm going to *GUESS* that the problem is here:
Code:
...
wndHandle = CreateWindow( "DirectXExample", "DirectXExample", ...
...
Because both of those strings are, indeed, const char[15]. (Don't forget, you have to count the NULL character on the end...14 letters plust the null gives you 15 characters and indeed since they are literal strings they are const.)
And the CreateWindow call apparently requires a UNICODE ("wide character") string, instead of an ordinary one-byte-per-character string, for one or both of those first two arguments.
&&&&&&&&&&&&
Just noticed that the message said "argument two" is the one with the wrong type, so maybe the first string is valid. Dunno. You need to find the definition of that function (it's probably in "windows.h") and pass args that match the requirements.
And if you didn't know, you read " LPCWSTR" to be "Long Pointer to Constant Wide STRing". The "Long" part is a holdover from 16-bit system days (shows how often MS updates this stuff) just meaning this is a 32-bit pointer.
I am *NOT* a Visual C++ user (or, rather, I used to be but haven't used it for 8 or 9 years or so), but that kind of message is a pretty clear one: You simply used the wrong kind of argument in calling a function.
Last edited by Old Pedant; December 22nd, 2008 at 01:12 AM..
|
|

December 22nd, 2008, 09:10 PM
|
|
Friend of Wrox
|
|
Join Date: Mar 2008
Posts: 133
Thanks: 15
Thanked 1 Time in 1 Post
|
|
DirectX Time
okay. i fixed my problem. it turns out creating an empty project is what i had to do... the book ( Begining DirectX 9 by Wendy Jones ) told me to make an empty win32 project. So in short i have a working window now with a white client area. Now i have added some directX code and i have about 5 to 8 or so errors all in windows.h complaining about something with a PVOID64 data type. anyways. i should be on a directX forum i guess but since this one is a favorite of mine im going to see who can help me here :)
Code:
// Include windows header
#include<windows.h>
#include<d3d9.h>
HINSTANCE hInst;
HWND wndHandle;
LPDIRECT3D9 pD3D;
LPDIRECT3DDEVICE9 pd3dDevice;
// Prototypes
bool initWindow( HINSTANCE hInstance );
bool initDirect3D(void);
void render(void);
void cleanUp(void);
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM );
// Entry point
int WINAPI WinMain( HINSTANCE hInstance,HINSTANCEhPrevInstance, LPTSTR lpCmdLine, int nCmdShow )
{// Init window
if( !initWindow(hInstance))return false;
// Called after initializing window
if(!initDirect3D() )return false;
// Message loop
MSG msg;
ZeroMemory( &msg, sizeof( msg) );
while( msg.message!=WM_QUIT )
{// Check the msg queue
if( PeekMessage( &msg, NULL, OU, OU, PM_REMOVE ) )
{TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{render();
}
}
return (int)msg.wParam;
}
bool initWindow( HINSTANCE hInstance )
{WNDCLASSEX wcex;
// Fill in the wndclassex struct
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "DirectXExample";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
// Create the window
wndHandle = CreateWindow("DirectXExample",
"DirectXExample",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if(!wndHandle)return false;
// Display window
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
bool initDirect3D(void)
{pD3D = NULL;
pd3dDevice = NULL;
// Create the DX Obj
if( NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION ) ) )
{
return false;
}
// Fill presParams
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 the default DX device
if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
wndHandle,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&pd3dDevice ) ) )
{return false;
}
return true;
}
void render(void)
{// Check validity of D3D device
if( NULL == pd3dDevice )return;
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );
// Pres params
pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
void cleanUp(void)
{// Release device and d3d obj.
if( pd3dDevice != NULL )pd3dDevice->Release( );
if( pD3D != NULL )pD3D->Release( );
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// Check any available msgs
switch(message)
{
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}
|
|
 |