Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with *&

Status
Not open for further replies.

mlockwood

Programmer
Oct 11, 2000
2
GB

I am an inexperienced C++ programmer and I am trying to interface my code
with a 'developers kit' provided by a commercial software producer. The
support they give is very poor and I am stuck.

I wish to get at some data stored in a Class which is mainly a large
buffer. They provide routinre to access the data but use *& as part of the
declaration. I do not fully understand the implications of this and,
although I have made a number of attempts, I cannot get the code to
compile.

I would be grateful for any help you can give me. Below, I am attaching
the skeleton code I wish to use and a fragment of the header file
published in the developer kit. I am bound not to publish their code so I
have changed names. This may mean I have made the code uncompliable but I
do not think I have changed anything significant. Thank you

Morris Lockwood

Extract from MyModule.cpp
//------------------------------------------------------------------------
---
BOOL CDataPackageHandler::ExtractSymbolNameFromeObject(const CCATPACKET&
Packet)
{
PACKET_FIELD *pPF = new PACKET_FIELD;
if (Packet.FindField(CAT_PFID_SYMBOLNAME, pPF))

// Gives Error message : MyModule.cpp(851) : error C2664: 'int
CCATPACKET::FindField(unsigned short,const struct
CCATPACKET::pACKET_FIELD *& )const ' : cannot convert parameter 2 from
'struct PACKET_FIELD *' to 'const struct CCATPACKET::pACKET_FIELD *&
'

{
CString TestStr = "";
TestStr = Packet.GetDataString(pPF) ;

Gives compiler error message : MyModule.cpp(856) : error C2664:
'GetDataString' : cannot convert parameter 1 from 'struct PACKET_FIELD
*' to 'const struct CCATPACKET::pACKET_FIELD *'

}
return TRUE;
}
//------------------------------------------------------------------------
---


Extract from TheirModule.h
//------------------------------------------------------------------------
---

// Sizes
enum CATSizes
{
CAT_SIZE_PACKET_BUFFER = 3000,
CAT_SIZE_SYMBOL = 20,
CAT_SIZE_DESCRIPTION = 51,
};


// Limits
enum CATLimits
{
CAT_MAX_FIELD_SETTINGS = 30,
CAT_MAX_PACKET_FIELD = 100
};

//------------------------------------------------------------------------
---


// CAT_FIELD
typedef WORD CAT_FIELD;



// Field IDs

#define CAT_FIRST_PFID 0

#define CAT_PFID_SYMBOLNAME 31 //
#define CAT_PFID_DESCRIPTION 62 //
#define CAT_LAST_PFID 337


// List of data types (CAT_PFID_FIELD_TYPE)

typedef BYTE CAT_FIELD_DATA_TYPE;

#define CAT_FIELD_TYPE_NUMERIC 0
#define CAT_FIELD_TYPE_TEXT 1


class AFX_EXT_CLASS CCATPACKET
{
public:


// PACKET Field Data Type
enum PFTYPE
{
PFTYPE_STRING = 2, // String (WORD (string length + 1), string data including null terminator)
};




// Field Info
struct CAT_FIELD_INFO
{
public:
CAT_FIELD_INFO() : FieldStatus(0), DateTimeStatus(0), jDate(0), sTime(0) {};


BYTE FieldStatus;

BYTE DateTimeStatus;
WORD jDate;
DWORD sTime;


};

// PACKET Field
struct CAT_PACKET_FIELD
{
BYTE Status : 4;
BYTE Type : 4;

CAT_FIELD FieldID;

BYTE Data[1];
};


// PACKET
struct CAT_PACKET
{
WORD NumFields;
WORD dwStructSize;

CAT_PACKET_FIELD FieldList[1];
};


public:
struct FieldPosition
{
private:
UINT i;
const CAT_PACKET_FIELD* pPF;


FieldPosition(UINT Index, const CAT_PACKET_FIELD* pPField) { i = Index; pPF = pPField; };

public:
FieldPosition() { i=0; pPF = NULL; };
FieldPosition(const int& nNull) { ASSERT(nNull == NULL); i=0; pPF = NULL; };
FieldPosition(const FieldPosition& pos) { i = pos.i; pPF = pos.pPF; };

FieldPosition& operato
r=( const FieldPosition& pos) { if (*this == pos) return *this; i =
pos.i; pPF = pos.pPF; return *this; };
FieldPosition& operator=( const int& nNull ) { ASSERT(nNull ==
NULL); i=0; pPF = NULL; return *this; };
BOOL operator==( const FieldPosition& pos ){ return i==pos.i &&
pPF==pos.pPF; };
BOOL operator==( const int& nNull ) { ASSERT(nNull ==
NULL); return pPF==NULL; };
BOOL operator!=( const int& nNull ) { ASSERT(nNull ==
NULL); return pPF!=NULL; };

friend class CCATPACKET;
};

public:
CCATPACKET(UINT unSameSizeBufferSize, UINT unVersion); //uses the same
size allocator. Only use for CSnapshot
CCATPACKET(CAT_PACKET* pPACKET);
CCATPACKET(char Buffer[], WORD wBufferSize);
CCATPACKET(WORD wBufferSize = CAT_SIZE_PACKET_BUFFER);
~CCATPACKET();

static void Init(); //USED FOR THE SAME SIZE ALLOCATOR.
static void UnInit();

void Empty();

CAT_FIELD_INFO GetFieldInfo(CAT_FIELD FieldID) const;
CAT_FIELD_INFO GetFieldInfo(const CAT_PACKET_FIELD* pPF) const;
void GetFieldData(CAT_FIELD FieldID, double &Data) const;

FieldPosition GetHeadPosition() const;
const CAT_PACKET_FIELD* GetNext(FieldPosition& pos) const;

UINT GetNumField() const;
WORD GetSize() const;
BOOL FindField(CAT_FIELD FieldID, const CAT_PACKET_FIELD*& pPF)
const;
const CAT_PACKET_FIELD* FindField(CAT_FIELD FieldID, const
CAT_PACKET_FIELD*& pPFStart, int& nIndex) const;
const CAT_PACKET* GetCAT_PACKET() const;


BYTE* GetBuffer(UINT Size);
void ReleaseBuffer();


void Serialize(CArchive& ar);


BOOL AddField(const CAT_PACKET_FIELD* pPF);
BOOL AddField(const CAT_PACKET_FIELD* pPF, const CAT_PACKET_FIELD*&
pPFAdded);
BOOL AddField(BYTE Status, BYTE DataType, CAT_FIELD FieldID, void*
pData, DWORD dwDataSize);
BOOL AddFieldString(BYTE Status, CAT_FIELD FieldID, LPCSTR szString);
BOOL AddFieldString(BYTE Status, CAT_FIELD FieldID, LPCSTR szString,
WORD Len);
WORD GetBufferSize() { return m_wBufferSize; };
CCATPACKET& operator=(const CAT_PACKET& PACKET);

void GetString(CString& strVal);

static BOOL FindField(const CAT_PACKET& PACKET, CAT_FIELD FieldID,
const CAT_PACKET_FIELD*& pPF);
static const
CAT_PACKET_FIELD* FindField(const CAT_PACKET& PACKET, CAT_FIELD FieldID,
const CAT_PACKET_FIELD*& pPFStart, int& nIndex);

static LPCSTR GetFieldName(const CAT_PACKET_FIELD* pPF);
static CString GetDataString(const CAT_PACKET_FIELD* pPF);
static CString GetTypeString(const CAT_PACKET_FIELD* pPF);

static UINT GetDataSize(const CAT_PACKET_FIELD* pPF);
static UINT GetDataSize(BYTE DataType, void* pData);
static UINT GetFieldDataSize(const CAT_PACKET_FIELD* pPF);
static UINT GetFieldDataSize(BYTE DataType, void* pData);
static UINT GetFieldSize(const CAT_PACKET_FIELD* pPF);

[sig][/sig]
 
Dear Morris,

Try declaring as follows in your module
Extract from MyModule.cpp

//----------------------------------------------------------
BOOL CDataPackageHandler::ExtractSymbolNameFromeObject(const CCATPACKET&
Packet)
{
// Old Code
// PACKET_FIELD *pPF = new PACKET_FIELD;

// New Code
CCATPACKET::pACKET_FIELD *pPF = new CATPACKET::pACKET_FIELD;
...
//----------------------------------------------------------


In their routines which are declared as "const X *&" means

that the function takes a "const reference to a pointer to X".

Cheers,
Manjunath P S
[sig]<p>P S Manjunath<br><a href=mailto:manjunath.ps@chennaimail.ltitl.com>manjunath.ps@chennaimail.ltitl.com</a><br><a href= > </a><br> [/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top