|
Only compiler designers and people with a strange liking for dull reading need it anyway.
Bernd
|
|
|
|
|
hi..
can someone tell me how do i get the IP address of my own PC???
tks a lot...
With Regards
Joseph R. Thomas
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
|
|
|
|
|
....
char host[80];
gethostname(host,80);
LPHOSTENT lpHost;
lpHost = gethostbyname(host);
UINT ip = ((LPIN_ADDR)lpHost->h_addr)->s_addr;
....
|
|
|
|
|
nope...doesnt work!!!
With Regards
Joseph R. Thomas
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
|
|
|
|
|
Try initializing winsock first:
#include "Winsock2.h"
#pragma comment(lib,"Ws2_32.lib")
int main(int argc, char* argv[])
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return -1;
}
char host[80];
gethostname(host,80);
LPHOSTENT lpHost;
lpHost = gethostbyname(host);
UINT ip = ((LPIN_ADDR)lpHost->h_addr)->s_addr;
char* addr= inet_ntoa(*(LPIN_ADDR)lpHost->h_addr);
return 0;
}
John
|
|
|
|
|
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
Autoconfiguration IP Address. . . : 169.254.159.128
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :
PPP adapter PacNet:
Connection-specific DNS Suffix . :
IP Address. . . . . . . . . . . . : 210.24.247.6
Subnet Mask . . . . . . . . . . . : 255.255.255.255
Default Gateway . . . . . . . . . : 210.24.247.6
the codes u gave me are fetching Autoconfiguration IP Address i.e 169.254.159.128
what i need is IP Address i.e 210.24.247.6
can someone please help???
With Regards
Joseph R. Thomas
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
|
|
|
|
|
Joseph_R_Thomas wrote:
can someone please help???
The problem is you have more than one ip address. The code above will return the first.
replace h_addr in the previous examples with h_addr_list[1] to get the second.
John
|
|
|
|
|
|
but what if the program keeps on shifting from one machine to another where some machine have more than one IP addresses and soem have only one????
With Regards
Joseph R. Thomas
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
|
|
|
|
|
It gets very complicated. Any network adapter may have multiple IP addresses. A computer may have more than one network adapters. I am not sure how you can figure out which ip address is the one that is connected to the internet and actually more than one can be connected to the internet.
You can use this code to go through the list of ip addresses:
#include "Winsock2.h"
#pragma comment(lib,"Ws2_32.lib")
int main(int argc, char* argv[])
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 2, 2 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return -1;
}
char host[80];
gethostname(host,80);
LPHOSTENT lpHost;
lpHost = gethostbyname(host);
for(int i=0;(LPIN_ADDR)lpHost->h_addr_list[i] != 0;i++) {
UINT ip = ((LPIN_ADDR)lpHost->h_addr_list[i])->s_addr;
char* addr= inet_ntoa(*(LPIN_ADDR)lpHost->h_addr_list[i]);
}
return 0;
}
John
|
|
|
|
|
but then how to select the correct one????
With Regards
Joseph R. Thomas
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
|
|
|
|
|
Joseph_R_Thomas wrote:
but then how to select the correct one????
They are all correct. I will explain. Think about the case where there is a lan connected to one network adapter and a second network adapter is conected to the internet using a dsl modem. One ip adddress will work to talk to the other pcs on the lan. The other ip address will work for the internet.
I assume you mean the one connected to the internet?? I am not sure.
John
|
|
|
|
|
u see..in my school its al connected to lan so there is only one ip..
at my house however as i showed you in the first or second post..there are more than one IP Address....in this case i need the IP Address that connects to the internet...the one that is called IP Address not AutoConfiguration IP Address.....
so in school the codes work fine..but at home...i got prob since i need to select the IP Address not the Auto config IP Address....
With Regards
Joseph R. Thomas
Have a Super Blessed Day!
-------------------------
For God has not given us a spirit of fear, but of power and of love and of a sound mind.
2 Timothy 1:7
|
|
|
|
|
I might be on the wrong track here but when you call bind on a socket you can specify ADDR_ANY for the ip address. Then, windows will sort out which actual IP address to use based on routing information - this saves you having to manually determine which IP address you need to select.
Phil
|
|
|
|
|
I was thinking the same. It depends why he wants the address.
John
|
|
|
|
|
recently i work on oledb&sqlserver, for some reason , i use many unregular table name just like guid, for example: 4DACE4ED-55A9-4F9C-9270-CE73CBF067F3.
there is no problem on my computer at all, but yesterday i install the application on an other machine, it does not work anymore,so i debuged the program on that machine and found that creating table is ok, but error occurs while opening a table with such unregular name. can anyone please tell me what the reason?
should i need any aditional package?
many thanks
|
|
|
|
|
All right, I think I'm a little dense here! So, I'm going back to some basic questions.
When drawing objects on the screen, what is the best mapping mode?
When storing these objects (locations) in a file for sending, printing, and all the other goodies that you can do? What should be the best way to store. Locations. In logical or display?
When inputting text blocks (like edit or rich edit) how do we save the text so that when it is read back into a system that has a smaller resolution that is looks like it did with the bigger?
Any advise would help. Act like I'm a windows newbie (at this point asking these questions, I think I am! )
Thanks fellas
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
for storing the object,I often use CFile class to write into disk,
or use IStorage and IStream.
dupengfei
|
|
|
|
|
Thanks PengFeidu,
I was wondering about the data locations. Do you draw them in MM_TEXT and save the MM_TEXT points or do you change them into logical and save that?
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|
|
This is probably a ridiculously easy question but I can't seem to find the answer in the documentation:
How do you make an application minimize without requiring the user to actually click on the minimize button or the system menu?
|
|
|
|
|
|
i created a dialog1 and a database. the CRecordset class have already been added and member variables added using m->pSet. how to link the dialog1 to the database such that the database dialog will appear when a button in dialog1 is clicked? is there any sample code for database using dialog coz i surf around and found samples for SDI (using formview/recordview) database only.
|
|
|
|
|
I'm unable to determine if you have two dialogs or just one. If two, then the button-click handler on dialog 1 will create an instance of dialog 2 and call its DoModal() method.
If, however, you are trying to associate a CRecordset with a CDialog , here are the steps:
1) Call the recordset's Open() method in the dialog's OnInitDialog() .
2) Create some sort of "UpdateControls" method that updates the dialog's controls with the current CRecordset values.
3) In this "UpdateControls" method, simply call SetWindowText() for each control, like:
m_Name.SetWindowText(m_set.FirstName);<br />
m_Addr.SetWindowText(m_set.Address);<br />
m_State.SetWindowText(m_set.State);
Make sense?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
i am using the following:
BOOL CDLGdb::OnInitDialog()
{
CDialog::OnInitDialog();
m_pSet->Open();
UpdateControls();
return TRUE;
}
void CDLGdb::UpdateControls()
{
m_AddressID.SetWindowText(m_pSet->m_AddressID);
}
i get errors of 'm_AddressID' : undeclared identifier and
left of '.SetWindowTextA' must have class/struct/union type
how to resolve this?
|
|
|
|
|
Is m_AddressID a CEdit control variable?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|