LPDIRECTDRAWSURFACE question

Started by
2 comments, last by while1 22 years, 2 months ago
I have a little problem with the LPDIRECTDRAWSURFACE7 type. Look at this:
  

class MySurf
{
  MySurf(LPDIRECTDRAWSURFACE7 p_tSurf) {m_tSurf = p_tSurf}; 
  LPDIRECTDRAWSURFACE7 m_tSurf;
};

std::vector<MySurf*> g_aArray;

  
Now in the main function should I do like this:
  

void main()
{
  LPDIRECTDRAWSURFACE* l_ptSurf;
  MySurf* l_pNewSurf = new MySurf(l_ptSurf);
  g_aArray.push_back(l_pNewSurf);
}

  
or like this:
  

void main()
{
  LPDIRECTDRAWSURFACE l_tSurf;
  MySurf* l_pNewSurf = new MySurf(&l_tSurf);
  g_aArray.push_back(l_pNewSurf);
}

  
Advertisement
The problem is that you need to initialize the LPDIRECTDRAWSURFACE that you pass to the constructor, or create the surface inside the constructor. Use CreateSurface to create the surface; it will return an LPDIRECTDRAWSURFACE that you can use in your class.

So, you could do something like this:

  void main({  LPDIRECTDRAWSURFACE* l_ptSurf;  DDSURFACEDESC       ddsd;  HRESULT             ddreturn;  //  Create the surface as offscreen, system memory  //   (not video memory).  //  Assumes ''ddobj'' points to direct draw object.  ddsd.dwSize = sizeof(ddsd);  ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;  ddsd.ddsCaps.dwCaps =   DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY;  ddsd.dwHeight = Height;  // Surface height  ddsd.dwWidth  = Width;   // Surface width  ddreturn = ddobj->CreateSurface(&ddsd, &l_ptSurf, NULL);  if (ddreturn != DD_OK)	exit(1);   // Couldn''t create surface  MySurf* l_pNewSurf = new MySurf(l_ptSurf);  g_aArray.push_back(l_pNewSurf);}  
MySurf takes a pointer to DirectDraw surface, not a pointer to pointer, so either way would be wrong.

I haven''t used DirectDraw that much, but I would guess that simple pointer would do. So second option would be correct, except you shouldn''t use & in front of l_tSurf, when creating MySurf.

So you would write:

void main()
{
LPDIRECTDRAWSURFACE l_tSurf;
/* create surface here, or do what you want... */
MySurf* l_pNewSurf = new MySurf(l_tSurf);
g_aArray.push_back(l_pNewSurf);
}

OldGuy:

Is that an error, or does CreateSurface() really take a pointer to pointer to pointer as a second argument? Wow!
Sorry, it was a typo on my part; I copied the declaration of the LPDIRECTDRAWSURFACE from the original. It should be declared as ''LPDIRECTDRAWSURFACE'', not ''LPDIRECTDRAWSURFACE *''.

This topic is closed to new replies.

Advertisement