Advertising (This ad goes away for registered users. You can Login or Register)

C computer, need some help/advice

Discuss about your favorite (gaming...or not) devices here. The most popular ones will end up getting their own categories
Programming discussions for your favorite Device
Forum rules
Forum rule Nº 15 is strictly enforced in this subforum.
asgard20032
Posts: 186
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

C computer, need some help/advice

Post by asgard20032 » Tue Apr 19, 2011 4:15 am

Before i start, i want to say: I know i started a thread in the other programming forum, the one for psp, that list some resource and tutorial. Its unfinished, and it will remain until i got more time. School steal me a lot of time, but i still try to learn some new thing.

Preference:
-C only (no C++)
-I don't want to use library that require the user to download a specific dll... i mean, i want to use only the library that come by default with windows. I think opengl don't require any download, and come by default, can someone confirm that?
-Please, can you also post an exemple? Not a whole source, but only 3-4 line to show how it work.

Actually, im looking for some C tutorial, the one at http://www.cprogramming.com/ is... not so useful.

Actually, im learning socket, very interesting(at http://www.cprogramming.com/, they only show how to use variable, pointer, write file... but nothing more)

After reading it, i got an idea, but not really about socket, but the idea come from that...

If a server can have his server application in background, why i don't do the same thing with my program?

The same day, i was also searching to learn more about creating multithreading application. (if you get a good tutorial that don't require me to download some library..., feel free to share, almost every time, the tutorial use pthread or something like that... i don't want to use that)

I read somewhere a way to actually hide the console, by making a new thread, then killing the parent thread (the main)... like the idea... but... you will see why i hesitate soon.





After reflexion, i know exactly what i want to do, just a program, that when we execute, no console, but we can make the console appear: A background program that we could call the console. for exemple, if my program act like a server, i could want to call the console, enter a specific command, like a restart or just ban an ip, then just write HIDE, to hide the console again.
To call it, i want to

A: create a service(still dont know how) that when we make it execute it make the console appear, and when we stop it, the console close, or if we type HIDE in the console, the service stop, and the console hide
B: Just creating an icon, next to where time is show... you know... in the blue bar, left corner... When we click on it, the window appear, then we type HIDE to hide it...
C: making another program that could the process of my background program.

Either option, i need a way to hide the console, then be able to call it back. My favorite option would be B, but i would still also want to learn how to create service or how to make a program controlling another process... for further use.
Advertising
Image

MVP
Posts: 78
Joined: Fri Jan 21, 2011 4:21 am

Re: C computer, need some help/advice

Post by MVP » Tue Apr 19, 2011 12:23 pm

windows api can do all those things. hide console, show in taskbar, etc.
Advertising

Strangelove
Posts: 286
Joined: Thu Nov 25, 2010 6:32 pm

Re: C computer, need some help/advice

Post by Strangelove » Tue Apr 19, 2011 1:16 pm

Seldom I see a bigger piece of verbal porridge... :shock:
If you want good answers have good questions. In my case that means specific questions.
I'll just try to give you an very basic overview of the windows programming forest here:

The good old win32 api is what everything on windows was built on. it can do pretty much anything. it's also a C API.
Standard C library calls are handled by the C runtime, which either maps to Win32 API calls or gets handled at a lower level.

To make things easier for programmers, microsoft developed the MFC which is a C++ class API that runs on top of the win32 api and simplifies programming.

You didn't mention graphics, but IMO handling graphics on win32 api is a pain. all graphics intensive applications these days use directx. this library provides something the win32 api doesn't: a modern and effective way to write games etc. This is an API that isn't really built on top of the Win32 API, where possible it attempts to access hardware more directly, hence the name.

the latest standard api to emerge from microsoft is .NET. this runs on top of the win32 api, and to simplify, it is aimed to replace the use of win32 api with a more modern api. afaik it also adds some overhead and encourages (lures) the programmer to write so-called "managed code".

so there you have it, four APIs that is always present (or should be) on any windows computer: Win32, MFC, DirectX and .NET.

you forget though, that you can distribute non-standard libraries with your application or link them statically (!).
some tasks are complicated to do by using the win32 api alone, so most programmers end up doing these tasks with the help of a 3rd party library.

regarding your question about the console window. you either have one, or you don't. this is decided when you compile your program, and it all has to do with what runtime you link against. In a IDE you usually choose between "win32 console application" and "win32 windowed", on the command line you use a parameter to specify which runtime you link your application against. as you guessed it is possible to disable the console window with a command in your program.

also some stuff like icons are handled as "resources". you should have a resource compiler somewhere in your toolchain.

if i understood correctly you shouldn't need threads for what you are trying to achieve. you can create a server application that does whatever you want it to do, then have another client application to communicate with it. there are many ways to achieve this, one is by communicating via network calls, or you can use an IPC of sorts, heck you could even use shared memory, pipes or even text-files. :P
"If you have specific questions ... don't hesitate to ask as the more generic the question is the more philosophic the answer will be" - PSPWizard

asgard20032
Posts: 186
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

Re: C computer, need some help/advice

Post by asgard20032 » Tue Apr 19, 2011 9:36 pm

MVP wrote:windows api can do all those things. hide console, show in taskbar, etc.
I know windows api can do it, but i dont know how to make windows api to do it.
And when i said hide the console, i dont just mean minimized, but really hided, so hided that if i press alt tab, its not here.
Image

MVP
Posts: 78
Joined: Fri Jan 21, 2011 4:21 am

Re: C computer, need some help/advice

Post by MVP » Wed Apr 20, 2011 11:02 pm

list of windows api functions and how they work.

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

asgard20032
Posts: 186
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

Re: C computer, need some help/advice

Post by asgard20032 » Thu Apr 21, 2011 3:16 am

actually, im coding a client, for a server im also coding.

My client can connect, now i modify it so the user input the ip when the program is started.
Is there anyway to use a dynamic string, then use a fonction to retrieve the user input?
i tried getline, but dont work, mingwe dont like it... scanf... not so good...


char **IP;
printf("Entrer le IP");
gets(IP);


why it don't work? any way to make it work? I don't want to put a fixed size, even if i should, since i know in another project i could need to let the user input as many thing as he want... and i want to know how to do it. For now, i will use scanf, but if someone could learn me how to make a dynamic string and retrieve user input to put in...



i also tried to make that if user start the program with an argument, it pass the argument to IP string

if (argc == 2){
char *IP;
IP = argv[1];
}
else{
char IP[15];
printf("Entrer le IP:\n");
scanf("%s", IP);
}


but it dont work, i get an error saying that: C:\Users\Alexandre\Documents\Projet\Client\main.c|54|error: 'IP' undeclared (first use in this function)|
if i ask the user for IP, it work, but if i try to copy string content from argv, dont work... how sgould i do that?
Image

MVP
Posts: 78
Joined: Fri Jan 21, 2011 4:21 am

Re: C computer, need some help/advice

Post by MVP » Thu Apr 21, 2011 4:11 am

to copy the string, use the strcpy function.

Code: Select all

strcpy(IP,argv[1]);
and for a dynamic string use malloc

User avatar
m0skit0
Guru
Posts: 3817
Joined: Mon Sep 27, 2010 6:01 pm

Re: C computer, need some help/advice

Post by m0skit0 » Sat Apr 23, 2011 11:40 am

You should get a good book a bout C and read it first.

First, as convention, variables are lower case while constants are upper case. using IP as variable is not a good idea, use ip instead.

Code: Select all

char **IP;
Double pointer? Why? Also you're not allocating any memory for this string, you're just declaring a pointer. Thus when you do:

Code: Select all

printf("Entrer le IP");
gets(IP);
You're actually writing the string to uninitalized unallocated memory. Very bad bug here. Same thing here:

Code: Select all

if (argc == 2)
{
    char *IP;
    IP = argv[1];
}
Also as pointed out by MVP to copy a string to another one you need to use strcpy, you cannot simply use = (since you're then assigning pointers and not their content).

And use the

Code: Select all

 tags when posting your code.
I wanna lots of mov al,0xb
Image
"just not into this RA stuffz"

asgard20032
Posts: 186
Joined: Thu Jan 20, 2011 1:16 pm
Location: Milky Way, Solar system, Earth, North America, Canada, Québec..... In front of my computer

Re: C computer, need some help/advice

Post by asgard20032 » Mon May 02, 2011 3:16 am

Im doing a calculator for linux, using codeblock ide.
When i try to compile, it say:

warning: comparison with string literal result in unspecified behavior
at each logical test:

Code: Select all

int main(int argc, char** argv){
  int choice;
  ...//i will not rewrite all my code in the forum...
  else if (argv[1] == "Help"){ //right here
  choice = 1;
  }
  else if (argv[1] == "a" || argv[1] == "add"){//again
  choice = 2;
  }
  ...//no need to show all my code
}
i wanted to use the argument passed to main for a switch statement, but i read i cannot do a switch with string, so i assign an integer for each possibility. So i will do my switch with the int choice.

My goal is to make a program that i will call from the terminal to do basic operation.

So what should i do?
Image

waratte
Posts: 1320
Joined: Wed Oct 20, 2010 12:03 am

Re: C computer, need some help/advice

Post by waratte » Mon May 02, 2011 3:48 am

asgard20032 wrote:Im doing a calculator for linux, using codeblock ide.
When i try to compile, it say:

warning: comparison with string literal result in unspecified behavior
at each logical test:

Code: Select all

int main(int argc, char** argv){
  int choice;
  ...//i will not rewrite all my code in the forum...
  else if (argv[1] == "Help"){ //right here
  choice = 1;
  }
  else if (argv[1] == "a" || argv[1] == "add"){//again
  choice = 2;
  }
  ...//no need to show all my code
}
i wanted to use the argument passed to main for a switch statement, but i read i cannot do a switch with string, so i assign an integer for each possibility. So i will do my switch with the int choice.

My goal is to make a program that i will call from the terminal to do basic operation.

So what should i do?
1.I believe we use strcmp(string compare) instead of "==".
2.Why not do whatever inside of the "if" statement Instead of the switch statement?

Post Reply

Return to “Programming and Security”