passing functions through files

Started by
5 comments, last by gameprogrammerwiz 23 years, 10 months ago
ok, here's my code: (i'll explain my problem later) ================================================================= // =================== // = main.h = // =================== #include ddraw.h #include "ddutil.h" ... LPDIRECTDRAWSURFACE lpddsback = NULL; ... // =================== // = main.cpp = // =================== #include "main.h" #include "drawtext.h" ... draw_text(...); ... // =================== // = drawtext.h = // =================== void draw_text(char* str, int x, int y, int color); // =================== // = drawtext.cpp = // =================== #include ddraw.h #include "drawtext.h" void draw_text(char* str, int x, int y, int color) { HDC hdc; if (lpddsback->GetDC(&hdc) == DD_OK) { SetBkMode(hdc, TRANSPARENT); if(color == 0) { SetTextColor(hdc, RGB(0, 0, 0)); } if(color == 1) { SetTextColor(hdc, RGB(255, 255, 255)); } if(color == 2) { SetTextColor(hdc, RGB(255, 0, 0)); } TextOut(hdc, x, y, str, strlen(str)); lpddsback->ReleaseDC(hdc); } } ================================================================= now, i get these errors: C:\Windows\Desktop\Magesticon\drawtext.cpp(13) : error C2065: 'lpddsback' : undeclared identifier C:\Windows\Desktop\Magesticon\drawtext.cpp(13) : error C2227: left of '->GetDC' must point to class/struct/union C:\Windows\Desktop\Magesticon\drawtext.cpp(22) : error C2227: left of '->ReleaseDC' must point to class/struct/union Error executing cl.exe. and if i try to include "main.h" in "drawtext.cpp", it gives me 100+ errors for every line in main.h saying that its a redefinition. i have no idea what wrong here...any ideas? but i think for some reason, i need "main.h" to be included in "drawtext.cpp" so that it can pass the "LPDIRECTDRAWSURFACE lpddsback = NULL;" into "drawtext.cpp" so that it can use it. but if i do try to include "main.h" i get those 100+ errors, like i said. Edited by - gameprogrammerwiz on 6/14/00 1:43:50 AM
==============================
whats a signature?
htm[s]l[/s]
Advertisement
Somehow you need to define lpddback in drawtext.h
I suggest defining them in drawtext, and including drawtext.h at the top of main.
~V''lion

I came, I saw, I got programmers block.
~V''lion
~V'lionBugle4d
i cant define the lpddsback surface in drawtext.h or drawtext.cpp. i need to use the same one thats been defined in main.h
==============================
whats a signature?
htm[s]l[/s]
does "extern" work?

a2k
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Create two headers file, one called external.h and the other called global.h

In external.h, declare all the global variables as extern, like


extern LPDIRECTDRAW7 lpdd;


In the globals.h, declare all globals like


LPDIRECTDRAW7 lpdd = NULL;


Every cpp that wants access to lpdd include external.h.

Only 1 cpp (typically main.cpp) should include the global.h

That''s the idea how to use global variables. Note though placing all of them in 1 file gets very nasty..

..
Generally, actual instances of variables should be in a single .CPP file. And you make extern references to them in .H files. That solves the problem and lets you include your .H files wherever they are needed.
nevermind, i got it to work...it onyl took two hours of recoding. the name of my new arch rival is: EXTERN

==============================
whats a signature?
htm[s]l[/s]

This topic is closed to new replies.

Advertisement