• Advertisement
Sign in to follow this  

Problem parsing X-files

This topic is 4251 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to retrieve the data from an X-file. What I want to know is when I know the type of data how do I get the data. the documentation is poor. Here is the code:
	IDirectXFile *pDXFile = NULL;
	IDirectXFileEnumObject *pDXEnum = NULL;
	IDirectXFileData *pDXData = NULL;
	int nResult;

	if (FAILED(DirectXFileCreate(&pDXFile)))
		return -1;

	if (FAILED(pDXFile->RegisterTemplates((LPVOID)D3DRM_XTEMPLATES, D3DRM_XTEMPLATE_BYTES)))
	{
		pDXFile->Release();
		return FALSE;
	}

	if (FAILED(pDXFile->CreateEnumObject((LPVOID)szFileName, DXFILELOAD_FROMFILE, &pDXEnum)))
	{
		pDXFile->Release();
		return FALSE;
	}


	nResult = 1;
	while (SUCCEEDED(pDXEnum->GetNextDataObject(&pDXData)) && nResult)
	{
		nResult = GetData(pDXData);
		pDXData->Release();
		pDXData = NULL;
	}

	pDXEnum->Release();
	pDXFile->Release();

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

int GetData(IDirectXFileData *pDXData)
{
	IDirectXFileObject *pDXObject = NULL;
	IDirectXFileDataReference *pDXReference = NULL;
	IDirectXFileData *pDXSubData = NULL;

	const GUID *Type = NULL;

	pDXData->GetType(&Type);


	if (*Type == TID_D3DRMMesh)
	{	
	// DOESNT GIVE CORRECT DATA!

		DWORD dwSize = 4;
		DWORD Buffer[16];

		memset(Buffer, 0, 16 * 4);

		pDXData->GetData(NULL, &dwSize, (void **)&Buffer);

		printf("Mesh\n");
		printf("%d\n", Buffer[0]);

	}

	while(SUCCEEDED(pDXData->GetNextObject(&pDXObject)))
	{
		// Process embedded references
		if(SUCCEEDED(pDXObject->QueryInterface(IID_IDirectXFileDataReference, (void **)&pDXReference)))
		{
			if(SUCCEEDED(pDXReference->Resolve(&pDXSubData)))
			{
				GetData(pDXSubData);
				pDXSubData->Release();
				pDXSubData = NULL;
			}
			pDXReference->Release();
			pDXReference = NULL;
		}

		// Process non-referenced embedded templates
		if(SUCCEEDED(pDXObject->QueryInterface(IID_IDirectXFileData, (void **)&pDXSubData)))
		{
			GetData(pDXSubData);
			pDXSubData->Release();
			pDXSubData = NULL;
		}
		pDXObject->Release();
		pDXObject = NULL;
	}


	return 1;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement