Winnie - from Sourcecode

Hi,

Would somebody please help me to get simple code (Winnie) work?
This should be quite a simple one but I don't understand why can't I get it builded?

I'm very new with C++ and Visual C++ 2008 Express Edition
(have made some applets with Java before).

Just trying to get into C++ but have not had too much success with it.

Best regards,
TapaniS


Story begins:
------------------
1. Downloaded Winnie -code from Sourcecode
2. Created a new "CLR Empty Project"
3. Pulled WinTut.cpp to Source Files -folder
4. Pulled WinTut.h to Header Files -folder
5. Pushed "Build Solution" -> error message
6. Changed line 2: #include <windows> to #include <windows.h>
7. Pushed "Build Solution" -> error messages:

------ Rebuild All started: Project: Window1, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'Window1', configuration 'Debug|Win32'
Compiling...
WinTut.cpp
..\..\..\..\..\..\..\Cpp\Ohjelmia\WinTut.cpp(21) : error C2440: '=' : cannot convert from 'const char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
..\..\..\..\..\..\..\Cpp\Ohjelmia\WinTut.cpp(26) : error C2664: 'MessageBox' : cannot convert parameter 2 from 'const char [39]' to 'LPCTSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
..\..\..\..\..\..\..\Cpp\Ohjelmia\WinTut.cpp(29) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [12]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
..\..\..\..\..\..\..\Cpp\Ohjelmia\WinTut.cpp(33) : error C2664: 'MessageBox' : cannot convert parameter 2 from 'const char [28]' to 'LPCTSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\Tapani\Omat tiedostot\Visual Studio 2008\Projects\Window1\Window1\Debug\BuildLog.htm"
Window1 - 4 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Last edited on
Can't do much just by seeing errors. Post the code creating the problem
Hi, thanks for a message!

Code can be downloaded from here:
http://www.cplusplus.com/src/
(First one under Windows programs)

Oh, notised that this one is not a console program, right?
I try to create a new, windows -based project.
Let you know if this works ...
--------
Hmm... Could not get it throuh. This is somehow confusing me.


Best regards,
TapaniS
Last edited on
Not completely sure about te errors, they don't appear for me but this winnie stuff is basic graphics programming.

It apparently doesn't use any MFC libraries at all so that may be the problem
Tested to build this project with Dev-C++ 4.9.9.2, got one warning but got that .exe -file and it works fine.

Would like to use Visual C++ 2008 to build projects in CLR-format and will continue to find a way for this ...

Best regards,
TapaniS
The problem is that Visual Studio 2005, 2008 etc defaults to UNICODE builds.

Your code contains string literals like "Hello World".
These are ANSI (8 bit strings) not unicode (wide char) strings.

There two things you can do:

1. Go Project -> Properties Select each of the builds (debug and Releae) in turn and under Configuration Properties ->general change the Character Set properties from Use UNICODE character set to Use multi-byte character set.

OR

2. Find all the string literals in the code and put a capital L in front of them
so that they look something like this L"Hello World"
Last edited on
Hi,

Thank you for a solution.

I'll test it this evening and let you know how it goes.

Notised also that there is SP1 available for Visual C++ 2008 Express Edition. I'll update as soon as have some time to do it :-) Also notised that Microsoft MSDN Express Library must be installed separately. Will do that also same time.

---------- Edit

Hmmm ... Could not get it work. Got different type of error messages, all started with letter C.

So started to upgrade my system to SP1.


Best regards,
TapaniS
Last edited on
I should have added that the L option always create a wide string (unicode).

the _T macro either makes a UNICODE or standard C string depending on
whether UNICODE has been defined. For example _T("Hello World") - notice the use of the brackets. So it is the safer option.
Hi,

It looks better after SP1-update and MSDN Express Library installation. Only two linking errors as follows:

Best Regards,
TapaniS

PS. Have not installed Windows SDK yet.

------------
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\Documents and Settings\Tapani\Omat tiedostot\Visual Studio 2008\Projects\New_Window1\Debug\New_Window1.exe : fatal error LNK1120: 1 unresolved externals

--------------------------- Edited ----------------

Got too optimistic. Above was after creating a new Win32 Console Application. After creating a new CLR Empty Project got the same 25 errors as before. The errors were like:

WinTut.obj : error LNK2028: unresolved token (0A000041) "extern "C" struct HICON__ * __stdcall LoadCursorA(struct HINSTANCE__ *,char const *)" (?LoadCursorA@@$$J18YGPAUHICON__@@PAUHINSTANCE__@@PBD@Z) referenced in function "public: __thiscall WinTut::WinTut(struct HINSTANCE__ *)" (??0WinTut@@$$FQAE@PAUHINSTANCE__@@@Z)
WinTut.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall GetMessageA(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int)" (?GetMessageA@@$$J216YGHPAUtagMSG@@PAUHWND__@@II@Z) referenced in function "extern "C" int __cdecl GetMessage(struct tagMSG *,struct HWND__ *,unsigned int,unsigned int)" (?GetMessage@@$$J0YAHPAUtagMSG@@PAUHWND__@@II@Z)

--------------------------- Edited2 ----------------

Tried with another sourcecode (Win32 Example from Jared Bruni) and it worked just fine! First one that worked! You know that feeling?

--------------------------- Edited3 ----------------

Installed Windows SDK, but it was no help. The same errors as before.
Last edited on
You first said

Story begins:
------------------
1. Downloaded Winnie -code from Sourcecode
2. Created a new "CLR Empty Project"
3. Pulled WinTut.cpp to Source Files -folder
4. Pulled WinTut.h to Header Files -folder
5. Pushed "Build Solution" -> error message
6. Changed line 2: #include <windows> to #include <windows.h>
7. Pushed "Build Solution" -> error messages


To run that example, try to start with an "Empty Project", without CLR
Hi again,

Thanks Bazzy! Now I got it! It works!

Hmm... Obviously it is not very clear to me what kind of template to use. Maybe this code is not possible to build under CLR? Just thought it would be better to do project building within CLR in order to get a program (exe-file) for several platform/OS at one go. I'm not sure if I have got the idea of CLR right, but this is how I understood it.

Thank again and best regards,
TapaniS
Topic archived. No new replies allowed.