Jump to content
  • Advertisement
Sign in to follow this  
ProblemBaby

Problem parsing X-files

This topic is 4529 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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!