Jump to content

  • Log In with Google      Sign In   
  • Create Account

Learnin' DirectX


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 afmack   Members   -  Reputation: 111

Like
0Likes
Like

Posted 15 June 2012 - 11:29 AM

Hello, I'm in the process of learning DirectX 11 with the book "Beginning DirectX 11 Game Programming". I'm using Microsoft Visual Studio '10 and I'm trying to get a blank window running.

Here's the code I'm running:

#include <Windows.h>
LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
PAINTSTRUCT paintStruct;
HDC hDC;
switch( message )
{
case WM_PAINT:
   hDC = BeginPaint( hwnd, &paintStruct );
   EndPaint( hwnd, &paintStruct );
   break;
  case WM_DESTROY:
   PostQuitMessage( 0 );
   break;
  default:
   return DefWindowProc( hwnd, message, wParam, lParam );
}
return 0;
}
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow )
{
UNREFERENCED_PARAMETER( prevInstance );
UNREFERENCED_PARAMETER( cmdLine );
WNDCLASSEX wndClass	= {0};
wndClass.cbSize		= sizeof( WNDCLASSEX ) ;
wndClass.style		 = CS_HREDRAW | CS_VREDRAW;
wndClass.lpfnWndProc   = WndProc;
wndClass.hInstance	 = hInstance;
wndClass.hCursor	   = LoadCursor( NULL, IDC_ARROW );
wndClass.hbrBackground = (HBRUSH ) (COLOR_WINDOW + 1 );
wndClass.lpszMenuName  = NULL;
wndClass.lpszClassName = "DX11BookWindowClass";
if( !RegisterClassEx (&wndClass ) )
  return  -1;
RECT rc = { 0, 0, 640, 480 };
AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
HWND hwnd = CreateWindowA( "DX11BookWindowClass", "Blank Win32 Window",
  WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left,
  rc.bottom-rc.top, NULL, NULL, hInstance, NULL );
if(!hwnd)
  return-1;
ShowWindow( hwnd, cmdShow );
// demo init
MSG msg = { 0 };
while( msg.message != WM_QUIT )
{
  if ( PeekMessage(&msg, 00, 0, 0, PM_REMOVE) )
  {
   TranslateMessage( &msg );
   DispatchMessage( &msg );
  }
  else{
  // Update
  // Draw
  }
}
// Demo Shutdown
return static_cast<int>( msg.wParam );
}

The error I'm receiving is: error C2440: '=' : cannot convert from 'const char [20]' to 'LPCWSTR' .
For the line: wndClass.lpszClassName = "DX11BookWindowClass";

Any ideas as to how I can fix this?

Sponsor:

#2 Inuyashakagome16   Members   -  Reputation: 835

Like
1Likes
Like

Posted 15 June 2012 - 11:49 AM

http://www.gamedev.net/topic/403518-cannot-convert-char-to-lpcwstr/ < That should help. I actually had the same issue with that book and that topic helped out. :P Damn Unicode.

#3 afmack   Members   -  Reputation: 111

Like
0Likes
Like

Posted 15 June 2012 - 12:26 PM

Thanks a lot! That was actually a REALLY simple fix, lol.

#4 Inuyashakagome16   Members   -  Reputation: 835

Like
0Likes
Like

Posted 15 June 2012 - 02:14 PM

It was when I had the issue as well. :P I'm not very fluent in DX yet but that's one issue I run into a lot. :P Keep that fix handy, you'll need it.

#5 Aardvajk   Crossbones+   -  Reputation: 6260

Like
0Likes
Like

Posted 15 June 2012 - 04:34 PM

If it's easier, you can go to Project->Properties->General and change Use Character Set to Multibyte. This will switch off the UNICODE setting in on a project-wide basis.

Not recommending this for real code - we should all be using UNICODE as standard now, but when following code from an older book that does not use UNICODE, can be simpler.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS