473,513 Members | 10,313 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get IP address by code

hi, i tried migrating my VB.net code to get the computers IP address to C++
and it doesnt work, so im wonderign if anyone knows how to do it in
C++.net...thanks
--
-iwdu15
Jan 6 '06 #1
5 2195
"iwdu15" <jmmgoalsteratyahoodotcom> wrote in message
news:6C**********************************@microsof t.com...
hi, i tried migrating my VB.net code to get the computers IP address to
C++
and it doesnt work, so im wonderign if anyone knows how to do it in
C++.net...thanks


What did you do in VB.Net? You should be able to do tha same things with
either Managed C++ (VS2003) or C++/CLI (VS2005).

On the other hand, if your migration was to native C++ under Win32, you will
likely need to make use of a completely different set of services.

If you are thinking to yourself - "Great, Will. That's none too specific to
help me" - then you'd be right. To get good advice you need to explain a
little more about what you want or how what you tried failed.

Regards,
Will

Jan 6 '06 #2
my mistake, sorry about that... heres howi tried it in vb:

''Global Var
Dim homeip As IPAddress

''In form load
homeip =
Net.Dns.GetHostByName(Net.Dns.GetHostName).Address List.GetValue(0)

in C++ i tried:

//Global Var
System::Net::IPAddress * homeip;

''in formload
homeip =
Net::Dns::GetHostByName(Net::Dns::GetHostName())->AddressList->GetValue(0);

it throws this build error

c:\Documents and Settings\User\Desktop\Final_Project\Final
Project\Final\Form1.h(4029): error C2440: '=' : cannot convert from
'System::Object __gc *' to 'System::Net::IPAddress __gc *'

let me kno if u need anymore info
--
-iwdu15
Jan 6 '06 #3
iwdu15 wrote:
my mistake, sorry about that... heres howi tried it in vb:

''Global Var
Dim homeip As IPAddress

''In form load
homeip =
Net.Dns.GetHostByName(Net.Dns.GetHostName).Address List.GetValue(0)

in C++ i tried:

//Global Var
System::Net::IPAddress * homeip;

''in formload
homeip =
Net::Dns::GetHostByName(Net::Dns::GetHostName())->AddressList->GetValue(0);

it throws this build error

c:\Documents and Settings\User\Desktop\Final_Project\Final
Project\Final\Form1.h(4029): error C2440: '=' : cannot convert from
'System::Object __gc *' to 'System::Net::IPAddress __gc *'


Try this:

homeip = (System::Net::IPAddress
*)Net::Dns::GetHostByName(Net::Dns::GetHostName())->AddressList->GetValue(0);

VB.NET automatically inserts a cast for you, C++ does not.

-cd
Jan 6 '06 #4

Carl Daniel [VC++ MVP] a écrit :
iwdu15 wrote:
my mistake, sorry about that... heres howi tried it in vb:

''Global Var
Dim homeip As IPAddress

''In form load
homeip =
Net.Dns.GetHostByName(Net.Dns.GetHostName).Address List.GetValue(0)

in C++ i tried:

//Global Var
System::Net::IPAddress * homeip;

''in formload
homeip =
Net::Dns::GetHostByName(Net::Dns::GetHostName())->AddressList->GetValue(0);

it throws this build error

c:\Documents and Settings\User\Desktop\Final_Project\Final
Project\Final\Form1.h(4029): error C2440: '=' : cannot convert from
'System::Object __gc *' to 'System::Net::IPAddress __gc *'


Try this:

homeip = (System::Net::IPAddress
*)Net::Dns::GetHostByName(Net::Dns::GetHostName())->AddressList->GetValue(0);


Or better :

homeip=__try_cast<System::Net::IPAddress*>
(Net::Dns::GetHostByName(Net::Dns::GetHostName())->AddressList->GetValue(0));

Arnaud
MVP - VC

Jan 6 '06 #5
<ad******@club-internet.fr> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
Carl Daniel [VC++ MVP] a écrit :
Try this:

homeip = (System::Net::IPAddress
*)Net::Dns::GetHostByName(Net::Dns::GetHostName())->AddressList->GetValue(0);


Or better :

homeip=__try_cast<System::Net::IPAddress*>
(Net::Dns::GetHostByName(Net::Dns::GetHostName( ))->AddressList->GetValue(0));


Yep, that's better - always prefer the new cast syntax so the intent and
behavior of the cast is apparent.

-cd
Jan 6 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4574
by: YAN | last post by:
Hi, I want to get the mac address from a machine, which i have the IP address of that machine, how can i do that? I know how to get the mac address of the local machine from the following code: ...
12
2439
by: johny smith | last post by:
I am trying to figure out a way to print the address of what called a certain function once inside the function. I am assuming that this information is on the stack somewhere. But can someone...
22
2422
by: ypjofficial | last post by:
Hello All, While readling the C and C++ literature i came to know that the OS allocates separate protected memory space for each running program and the program do not interfare into one another's...
4
5494
by: Tom Warren | last post by:
About once a year or so for the last 10 years, I update my street address parser and I'm starting to look at it again. This parser splits a street address line into its smallest common elements...
11
4134
by: farqs | last post by:
I've got a form with feilds: Address, Suburb, State, Pcode (for the Location Addres) and then: PAddress, PSuburb, PState, PPcode (for the Postal Address). When the postal address is the same as...
35
10740
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
81
3149
by: candy | last post by:
hi all, Is there is any way in the C language by which I can get the address of a statement? For eg,consider the following simple program: 1. #include<stdio.h> 2. 3. int main(void){ 4. ...
6
5015
by: Todd A. Anderson | last post by:
I have a function foo of which I need to get the address. The problem is that when you say "&foo" (or just foo for that matter), you get the address of this function's entry in a jump table and...
5
1985
by: kumarsssss | last post by:
I have just new to degugger. It shows the data registers and address registers. Data registers contatin the data values for the different variables. But what the address registers holds? Does...
1
3109
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.