Skip to main content
GameDev.net gamedev.net
🔒 Locked

Having trouble with pointers

Started by Sagar_Indurkhya Jan 14, 2005 at 9:54 PM 3 replies 1.3k views
Original Post
Sagar_Indurkhya
Sagar_Indurkhya
First, I know this should be in the Directx Forum, but I think the problem has to do with pointers, not directx. I have a class Mesh. It can load, render, and dispose of meshes. Here is the code: mesh.h

#pragma once
#include <d3dx9.h>

class Mesh
{
public:
	Mesh(string FileName, LPDIRECT3DDEVICE9* pDevice);
	~Mesh(void);

	// Loads a mesh from an X File
	bool LoadMeshFromFile(LPCTSTR fileName);
	// Render's this mesh
	void Render(void);

private:
	LPD3DXMESH              pMesh; // Our mesh object in sysmem
	D3DMATERIAL9*           pMeshMaterials; // Materials for our mesh
	LPDIRECT3DTEXTURE9*     pMeshTextures; // Textures for our mesh
	DWORD                   dwNumMaterials;   // Number of mesh materials
	LPDIRECT3DDEVICE9*		Device;
};

mesh.cpp

#include "StdAfx.h"
#include "mesh.h"
#include <strsafe.h>
#include <string>

using namespace std;

Mesh::Mesh(string FileName, LPDIRECT3DDEVICE9* pDevice) : pd3dDevice(NULL)
{
	if(Device != NULL)
	{
		Device = pDevice;
		LoadMeshFromFile(LPCTSTR(FileName.c_str()));
	}
}

Mesh::~Mesh(void)
{
}

// Loads a mesh from an X File
bool Mesh::LoadMeshFromFile(LPCTSTR fileName)
{
	//Ommited, because it works, and is not source of error
}

// Render's this mesh
void Mesh::Render(void)
{
	// Meshes are divided into subsets, one for each material. Render them in
	// a loop
	for( DWORD i = 0; i < dwNumMaterials; i++ )
	{
		// Set the material and texture for this subset
                // ERROR ERROR ERROR ERROR ERROR ERROR
		Device->SetMaterial( &pMeshMaterials );    
		pd3dDevice->SetTexture( 0, pMeshTextures );

		// Draw the mesh subset
		pMesh->DrawSubset( i );
	}
}

so those two lines near the bottom, right below where it says "ERROR", this is where I am getting it. error C2227: left of '->SetMaterial' must point to class/struct/union error C2227: left of '->SetMaterial' must point to class/struct/union I think I am doing it right, but i guess not. Anyone got any idea what is going on?
darookie
darookie
In your header:
// wrong type - LPDIRECT3DDEVICE9 already is a pointer.LPDIRECT3DDEVICE9*		Device;


Correct code:
LPDIRECT3DDEVICE9	Device;


Regards,
Pat.

[edit]
Note: MS APIs seem to prefix their type macros with LP (which stands for Long Pointer, IIRC), so if you ever stumble across an LP-prefixed type, you can be sure it's a pointer.
[/edit]
Sagar_Indurkhya
Sagar_Indurkhya
Thanks!

For future reference, how can I figure out if something like that is a pointer though?
darookie
darookie
You can let the mouse pointer hover the variable. With VC 7.x the variable type will be displayed in form of a tooltip then.
Drew_Benton
Drew_Benton
Quote:
Original post by Sagar_Indurkhya
Thanks!

For future reference, how can I figure out if something like that is a pointer though?


Another thing is that DirectX uses Hungarian notation - so anyone at any time can be given a variable and know what type it is.

LPDIRECT3DDEVICE9 => 'LP' means pointer, 'DIRECT3DDEVICE' describes the the of variable, and '9' tells the version. If you read up on some of the other hungarian notation, you can find a lot of neat stuff! As another note - h means handle - as in hwnd, hinstance, etc... As for one more explanation D3DMATERIAL9 => just is verions '9' of the D3DMATERIAL class. I hope this helps some.

- Drew

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.