Hello!!
I am just about to break my computer......
Is a Window Programming issue .....compiler errors are as below :
1>------ Build started: Project: Project 78, Configuration: Debug Win32 ------
1>Compiling...
1>TextOut3.cpp
1>c:\documents and settings\seyed\ my documents\game course\cpp2\cha pter 5 cpp\projects\pr oject 78\project 78\textout3.cpp (57) : error C2664: 'TextOutW' : cannot convert parameter 4 from 'const char *' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
1>c:\documents and settings\seyed\ my documents\game course\cpp2\cha pter 5 cpp\projects\pr oject 78\project 78\textout3.cpp (97) : error C2440: '=' : cannot convert from 'const char [15]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
1>c:\documents and settings\seyed\ my documents\game course\cpp2\cha pter 5 cpp\projects\pr oject 78\project 78\textout3.cpp (105) : error C2664: 'CreateWindowEx W' : cannot convert parameter 2 from 'const char [15]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
1>c:\documents and settings\seyed\ my documents\game course\cpp2\cha pter 5 cpp\projects\pr oject 78\project 78\textout3.cpp (109) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cas t, C-style cast or function-style cast
1>Build log was saved at "file://c:\Documents and Settings\seyed\ My Documents\Game Course\CPP2\Cha pter 5 CPP\Projects\Pr oject 78\Project 78\Debug\BuildL og.htm"
1>Project 78 - 4 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The entire program : -
#include <windows.h>
-
#include <string>
-
#include <vector>
-
using namespace std;
-
-
//=========================================================
-
// Globals.
-
-
HWND ghMainWnd = 0;
-
HINSTANCE ghAppInst = 0;
-
-
struct TextObj
-
{
-
string s; // The string object.
-
POINT p; // The position of the string, relative to the
-
// upper-left corner of the client rectangle of
-
// the window.
-
};
-
-
vector<TextObj> gTextObjs;
-
-
// Step 1: Define and implement the window procedure.
-
LRESULT CALLBACK
-
WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-
{
-
// Objects for painting.
-
HDC hdc = 0;
-
PAINTSTRUCT ps;
-
-
TextObj to;
-
-
switch( msg )
-
{
-
// Handle left mouse button click message.
-
case WM_LBUTTONDOWN:
-
to.s = "Hello, World.";
-
-
// Point that was clicked is stored in the lParam.
-
to.p.x = LOWORD(lParam);
-
to.p.y = HIWORD(lParam);
-
-
// Add to our global list of text objects.
-
gTextObjs.push_back( to );
-
-
InvalidateRect(hWnd, 0, false);
-
-
return 0;
-
case WM_PAINT:
-
hdc = BeginPaint(hWnd, &ps);
-
-
for(int i = 0; i < (signed)gTextObjs.size(); ++i)
-
TextOut(
-
hdc,
-
gTextObjs[i].p.x,
-
gTextObjs[i].p.y,
-
gTextObjs[i].s.c_str(),
-
/*ERROR>>>>*/ (int)gTextObjs[i].s.size());
-
-
EndPaint(hWnd, &ps);
-
return 0;
-
-
// Handle key down message.
-
case WM_KEYDOWN:
-
if( wParam == VK_ESCAPE )
-
DestroyWindow(ghMainWnd);
-
-
return 0;
-
// Handle destroy window message.
-
case WM_DESTROY:
-
PostQuitMessage(0);
-
return 0;
-
}
-
// Forward any other messages we didn't handle to the
-
// default window procedure.
-
return DefWindowProc(hWnd, msg, wParam, lParam);
-
}
-
-
// WinMain: Entry point for a Windows application.
-
int WINAPI
-
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
-
PSTR cmdLine, int showCmd)
-
{
-
// Save handle to application instance.
-
ghAppInst = hInstance;
-
-
// Step 2: Fill out a WNDCLASS instance.
-
WNDCLASS wc;
-
wc.style = CS_HREDRAW | CS_VREDRAW;
-
wc.lpfnWndProc = WndProc;
-
wc.cbClsExtra = 0;
-
wc.cbWndExtra = 0;
-
wc.hInstance = ghAppInst;
-
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
-
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
-
wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
-
wc.lpszMenuName = 0;
-
/*ERROR>>>>*/ wc.lpszClassName = "MyWndClassName";
-
-
// Step 3: Register the WNDCLASS instance with Windows.
-
RegisterClass( &wc );
-
-
// Step 4: Create the window, and save handle in globla
-
// window handle variable ghMainWnd.
-
ghMainWnd = ::CreateWindow("MyWndClassName", "TextOut Example",
-
/*ERROR>>>>*/ WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, 0, 0, ghAppInst, 0);
-
-
if(ghMainWnd == 0)
-
{
-
/*ERROR>>>>*/MessageBox(0, "CreateWindow - Failed", 0, 0);
-
return false;
-
}
-
-
// Step 5: Show and update the window.
-
ShowWindow(ghMainWnd, showCmd);
-
UpdateWindow(ghMainWnd);
-
-
// Step 6: Enter the message loop and don't quit until
-
// a WM_QUIT message is received.
-
MSG msg;
-
ZeroMemory(&msg, sizeof(MSG));
-
-
while( GetMessage(&msg, 0, 0, 0) )
-
{
-
TranslateMessage(&msg);
-
DispatchMessage(&msg);
-
}
-
-
// Return exit code back to operating system.
-
return (int)msg.wParam;
-
}
-
I have indicated lines causing compiler error.
so what the hell is going on here??!!!
some one help!
many thanks.....
1 2291
Here's your code that compiles and links: -
#include "stdafx.h"
-
//#include <windows.h>
-
#include <string>
-
#include <vector>
-
using namespace std;
-
-
//================================================== =======
-
// Globals.
-
-
HWND ghMainWnd = 0;
-
HINSTANCE ghAppInst = 0;
-
-
struct TextObj
-
{
-
wstring s; // The string object.
-
POINT p; // The position of the string, relative to the
-
// upper-left corner of the client rectangle of
-
// the window.
-
};
-
-
vector<TextObj> gTextObjs;
-
-
// Step 1: Define and implement the window procedure.
-
LRESULT CALLBACK
-
WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-
{
-
// Objects for painting.
-
HDC hdc = 0;
-
PAINTSTRUCT ps;
-
-
TextObj to;
-
-
switch( msg )
-
{
-
// Handle left mouse button click message.
-
case WM_LBUTTONDOWN:
-
to.s = TEXT("Hello, World.");
-
-
// Point that was clicked is stored in the lParam.
-
to.p.x = LOWORD(lParam);
-
to.p.y = HIWORD(lParam);
-
-
// Add to our global list of text objects.
-
gTextObjs.push_back( to );
-
-
InvalidateRect(hWnd, 0, false);
-
-
return 0;
-
case WM_PAINT:
-
hdc = BeginPaint(hWnd, &ps);
-
-
for(int i = 0; i < (signed)gTextObjs.size(); ++i)
-
TextOut(
-
hdc,
-
gTextObjs[i].p.x,
-
gTextObjs[i].p.y,
-
gTextObjs[i].s.c_str(),
-
// /*ERROR>>>>*/ (int)gTextObjs[i].s.size());
-
gTextObjs[i].s.size()
-
);
-
-
EndPaint(hWnd, &ps);
-
return 0;
-
-
// Handle key down message.
-
case WM_KEYDOWN:
-
if( wParam == VK_ESCAPE )
-
DestroyWindow(ghMainWnd);
-
-
return 0;
-
// Handle destroy window message.
-
case WM_DESTROY:
-
PostQuitMessage(0);
-
return 0;
-
}
-
// Forward any other messages we didn't handle to the
-
// default window procedure.
-
return DefWindowProc(hWnd, msg, wParam, lParam);
-
}
-
-
// WinMain: Entry point for a Windows application.
-
int WINAPI
-
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
-
PSTR cmdLine, int showCmd)
-
{
-
// Save handle to application instance.
-
ghAppInst = hInstance;
-
-
// Step 2: Fill out a WNDCLASS instance.
-
WNDCLASS wc;
-
wc.style = CS_HREDRAW | CS_VREDRAW;
-
wc.lpfnWndProc = WndProc;
-
wc.cbClsExtra = 0;
-
wc.cbWndExtra = 0;
-
wc.hInstance = ghAppInst;
-
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
-
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
-
wc.hbrBackground = (HBRUSH)::GetStockObject(WHITE_BRUSH);
-
wc.lpszMenuName = 0;
-
/*ERROR>>>>*/ wc.lpszClassName = TEXT("MyWndClassName");
-
-
// Step 3: Register the WNDCLASS instance with Windows.
-
RegisterClass( &wc );
-
-
// Step 4: Create the window, and save handle in globla
-
// window handle variable ghMainWnd.
-
ghMainWnd = ::CreateWindow(TEXT("MyWndClassName"), TEXT("TextOut Example"),
-
/*ERROR>>>>*/ WS_OVERLAPPEDWINDOW, 200, 200, 640, 480, 0, 0, ghAppInst, 0);
-
-
if(ghMainWnd == 0)
-
{
-
/*ERROR>>>>*/MessageBox(0, TEXT("CreateWindow - Failed"), 0, 0);
-
return false;
-
}
-
-
// Step 5: Show and update the window.
-
ShowWindow(ghMainWnd, showCmd);
-
UpdateWindow(ghMainWnd);
-
-
// Step 6: Enter the message loop and don't quit until
-
// a WM_QUIT message is received.
-
MSG msg;
-
ZeroMemory(&msg, sizeof(MSG));
-
-
while( GetMessage(&msg, 0, 0, 0) )
-
{
-
TranslateMessage(&msg);
-
DispatchMessage(&msg);
-
}
-
-
// Return exit code back to operating system.
-
return (int)msg.wParam;
-
}
-
Basicly, you got trapped in UNICODE vs CHAR. Visual Studio.NET has a default of _UNICODE. You could undefine this. However, with Windows it's just easier to use tchar.h. This header has various macros for converting between char and wchar_t.
The error was not on the line you identified but on the line above.
I just added TEXT macros to convert your literals to whar_t and I change the string in your struct to a wstring. Though you could: -
struct TextObj
-
{
-
#ifdef _UNICODE
-
wstring s; // The string object.
-
#else
-
string s; //The string object
-
#endif
-
POINT p; // The position of the string, relative to the
-
// upper-left corner of the client rectangle of
-
// the window.
-
};
-
-
This is the stdafx.h that I used: -
// Windows Header Files:
-
#include <windows.h>
-
-
// C RunTime Header Files
-
#include <stdlib.h>
-
#include <malloc.h>
-
#include <memory.h>
-
#include <tchar.h>
-
-
-
// TODO: reference additional headers your program requires here
-
Hope this helps.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: inquirydog |
last post by:
Hello-
I, the inquirydog, would like to solicit suggestions for a new
web page I am making:
I am creating a simple website that will translate concepts
between windows os's, Linux, and the Java language with all of its
related technologies. The website is at
http://members.dslextreme.com/users/inquirydog, and is a mock-version
of the Rosetta stone, which indicates concepts from each "platform"
|
by: Olli Piepponen |
last post by:
Hi,
I'm having a little problem catching keystrokes under Windows. I did a
little research and found that with mscvrt.getch() one can cath a single
key that is pressed. However this doesn't work when the program is run
on the backround and not as the primary task. What I would like to have
is a same sort of function that would also work when the program is being
run on the background. I'm trying to implement a program that would listen...
|
by: John Bailo |
last post by:
The war of the OSes was won a long time ago.
Unix has always been, and will continue to be, the Server OS in the form
of Linux.
Microsoft struggled mightily to win that battle -- creating a poor man's
DBMS, a broken email server and various other /application/ servers to
try and crack the Internet and IS markets.
In the case where they didn't spend their own money to get companies to
|
by: Christian McArdle |
last post by:
REQUEST FOR DISCUSSION (RFD)
unmoderated group comp.os.ms-windows.programmer.win64
This is a formal Request For Discussion (RFD) to create
comp.os.ms-windows.programmer.win64 as an unmoderated world-wide Usenet
newsgroup dedicated to the discussion of Microsoft Windows 64 bit
programming. This is not a Call for Votes (CFV); you cannot vote at
this time. Procedural details appear below. All followup discussion
should be crossposted to...
|
by: Christian McArdle |
last post by:
REQUEST FOR DISCUSSION (RFD)
unmoderated group comp.os.ms-windows.programmer.win64
This is a formal Request For Discussion (RFD) to create
comp.os.ms-windows.programmer.win64 as an unmoderated world-wide Usenet
newsgroup dedicated to the discussion of Microsoft Windows 64-bit
programming. This is not a Call for Votes (CFV); you cannot vote at
this time. Procedural details appear below. All followup discussion
should be crossposted to...
| |
by: Christian McArdle |
last post by:
REQUEST FOR DISCUSSION (RFD)
unmoderated group comp.os.ms-windows.programmer.64bit
This is a formal Request For Discussion (RFD) to create
comp.os.ms-windows.programmer.64bit as an unmoderated world-wide Usenet
newsgroup dedicated to the discussion of Microsoft Windows 64-bit
programming. This is not a Call for Votes (CFV); you cannot vote at
this time. Procedural details appear below. All followup discussion
should be crossposted to...
|
by: Patrice de Boisgrollier |
last post by:
Hello
I'm having trouble under windows 2000 dealing with programming a ping in a Visual C++ 6 environment
My problem is that my code is based on a code sampl
from Microsoft that is found in the MSDN library
Under Windows 98 there is no problem and everythin
works fine but I have a problem in Windows 2000 and XP as well with the following function :
bread = recvfrom(sockRaw
|
by: ruca |
last post by:
Hi
I have this problem:
I have a web app in two diferent servers to run. It is exactly the same
application. In this app I use the Integrated Windows Authentication.
So far so good... But the same application have diferent behaviors in both
servers. I must say that both servers (or machines) are under the same
domain.
The problem is that one (server A) of them lets me authenticate and the
other no (server B).
|
by: programming |
last post by:
Hi all,
i have been having trouble with a login script that works on my
windows machine, however when i upload it to the Unix server through
VPN, the same script won't work! It won't parse member.txt properly i
think. The password and usernames i am using are at the bottom of this
post.
Each time i go to login on the unix server, it clears the username and
password field. I have been attempting to solve the problem, but have
been...
|
by: Dan Tallent |
last post by:
A textbox has a attribute for ReadOnly. This seems like such a simple
concept. When a textbox is set to read only the user cannot change the
contents of the field.
I have been trying to find that missing ability for other predefined
controls in C#. The radiobutton, checkbox, and combobox controls do not
share this ability. I find it difficult to believe that this feature was
left out and Microsoft expects everyone to write...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |