|
Hi!
In MFC how can we find the ip address of our own computer?
Thanks.
Avi
|
|
|
|
|
Try gethostname() followed by gethostbyname() .
(David Crow posted this reply to an identical question earlier today).
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
hi Ravi,
thanks for pointing to that message. but this is what i meant--
is it possible to obtain ipaddress of a computer, when it is not connected to network. say u run mfc application on your computer and it prints out the ipaddress of your machine. i was wondering if there was any function available in mfc for this purpose.
thanks.
Avi
|
|
|
|
|
I suspect David's solution may just return 127.0.1.1 ("localhost") if you're not part of a LAN. Perhaps you want this[^] article?
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I'm a tyro at VC++, but I've been following this thread with some interest. Forgive me if this is a stupid idea, but is there some way you can capture the output of a call to ShellExecute on the command ipconfig? If you're disconnected you may have to add the /all option to make it cough up inactive connections, and you're probably going to have to parse a bunch of text to capture the IP address. Just a thought - I haven't tried it. But I hope that it might provide some sort of solution, however kludgy it might be...
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|
Hi,
The ShellExecute doesn't output the text returned by ipconfig, but you can redirect the output from ipconfig to a file!
For exemple: in the console (command prompt if you will) one can type
"ipconfig /all > somefile.txt".
This way the output will be written in "somefile.txt". If it doesn't exist, it'll be created.
Knowing this, the call to ShellExecute() will look like this
<FONT COLOR="blue">int</FONT> nResult = ShellExecute(hYourMainWindowHandle,
NULL,
"ipconfig /all > SomeFile.txt",
NULL,
NULL,
0
);
All you have to do is parse "SomeFile.txt".
Hope this helps
A student knows little about a lot.
A professor knows a lot about little.
I know everything about nothing.
|
|
|
|
|
That was my thought - redirect to a file and read it back. But I assumed someone smarter than I might know a way to do it more efficiently C++. In Java, of course, you'd only have to do a
InetAddress address = InetAddress.getByName(<host url="">);
byte[] addressBytes = address.getBytes();
to retrieve the machine address.
"Another day done - All targets met; all systems fully operational; all customers satisfied; all staff keen and well motivated; all pigs fed and ready to fly" - Jennie A.
|
|
|
|
|
Roger Wright wrote:
...is there some way you can capture the output of a call to ShellExecute on the command ipconfig?
Yes, see these MSDN articles for examples:
http://support.microsoft.com/default.aspx?scid=kb;en-us;190351
http://tinyurl.com/guro
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I need to present a dialog to the user similar to an installer license agreement dialog. What is the best way to present many read-only lines of vertical-scrollable text to the user with automatic horizontal word-wrapping? I thought that something like word-wrapping would be a basic feature for the MFC CEdit control, but I couldn't find any option to enable it.
|
|
|
|
|
|
Static text controls have vertical scrollbars? How do I enable them?
|
|
|
|
|
Make sure the multiline style is set (ES_MULTILINE ), and make sure the automatic horizontal scrolling style is not (ES_AUTOHSCROLL ). Also set ES_READONLY if you do not intend for it to be edited.
Shog9
---
You'd better turn back, before the frost sets in.
These desert nights are for weathered men,
The ones who've already given in...
|
|
|
|
|
Thanks, I didn't have auto-hscroll off .
|
|
|
|
|
hello i am working on an encryption project.
i have delacared a variable
HCRYPTPROV abc;
HCRYPTPROV is defined in the Wincrypt.h header file as:
typedef unsigned long HCRYPTPROV;
i have include the "Wincrypt.h" in my project and the file is present in Include directory..
but i get an error "Undeclared variable" for my statement
can any one suggest why and how to solve it
qrious
|
|
|
|
|
Are you SURE you've included it so that it is visible to the file that defines this variable ? Because, if you have, then this will work.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
yes i have included the Wincrypt.h header file in my project but still i am getting the errors.....
thank you
qrious
|
|
|
|
|
To reiterate: you are either not including this file, or you are including it in the wrong place, or it does not define what you think it does. Or possibly you have two files with that name, and the wrong one is being included.
It would help if you posted some code, and the error you are getting.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
i guess the mistake, that you are doing is that, you are using double quoutes instead of angled brackets to include the the file.
kindly write #include<wincrypt.h> at the top of your .cpp file in which you using HCRYPTPROV. You should use Microsoft C compiler instead of Turbo C.
|
|
|
|
|
hi
i have used angle brackets to include th file Wincrypt.h in my file
and iam using VC++ for doing the project .. i hope that should be enough
i am not able complie the project
thanks ...
qrious
|
|
|
|
|
Hello all,
I'm a really new c++ programmer in the U.S. Navy. I'm trying to write an airline reservation program with a class list{} class flight{} and class passenger that has to read passengers and files from a file. I have no idea how to start this program. Any help would be appreciated. this is what I was given for it. Struct flight { int number; //flight number
char *from; //departure city
char *to //destination city
struct flight *next; // link to next flight
struct pass *pass //link to passengers
};
struct pass
{
char *first; //first name
char *last; // last name
char seat[4] //seat number
struct pass *pass; // link to passengers
struct header
{
struct flight *first;
struct flight *last;
int howmany; //howmany flights
Any help on getting started with the accessors and constructors I might need would help a lot. I did this school that I was made to do in a week and trying to learn all of c++ in a week is not easy. If anyone has any good ideas on a start or how I should go about doing this please help me.
Thanks
|
|
|
|
|
Hi there. If you need to read and write information from a file, you should read my articles on iostreams. Basically you #include<fstream> and then you can read and write files easily, and you could even set yourself up to read and write your custom structures with inserters and extractors ( this is not hard, I have an article on it here on CP ). Then you could do this:
pass myPass;
ifstream myFile("c:\\file.txt");
while (myFile.good())
{
myFile >> myPass;
// do something with the passenger
}
// the end.
It's a shame you need to use char *'s instead of strings. A struct is just a class whose default access is public, you should add constructors and destructors to the structs, the constructor should set the char *'s to null, and the destructors show call delete [] on them if they are not null.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I can change what is inside of my struct or I can even make it a class i'm not bound to do it that way. It was just an example set up for us. I just have trouble starting the program. I'm so new that I still look in books and try to get ideas but still struggling. Thanks for the advice I will definetly try to figure it all out.
|
|
|
|
|
sakota wrote:
I can change what is inside of my struct or I can even make it a class i'm not bound to do it that way.
In that case, absolutely make the strings strings instead of char *. so #include<string> and put using std::string at the top of your code. Then you can use the string class to handle string memory for you. Your only problem is if you use iostreams to read the file, you'll need to use getline to read strings, or otherwise reading will stop when the string has a space in it.
By all means, post your code as you go, and we'll be glad to help more.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Also the program has to have a menu that allows users to list flights (from a txt file called flights)
list passengers on a particular flight (from a txt file called pass)
add a passenger (add to a particular flight that is in the flight file)
and exit.
Making the menu is pretty much the only thing that I'm able to do pretty easily I think. Thank you all for the help.
it says that I will need at least these three classes
class list {} to be used by the flight class
class Flight {} a flight object for each flight
class Passenger {} a passenger Object for each passenger
Most of the people in this class are new at programming and have given up on this project already. We aren't graded on it we just are suggested to do it. I want to do it so I can gain the coding experience. It is hard to get ideas when you don't know where to start or what you should be looking at. We don't even have an instructor to ask we had to learn everything by a CBT online. This really sucks.
|
|
|
|
|
sakota wrote:
I want to do it so I can gain the coding experience. It is hard to get ideas when you don't know where to start or what you should be looking at. We don't even have an instructor to ask we had to learn everything by a CBT online. This really sucks.
It sounds like an advanced starting project, but it also sounds like you have the right attitude. Stick with it, you'll learn a lot from this project, and you can always ask more questions when you get stuck.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|