Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Include files sem to be in the wrong directory.


  • Please log in to reply

#1
Sescheraun

Sescheraun

    New Member

  • Member
  • Pip
  • 3 posts
Ok,

Let me see if I can get this explained clearly...

I have had VB6 for a while, and recently gotten VC++6. I installed it and everything went just fine... or so it seemed.

I have written a program and tried to compile it...

//header files to include

#include <windows.h>
#include <stdlib.h>
#include <time.h>

//App title
#define APPTITLE "Hello World"

//function prototypes
BOOL InitInstance(HINSTANCE,int);
ATOM MyRegisterClass(HINSTANCE);
LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM);

//The window even callback function
LRESULT CALLBACK WinProcHWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
char *szHello = "Hello World";
RECT rt;
int x, y, n;
COLORREF c;
switch (message)

{
case WM_PAINT:
//get the diminsions of the window
GetCLientRect(hWnd, &rt);

//Start drawing on the device context
hdc=BeginPoint(hWnd, &ps);

//draw some text
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);

//draw 1000 random pixels
for (n=0; n<3000; n++)

{
x=rand() % (rt.right - rt.left);
y=rand() % (rt.botton - rt.top);
c=RGB(rand()%256, rand()%256, rand()%256);
SetPixel(hdc, x, y, c);
}

//stop drawing
EndPaint(hWnd, &ps);
break;

case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, message, wParam, lParam);
}

//helper function to set up the window properties
ATOM MyRegisterClass(HINSTANCE hInstance)
{
//create the window class structure
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);

//fill the structure with info
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WinProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = APPTITLE;
wc.hIcon = NULL;

//set the window with class info
return RegisterClassEx(&wc0);
}

//Helper function to create the window and refresg it
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;

//Create a new window
hWnd = CreateWindow(
APPTITLE, //Window Class
APPTITLE, //Title Bar
WS_OVERLAPPEDWINDOW, //Window Style
CW_USEDEFAULT, // x Position of the window
CW_USEDEFAULT, // y Position of the window
500, //Width
400, //Height
NULL, //Parrent Window
NULL, //Menue
hInstance, //Application instance
NULL); //Window Parameters

//was there an error in creating the window?
if (!hWnd)
return FALSE;

//Display the window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);

return TRUE;
}

//Entry point for a windows program
int WINAPI WinMain(HUNSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
//Declare variables
MSG msg;

//Register the class
MyRegisterClass(hInstance);

//Initialize the application
if (!InitInstance (hInstance, nCmdShow))
return FALSE;

//Set the random number seed
srand(time(NULL));

//Main message loop
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}



The program is out of a tutorial book I have....



When I compile it I get this...

--------------------Configuration: Main - Win32 Debug--------------------
Compiling...
Main.cpp
e:\program files\vb6\msdev98\myprojects\windowtest\main.cpp(16) : error C2146: syntax error : missing ';' before identifier 'hWnd'
e:\program files\vb6\msdev98\myprojects\windowtest\main.cpp(16) : warning C4229: anachronism used : modifiers on data are ignored
e:\program files\vb6\msdev98\myprojects\windowtest\main.cpp(16) : fatal error C1004: unexpected end of file found
Error executing cl.exe.

Main.obj - 2 error(s), 1 warning(s)



Further digging has led me to believe that the program is not finding the include files. the program installed to /program files/vc98. but it is saving the projects in /program files/vb6/dev98/projects. the header files are located under the vc98 directory, and they are all there. I have gone under properties and made sure the directories tab points at the right folders.

I am not sure how sacred the directories are and so i am not sure if I can or should simply move my projects folder. I am also not sure if it's a code issue or not, though I doubt it is because I get the same error when i load the source code from from the cd that came with the book,


i would be greatfull for any help.


Thanks.
Bob
  • 0

Advertisements


#2
bdlt

bdlt

    Member

  • Member
  • PipPipPip
  • 876 posts
Hi Bob,

you may not believe this - the compiler actually found bad syntax on line 16, just as it reported. this code looks like it needs a lot of work.

suggestion 1 - start with a simple 'hello world' program to convince yourself that the include files are found.

after that, see if you can figure out how to fix line 16. then get ready for more failures. decide if it's worth your time to resurrect this code.

suggestion 2 - select other files from the cd and see how many of those work. this should give you an idea how reliable the cd files will be.

bdlt
  • 0

#3
Sescheraun

Sescheraun

    New Member

  • Topic Starter
  • Member
  • Pip
  • 3 posts
Oh, great.

Ok, After a silly thought about trashing the book, I spent the few moments and found the type in line 16. I also discovered that the code from the book simply loaded into the same project as my code, and thats why it gave me the error. lol...

Thanks
Bob

Edited by Sescheraun, 29 May 2005 - 07:51 AM.

  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP