P. Avery
P. Avery

Reputation: 809

Initializing a const GUID * (GUID pointer)

I'm trying to initialize a GUID pointer to NULL values for use with DirectX...I'm writing an .X file parser.

I'm having trouble initializing a GUID pointer! I need to compare the input GUID type from file with the internally defined Template types so that I can tell my program what to do with the information within the 'template from file.'

Here is what I have so far:

BOOL cXMeshParser::ParseObject(LPD3DXFILEDATA pDataObj, DWORD Depth, void **data)
{

    if(pDataObj->IsReference())
        return true;

    GUID pTemplateGUID;
    memset(&pTemplateGUID, 0, sizeof(GUID));

    GUID *pCpyGUID;
    memset(&pCpyGUID, 0, sizeof(GUID));

    memcpy(&pCpyGUID, &pTemplateGUID, sizeof(GUID));

    pDataObj->GetType(pCpyGUID);
    int isEqual =0;
    isEqual = IsEqualGUID(*pCpyGUID, TID_D3DRMMesh);
    if(isEqual){

           ...
         }
}

when I run the debugger, the data within the pCpyGUID is incorrect(not NULL)

I used a regular GUID def(GUID pTemplateGUID) to try and copy the GUID to const GUID* (I am able to inizialize GUID ... not GUID*)...the current problem with the parser is that the comparison between template data and internal definition cannot be assessed...

My question is:

How do I write a valid initialization for a const GUID* ?

Upvotes: 0

Views: 719

Answers (1)

Asaf
Asaf

Reputation: 4407

pCpyGUID is just a pointer, which means its value is an address. Since you did not initialize this address, it points to some random memory location, which can be non-readable and non-writable.

In any case, you also zero pTemplateGUID, and then try to copy it to pCpyGUID...

It looks like you don't need both pTemplateGUID and pCpyGUID.

You probably wanted to do:

GUID *pCpyGUID = &pTemplateGUID;

So pCpyGUID points to pTemplateGUID. But you don't need this.

Try this:

GUID templateGUID;

pDataObj->GetType(&templateGUID);
int isEqual = IsEqualGUID(templateGUID, TID_D3DRMMesh);
if(isEqual){
 ...

Upvotes: 2

Related Questions