Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - A few C/++ Questions
  
User name:
Password:
Reply:
 

UserPost
HyperLamer
Posts: 4347/8210
If that's your entire source, then yeah, that's the problem. It's one of the dumber-seeming (but actually not that dumb) things about C. You have to declare functions twice; once as a prototype and once as the function itself. Generally you'd use a header file for this. (I just stick them all in main.h but I do sort by file.) Basically you write a function:

void DoSomethingUseful()
{
//Todo: Code!
}


Then you copy everything up to the ), paste into the header file, and add a semicolon:
void DoSomethingUseful();
BOOL IsComputerOn();
int GetShoeSize(BODYPART* foot);


It's simple enough. It will get you from time to time; generally you'll get errors saying declarations don't match and/or are declared in odd places if you change one and not the other.
Parasyte
Posts: 499/514
Apparently not. There's a prototype, but no function.
Dish
Posts: 390/596
"Unresolved External" errors typically occur when you reference functions that have no body. You have the DialogProc prototype, and you reference the function by passing a pointer to it to DialogBox, but you don't have a DialogProc function body anywhere (or at least it's not finding it)
Ramsus
Posts: 59/162
Did you actually implement DialogProc?
windwaker
Posts: 1501/1797
*bumps after much attempt and frustration*

#include "stdio.h"
#include "windows.h"
#include "resource.h"

BOOL CALLBACK DialogProc (HWND, UINT, WPARAM, LPARAM) ;
int WINAPI WinMain (
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
DialogBox (hInstance, MAKEINTRESOURCE(DIALOG), NULL, (DLGPROC)DialogProc);
return (0);
}


Error report:

file.obj : error LNK2019: unresolved external symbol "int __stdcall DialogProc(struct HWND__ *,unsigned int,unsigned int,long)" (?DialogProc@@YGHPAUHWND__@@IIJ@Z) referenced in function _WinMain@16

I've looked through much source code on and off MSDN, and this seems like it should be valid.
Dish
Posts: 378/596
CreateDialog does a Modeless dialog (active alongside the parent). If you want a Modal dialog (takes control -- parent does not get control back until dialog is closed), look at DialogBox. I'm not sure you can make a Modeless dialog without having a parent window. I recall it being problematic for me in the past.

Most of this stuff could be figured by actually READING the remarks section under the function name ;P.. .but anyway:

hInstance - the instance of the application to load the dialog from (just pass it the instance passed to your program in WinMain() )

lpTemplate - the ID to the dialog -- although if your dialog ID is in integer form you need to use the MAKEINTRESOURCE macro. For your DLG_0100 (crummy name, btw ;P ) you'd do: MAKEINTRESOURCE( DLG_0100 )

hWndParent - handle to the parent window. NULL would specify the desktop as the parent (although, again, I think modeless dialogs need to have a parent window within the program).

lpDialogFunc - the window procedure for the dialog. All windows messages and control notifications will be passed to this function. The param itself is a function pointer. For more info on how to declare this function look up DLGPROC on MSDN.



When you're done with the dialog, DestroyWindow() gets rid of Modeless dialogs, whereas EndDialog() gets rid of Modal dialogs. Again I really suggest looking at DialogBox() unless you're sure you want a modeless dialog.
windwaker
Posts: 1469/1797
Ah, thanks, that's what I had to do.

The only thing that I don't seem to get right now is where I input the dialog name and everything. Like, when using CreateDialog():

HWND CreateDialog(

HINSTANCE hInstance,
LPCTSTR lpTemplate,
HWND hWndParent,
DLGPROC lpDialogFunc
);


Do I... replace lpTemplate with the dialog ID? (my included resource.h file includes #define DLG_0100 100)

If so, I have no idea what to put in the other parameters. ;>.>
HyperLamer
Posts: 4299/8210
Er yeah, I did mean the MSDN library, but I usually just go to msdn.microsoft.com and type whatever function I'm looking for in the search box. If it exists it'll be the first or second result.
Ramsus
Posts: 57/162
GCC when called without the -c flag will link and build the executable from all source and object files given to it, and then either output a.out (a.exe for MingW) or what you tell it to with -o (e.g. gcc -o test.exe test.c).

You can use the -c flag to compile each source file into an object file:
gcc -c source1.c # output source1.o
gcc -c source2.c # outputs source2.o
etc.

Then just call gcc and list all of the object files (and also source files) you want to use. It'll go ahead and call the linker and everything for you:

gcc -o source.exe main.c source1.o source2.o

With windows programs, be sure to include -mwindows and the resource file object:

gcc -o source.exe main.c source1.o source2.o res.o -mwindows


This is basic gcc usage, so remember it.
windwaker
Posts: 1448/1797
Whoa, thanks tons for that, Para. I couldn't really find any specific control info without knowing the functions from MSDN, that helps tons.

I have another question though, and I've looked through the MinGW documentation for this; how do you create executable and include a resource file? I've compiled resource files into object files, but I haven't found anything about including object files into a compilation. I also tried the thing Hyper suggested.
Parasyte
Posts: 471/514
Bookmark this link immediately: Individual Control Information. This is probably going to be the link you will use most on MSDN. (And always use the MSDN Library. It's important to note the Library because HyperHacker didn't link directly to it. Though he probably should have.)

The Individual Control Information page will tell you how to control all aspects of any control (window) in your program. Whether it's a button, check box, listbox, combo box, edit box, scroll bar, etc. That page has everything related to controls. And to help you imagine what HyperHacker ment by "all controls are windows" you can look up some of the Window manipulation function on MSDN, such as MoveWindow() -- which you can use to move and resize your main window or dialog, as well as any control window on it.
For more information on Dialog Boxes and Windows: MSDN Windowing.

Finally, when you ask for "a major resource with C functions" you're actually asking about the standard C libraries. Because, you see, the C language does not contain any functions at all; All functions are a product of the C language. However, most compilers come packed with standard libraries for your C programs to make use of. And for a list of the standard libs, you can try (one of my favourite resources) The Cplusplus.com STD Lib reference. Just be sure to steer clear of the iostream stuff, and stick with the links under "C standard library".
windwaker
Posts: 1446/1797
Hey, thanks for your help, man. So you tell the compiler the object files when compiling, allowing resource files to be used. I'll edit some more questions if I have any into this.

And for now.

DANCE.EXE
HyperLamer
Posts: 4285/8210
Well let's see, where to start here...

1) What I do is edit my makefile (a batch file) to have windres compile them before the program. Then I'm pretty sure you just include them in the call to gcc, like "gcc -o program.c resource.o" or something like that.

2) DialogBox() is one, I think another was something like CreateDialog()... MSDN has tons of info on this (and no, you don't need a license of, or even to be running, any Microsoft product to view it ). The biggest thing to keep in mind is that controls are treated just like windows, which can be confusing at times. (Also, there's MessageBox() for a pre-made, generic message box.)

3) Depends what kind and how you're using them. printf("%d",Var) prints a numeric variable. printf("%s",Str) prints a string. printf("%c",Var) prints a character (which can be a number, for example 31 prints an exclamation point). You can format them too: %3d = " 42", %03d = "042", and even hex: %x = "2a", %X = "2A", %03X = "02A" and so on.
Outside of printf() it's pretty simple.
Var = Var + 2; //Self-explanatory
Var += 2; //Same as above
Var++; //Same as 'Var = Var + 1', and yes, you can do -= and -- too
&Var; //Pointer to Var (This would be int*, not int, or whatever type it is)

4) MSDN, unlike most things Microsoft (), isn't all that bad. If you just use the search instead of trying to navigate manually, you should be alright. Besides that, typing a function's name (with or without brackets) usually yeilds good results, but you might need to add 'c' or 'c++' to the query.
windwaker
Posts: 1445/1797
Well, I'm *trying* to start with C, something just as/more useful than PHP.

How do you include compiled .rc files when using MinGW? I'm not really sure at all on this whole thing, as windres will convert .rc to .o, etc.

What functions do I use to screw with dialogs and such? I've searched for a list of this to no avail.

Easy question; what's the syntax for using variables? In PHP, it's not supposed to be in quotes, for instance:

echo "omgomg variable is: ". $var ." OMG.";

I haven't found anything that talks about the variable syntax.

And finally, is there a major resource (besides, ew, MSDN) with the C functions, such as php.net is for PHP?

edit on the syntax (wow I'm an idiot), it's just %d %d %d, the actual variable repeated at the end.
Acmlm's Board - I2 Archive - Programming - A few C/++ Questions


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.007 seconds.