Public Group

# Setting up a Windows App in Visual Studio 2005 Beta

This topic is 4739 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am currently having problems making a transition from Visual Studio 6 to Visual Studio 2005 Beta. I know a lot has changed from VS6, but can someone enlighten me on the issue with this coding? This code was actually snatched from the book I'm reading "OpenGL Game Programming" by Kevin Hawkins & Dave Astle. It *does* actually work in VS6, but not in the latest version of VS. Here is the actual coding. The error messages generated by the compiler are below...
#define WIN32_LEAN_AND_MEAN			// Trim excess fat from Windows

#include <windows.h>				// Standard windows app include

// The Windows Procedure event handler
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{

PAINTSTRUCT paintStruct;
HDC hDC;							// Device context
char string[] = "Hello, world!";	// text to be displayed

switch(message)
{
case WM_CREATE:					// Window is being created
return 0;
break;

case WM_CLOSE:					// Windows is closing
PostQuitMessage(0);
return 0;
break;

case WM_PAINT:
hDC = BeginPaint(hwnd, &paintStruct);

// set text color to blue
SetTextColor(hDC, COLORREF(0x00FF0000));

// display text in middle of window
TextOut(hDC, 150, 150, string, sizeof(string)-1);

EndPaint(hwnd, &paintStruct);
return 0;
break;

default:
break;
}

return (DefWindowProc(hwnd, message, wParam, lParam));
}

// The application entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{

WNDCLASSEX windowClass;				// Window class
HWND	   hwnd;					// window handle
MSG		   msg;						// message
bool	   done;					// flag saying when your app is complete

// fill out the window class structure
windowClass.cbSize = sizeof(WNDCLASSEX);
windowClass.style  = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = WndProc;
windowClass.cbClsExtra  = 0;
windowClass.cbWndExtra  = 0;
windowClass.hInstance   = hInstance;
windowClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
windowClass.lpszClassName = "MyClass";

// register the window class
if(!RegisterClassEx(&windowClass))
return 0;

// class registered, so now create your window
hwnd = CreateWindowEx(NULL,							    // Extended style
"MyClass",					    // Class name
"A REAL Windows Application!",	// App Name
WS_OVERLAPPEDWINDOW |				// Window Style
WS_VISIBLE |
100, 100,							// X, Y Coordinate
400, 400,							// Width & Height
NULL,								// Handle to parent
hInstance,						// Application instance
NULL);

// check if window creation failed (hwnd would equal NULL)
if(!hwnd)
return 0;

done = false;			// initialize the loop condition variable.

// main message loop
while(!done)
{

PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);

if(msg.message == WM_QUIT)		// Do you recieve a WM_QUIT message?
{
done = true;				// if so, time to quit the application
}
else
{
TranslateMessage(&msg);		// translate and dispatch to event queue
DispatchMessage(&msg);
}

}

return msg.wParam;

}


The error messages generated by the compiler are... ---------------------------------------------------- ------ Build started: Project: OpenGL_App, Configuration: Debug Win32 ------ Compiling... Main.cpp d:\programming projects\2005\opengl_app\opengl_app\main.cpp(31) : error C2664: 'TextOutW' : cannot convert parameter 4 from 'char [14]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\programming projects\2005\opengl_app\opengl_app\main.cpp(64) : error C2440: '=' : cannot convert from 'const char [8]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\programming projects\2005\opengl_app\opengl_app\main.cpp(83) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast d:\programming projects\2005\opengl_app\opengl_app\main.cpp(109) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data Build log was saved at "file://d:\Programming Projects\2005\OpenGL_App\OpenGL_App\Debug\BuildLog.htm" OpenGL_App - 3 error(s), 1 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Any suggestions?

##### Share on other sites
Okay, I fixed the problem... but I'm not completely sure on what I'm doing wrong. I converted the old VC++ 6 project file into the new 2005 Beta format and got it to work, but for some reason I'm having problems manually setting up the project from File>New>Project...

Can someone do a really brief walkthrough of this process? I'm making a wrong turn somewhere because it's giving me a handfull of errors.

##### Share on other sites
What kind of errors is it giving you?

##### Share on other sites
It's giving me the exact same errors from the original post which are...

The error messages generated by the compiler are...
----------------------------------------------------

------ Build started: Project: OpenGL_App, Configuration: Debug Win32 ------
Compiling...
Main.cpp
d:\programming projects\2005\opengl_app\opengl_app\main.cpp(31) : error C2664: 'TextOutW' : cannot convert parameter 4 from 'char [14]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\programming projects\2005\opengl_app\opengl_app\main.cpp(64) : error C2440: '=' : cannot convert from 'const char [8]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\programming projects\2005\opengl_app\opengl_app\main.cpp(83) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
d:\programming projects\2005\opengl_app\opengl_app\main.cpp(109) : warning C4244: 'return' : conversion from 'WPARAM' to 'int', possible loss of data
Build log was saved at "file://d:\Programming Projects\2005\OpenGL_App\OpenGL_App\Debug\BuildLog.htm"
OpenGL_App - 3 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Things run absolutely beautifully if I just convert an old VC++ 6 project, but this can be totally frustrating doing it everytime. I'd like to create a project manually from the new version while copying and pasting the old code from the Main.cpp file.

##### Share on other sites
I believe LPCWSTR is unicode. I would try looking at your project settings. See if unicode is defined. I think it would be /D "UNICODE" in the linker options, or look in the C/C++ section under Language. /Zc:wchar_t. I was able to duplicate your errors with either of those two options in Visual Studio 2003. I don't have 2005 so I'm afraid I can't help there, but I would dig around and try to find those two options.

##### Share on other sites
I looked under "Project->[Project Name] Properties-> C/C++ -> Command Line" and see /D "UNICODE", but I don't know if that's exactly what your looking for. The options setting for Visual Studio 2003 appears to be similar if not the same as Visual Studio 2005. These options are pretty foreign to me... hopefully you or someone out there can piece this little issue together faster then I can.

##### Share on other sites
Yeah I would remove that from your command line if possible. Again, I don't know that if that is exactly the problem, but give it a try and see if it works. You can always put it back again later if need be. Also in 2005, under Properties->C/C++->Language there is a "Treat wchar_t as Built-in Type" option, set it to no if it is yes.

##### Share on other sites
Hmm, it won't let me remove anything that is in that non-editable textbox. On the other hand I did switch the "Treat wchar_t as Built-in Type" option to "No" because it was selected as "Yes".

I'm going to try and sleep on this one to see if I can think of any other solutions. Hopefully you or someone else will come across an idea or possible solution. I appreciate your help!!

If anyone has some sort of experience setting up a Win32 Application in VStudio 2005 with similar code as above, then please feel free to educate me/us!

##### Share on other sites
Hmm, I'm having problems setting up this project in VS .NET 2003 too.

Maybe this will be easier to *debug* since most people run .NET these days.

I created a "Blank" Win32 document and manually copied and paste the code from the first post and got 1 error message. The error message was:

c:\Documents and Settings\Christopher\My Documents\Visual Studio Projects\Win32_App2\Win32_App2\Win32_App2.cpp(99): fatal error C1010: unexpected end of file while looking for precompiled header directive

It then points to the blank space after...
	return msg.wParam;}

Any suggestions? I think this may help resolve my issue with VS 2005.

##### Share on other sites
Hey, it is I again. This one I do believe I know, you need to turn off use Precompiled headers.

• 10
• 19
• 14
• 19
• 15