[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Help on VC++.NET class

Posted on 2005-05-12
7
Medium Priority
?
342 Views
Last Modified: 2011-09-20
I have tried this class to show the host Ip address here is what it looks like:

.H file
#pragma once

#using <mscorlib.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Net;
using namespace System::Net::Sockets;
using namespace System::Threading;
using namespace System::IO;
using namespace System::Data;

public __gc class IpAddress
{
public:
      IpAddress();
      void getHostIP();
      

};//end IpAddress

.CPP file
IpAddress::IpAddress()
{
      //left blank
}//end MemFun

void IpAddress::getHostIP()
{
      String *hostName = System::Net::Dns::GetHostName();
      IPHostEntry *ipE = System::Net::Dns::GetHostByName(hostName);
      IPAddress *IpA[] = ipE->AddressList;
      String *ip;

      for(int i = 0; i < IpA->Length; i++)
      {
            ip =("{0} : {1}", i, IpA[i]->ToString());
            
      }//end for
      

      
}//end getHostIP MemFunc

I have a form when I load it I want it to call the class getHost Ip method.

on the form1 .h
private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
{
      IpAddress *ipa;
      ipLbl->Text = ipa->getHostIP();
}

but I get this compile error:
error C2664: 'System::Windows::Forms::Control::set_Text' : cannot convert parameter 1 from 'void' to 'System::String __gc *'

Can anyone help?
0
Comment
Question by:fsharer
  • 3
  • 3
7 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13990451
You need something like this:

String IpAddress::getHostIP()
{
     String *hostName = System::Net::Dns::GetHostName();
     IPHostEntry *ipE = System::Net::Dns::GetHostByName(hostName);
     IPAddress *IpA[] = ipE->AddressList;
     String *ip;

     for(int i = 0; i < IpA->Length; i++)
     {
          ip =("{0} : {1}", i, IpA[i]->ToString());
         
     }//end for
     
    return ip;
     
}//end getHostIP MemFunc
0
 

Author Comment

by:fsharer
ID: 13990631
now I have these compile errors:
error C2561: 'IpAddress::getHostIP' : function must return a value
error C2440: 'return' : cannot convert from 'System::String __gc *' to 'System::String'
error C2664: 'System::Windows::Forms::Control::set_Text' : cannot convert parameter 1 from 'void' to 'System::String __gc *'


0
 
LVL 3

Expert Comment

by:mpf1748
ID: 13990907
You need to define your method like this:

String *IpAddress::getHostIP()
{
...
}

jaime_olivares must have unintentionally left the * off in the declaration.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13991037
sorry for the typo, also I notice you have not changed the decaration in class definition:

public __gc class IpAddress
{
public:
     IpAddress();
     String *getHostIP();

};//end IpAddress
0
 

Author Comment

by:fsharer
ID: 13991050
Got these errors now:
display IP class error LNK2022: metadata operation failed (80131187) : Inconsistent method declarations in duplicated types (types: IpAddress; methods: getHostIP): (0x06000002).

display IP class fatal error LNK1215: metadata operation failed (80131130)
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 1000 total points
ID: 13991073
I am not sure but sound like you have 2 versions of the same object or you have are including your .h twice
0
 

Author Comment

by:fsharer
ID: 13991123
On the form1.h would I declare it like this?
private: System::Void Form1_Load(System::Object *  sender, System::EventArgs *  e)
{
      IpAddress *ipA;
      ipLbl->Text = ipA->getHostIP();
}
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question