To get the data from a class and use it in a function we have declared that class in the function. Is it the only way to access the class data or is t

  • Thread starter Thread starter David student
  • Start date Start date
D

David student

Guest
Hello All,

The question I am asking is a basic question. Please don't mind as I am a beginner and working on a C++ project.



My requirement is to get the UPS data from the CUPSData class and use it in the WriteUPSDataToRegistry function to write the UPS data into the registry.

To get the data from the class we use that class in the function "WriteUPSDataToRegistry". To access any class data, Do we need to declare that class in a function where we are using or is there any other way?

And also we declared a pointer to the object of a class as a parameter to the function (void WriteUPSDataToRegistry(CEventGenerator *eventGeneratorPtr). My understanding is that this object has all the data members and member functions so that using this class object we can access the data. Is my understanding is correct?

Below is my code snippet:

int main()

{

CEventGenerator eventGenerator;

WriteUPSDataToRegistry(&eventGenerator);

}

void WriteUPSDataToRegistry(CEventGenerator *eventGeneratorPtr)
{

CUPSData * pUPSData = NULL;


eventGeneratorPtr->GetSnapshotHandle(&pUPSData);
assert(pUPSData != NULL);

//Product Name
regObj.Set(APC_TSDATA_UPS_MODEL, pUPSData->theProductName, dwSize);

//Serial Number
dwSize = MAX_PATH;
regObj.Set(APC_TSDATA_UPS_SERIAL_NUMBER, pUPSData->theSerialNumber, dwSize);

//UPS Firmware
dwSize = MAX_PATH;
regObj.Set(APC_TSDATA_UPS_FIRMWARE, pUPSData->theUPSFirmware, dwSize);

}

UPSData.h

class UPSCONTROL_API CUPSData
{
private:

public:

TCHAR theProductName[_MAX_PATH];
TCHAR theSerialNumber[_MAX_PATH];
TCHAR theUSBFirmware[_MAX_PATH];
TCHAR theUPSFirmware[_MAX_PATH];

CUPSData();

}

Thank you in advance.

Continue reading...
 
Back
Top