get IP address by code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 said:
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
 
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).AddressList.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 said:
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).AddressList.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
 
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));

Arnaud
MVP - VC
 
Carl Daniel [VC++ MVP] a écrit :
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
 
Back
Top