 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri May 09, 2008 9:06 am Post subject: [vsc++]win32 problem |
|
|
Ok. Whenever I try making a Win32 Application with VC++ it always gives me some error that my other compiler doesn't. Even when I'm not even doing anything. Like right now, I tested it with just a plain old skeleton cold to just make a window, that's it, and it still gave me an error. This is the code I'm using:
| Code: |
#include <windows.h>
/* Make the class name into a global variable */
char szClassName[ ] = "WindowsApp";
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hwnd; /* This is the handle for our window */
MSG messages; /* Here messages to the application are saved */
WNDCLASSEX wincl; /* Data structure for the windowclass */
/* The Window structure */
wincl.hInstance = hThisInstance;
wincl.lpszClassName = szClassName;
wincl.lpfnWndProc = WindowProcedure; /* This function is called by windows */
wincl.style = 0; /* Catch double-clicks */
wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */
wincl.cbWndExtra = 0; /* structure or the window instance */
/* Use Windows's default color as the background of the window */
wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&wincl))
{
MessageBox(NULL, "Window Registration Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
/* The class is registered, let's create the program*/
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Windows App", /* Title Text */
WS_OVERLAPPEDWINDOW, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
544, /* The programs width */
375, /* and height in pixels */
NULL, /* The window isn't a child */
NULL, /* No menu */
hInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
if(hwnd == NULL)
{
MessageBox(NULL, "Window Creation Failed!", "Error!",
MB_ICONEXCLAMATION | MB_OK);
return 0;
}
/* Make the window visible on the screen */
ShowWindow (hwnd, nCmdShow);
UpdateWindow(hwnd);
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0) > 0)
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
/* This function is called by the Windows function DispatchMessage() */
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) /* handle the messages */
{
case WM_CREATE:
case WM_CLOSE:
DestroyWindow(hwnd);
case WM_DESTROY:
PostQuitMessage(0); /* send a WM_QUIT to the message queue */
break;
default: /* for messages that we don't deal with */
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
|
And these are the errors it gives me...
| Quote: |
------ Build started: Project: test, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\oib\my documents\visual studio 2008\projects\test\test\main.cpp(17) : error C2065: 'hThisInstance' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\test\test\main.cpp(1 : error C2440: '=' : cannot convert from 'char [11]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\oib\my documents\visual studio 2008\projects\test\test\main.cpp(19) : error C2065: 'WindowProcedure' : undeclared identifier
c:\documents and settings\oib\my documents\visual studio 2008\projects\test\test\main.cpp(37) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\oib\my documents\visual studio 2008\projects\test\test\main.cpp(55) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'char [11]' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\oib\my documents\visual studio 2008\projects\test\test\main.cpp(60) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
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\OIB\My Documents\Visual Studio 2008\Projects\test\test\Debug\BuildLog.htm"
test - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
And my other compiler doesn't give me any errors with this code.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Ferocious Advanced Cheater
Reputation: 0
Joined: 06 Feb 2008 Posts: 54
|
Posted: Fri May 09, 2008 9:11 am Post subject: |
|
|
this is because, visual studio compiles it in UNICODE. convert all your strings to unicode, or compile as multi-byte.
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Fri May 09, 2008 9:22 am Post subject: Re: [vsc++]win32 problem |
|
|
Hi, I don't know all but I know some of the problems:
1. | Code: | | wincl.hInstance = hThisInstance; | Should be | Code: | | wincl.hInstance = hInstance; |
2. You should declare WindowProcedure at the top of you're file (before any functions):
| Code: | | LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); |
3. | Code: | | char szClassName[ ] = "WindowsApp"; | Should be changed to | Code: | | char* szClassName = "WindowsApp"; | (Or change the code and put &szClassName)
4. I don't know so much about unicode and ascii and multibyte or whatever it's called in C++, but I think you have to prefix the strings with L or something: (The error tells you're using the unicode version of MessageBox, so you might try MessageBoxA (ascii))
| Code: | | MessageBox(NULL, L"Window Registration Failed!", "Error!",.... |
5. CreateWindowEx: same as at 4.
EDIT: Or change it at you're options, like Ferocious said.
I hope this helped you.
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Fri May 09, 2008 10:15 am Post subject: |
|
|
| tombana's number 3 isn't really needed and to change the strings to unicode shove a L before the text or put it in _TEXT().
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri May 09, 2008 4:46 pm Post subject: |
|
|
Oh yeah the hInstance thing. I fixed that. But I Use a skeleton and I forgot to change the skeleton...so yeah. But normally that wouldn't be there.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
Posted: Fri May 09, 2008 5:24 pm Post subject: |
|
|
| The program will never run. It will, but it will end as soon as RegisterClassEx is called. Since there is no break on WM_CREATE, it will be treated as WM_CLOSE. Then, it will go to WM_DESTROY.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Fri May 09, 2008 5:30 pm Post subject: |
|
|
Btw, how do I use the window background that delphi and VSC++ uses (VSC++ when your doing a UI form and not Win32 APIs)
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|