🔒 Locked
Error in DDraw wrapper
Advertisement
Original Post
I have a problem when making my directdraw wrapper. I´m using an object oriented design and I have a surface class to handle all about ddraw surfaces. It has a directdrawsurface PRIVATE variable, a LPDIRECTDRAWSURFACE4 variable.I have a method called Get() to return it. I my DirectDraw class, to handle the interface IDIRECTDRAW4 I have 2 private variables that are pointers to the surface class, the front and back buffers.
The problem is when I need a pointer to the front buffer to call CreateSurface() or GetAttachedSurface().I try to do something like: &surface->get()and I get this error: & requires l-value. I´ve tried to fix it by putting parenthesis these ways:
&(surface->Get()) and
(&(surface->Get())) but it´s not fixed.
I hope I´ve explained it understandable!
Please help!
What the hells!
what does the variable surface represent.
Post some code up here to look at.
Post the .h files for both of the classes
"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions
Post some code up here to look at.
Post the .h files for both of the classes
"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions
I know this isn''t entirely going with the encapsulation flow of things, but have you considered making the surfaces, etc.. public? It''s probably make things easier.
Post your code anyway, that''ll be the easiest way for someone to tell you what''s wrong.
-----------------------------------------------------------------
I''m a lumberjack and I''m OK,
I sleep all night and I work all day,
I cut down trees, I wear high heels, suspenders and a bra,
I put on womens'' clothing, and hang around in bars.
Monty Python.
Post your code anyway, that''ll be the easiest way for someone to tell you what''s wrong.
-----------------------------------------------------------------
I''m a lumberjack and I''m OK,
I sleep all night and I work all day,
I cut down trees, I wear high heels, suspenders and a bra,
I put on womens'' clothing, and hang around in bars.
Monty Python.
The variable surface inside the surface class is the surface in itself, let me explain... I have the class that represents the surface, so it has variables such width, height and methods to blit it... The variable that is the LPDIRECTDRAWSURFACE4 itself is what I called the variable surface.
The class so far(At early work, but I have most of it already without an OO design):
class CDirectDraw;
////////
class CDirectSurface
{
public:
LPDIRECTDRAWSURFACE4 Get() const {return _lpdds;};
CDirectSurface();
CDirectSurface(CDirectDraw * owner,int width, int height, int flags=DDSCAPS_SYSTEMMEMORY);
CDirectSurface(CDirectDraw * owner,char * filename, int flags=DDSCAPS_SYSTEMMEMORY);
CDirectSurface(CDirectDraw * owner,CDirectSurface *cds,int flags=DDSCAPS_SYSTEMMEMORY);
virtual ~CDirectSurface();
private:
void _InitVar();
BOOL _CreateOffScreen(int width,int height,int flags=DDSCAPS_SYSTEMMEMORY);
static CDirectDraw * _owner;
LPDIRECTDRAWSURFACE4 _lpdds;
int _height;
int _width;
};
The call in the directdraw class:
if(FAILED(_lpdd->CreateSurface(&ddsd,&lpddsfront->Get(),NULL)))
What the hells!
The class so far(At early work, but I have most of it already without an OO design):
class CDirectDraw;
////////
class CDirectSurface
{
public:
LPDIRECTDRAWSURFACE4 Get() const {return _lpdds;};
CDirectSurface();
CDirectSurface(CDirectDraw * owner,int width, int height, int flags=DDSCAPS_SYSTEMMEMORY);
CDirectSurface(CDirectDraw * owner,char * filename, int flags=DDSCAPS_SYSTEMMEMORY);
CDirectSurface(CDirectDraw * owner,CDirectSurface *cds,int flags=DDSCAPS_SYSTEMMEMORY);
virtual ~CDirectSurface();
private:
void _InitVar();
BOOL _CreateOffScreen(int width,int height,int flags=DDSCAPS_SYSTEMMEMORY);
static CDirectDraw * _owner;
LPDIRECTDRAWSURFACE4 _lpdds;
int _height;
int _width;
};
The call in the directdraw class:
if(FAILED(_lpdd->CreateSurface(&ddsd,&lpddsfront->Get(),NULL)))
What the hells!
I fixed it! Or at least the compiler doesn´t give me any error...
I´ve changed the call from the directdraw class to:
if(FAILED(_lpddsfront->Get()->GetAttachedSurface(&ddsd.ddsCaps,(LPDIRECTDRAWSURFACE4*)_lpddsback->Get() )))
Is this right? I´m not very sure cause I understand it as casting the pointer to LPDIRECTDRAWSURFACE4 returned from Get() to the same,but it doesn´t do that, does it?
If I read that code I´d say that the second parameter isn´t different from just _lpddsback->Get(), and this gives me error.
I should read again about typecasting..
Please reply to say if this is right or wrong!
What the hells!
I´ve changed the call from the directdraw class to:
if(FAILED(_lpddsfront->Get()->GetAttachedSurface(&ddsd.ddsCaps,(LPDIRECTDRAWSURFACE4*)_lpddsback->Get() )))
Is this right? I´m not very sure cause I understand it as casting the pointer to LPDIRECTDRAWSURFACE4 returned from Get() to the same,but it doesn´t do that, does it?
If I read that code I´d say that the second parameter isn´t different from just _lpddsback->Get(), and this gives me error.
I should read again about typecasting..
Please reply to say if this is right or wrong!
What the hells!
It's because you've declared Get() constant. Get, therefore, returns a 'const LPDIRECTDRAWSURFACE4', rather than the 'LPDIRECTDRAWSURFACE4' that the _CreateOffscreen function prototype requires (probably). By casting the former to the latter, you hide the problem, not fix it.
But this is wrong. The whole point of const is that anything you return isn't modified by anything that receives it, which you are bypassing. You might want to make Get inline, though.
That is:
Doing this makes the function both const-correct (in that it's not constant, which is correct in this case), and it will perform quicker, because the compiler will directly replace the call to Get() - which returns _lpdds - with the value of _lpdds, saving cycles. Such is the benefit of inline. This works despite _lpdds being private, by the way.
TheTwistedOne
http://www.angrycake.com
Edited by - TheTwistedOne on July 11, 2000 5:27:42 AM
But this is wrong. The whole point of const is that anything you return isn't modified by anything that receives it, which you are bypassing. You might want to make Get inline, though.
That is:
inline LPDIRECTDRAWSURFACE4 Get() { return _lpdds; }
Doing this makes the function both const-correct (in that it's not constant, which is correct in this case), and it will perform quicker, because the compiler will directly replace the call to Get() - which returns _lpdds - with the value of _lpdds, saving cycles. Such is the benefit of inline. This works despite _lpdds being private, by the way.
TheTwistedOne
http://www.angrycake.com
Edited by - TheTwistedOne on July 11, 2000 5:27:42 AM
Thank you The Twisted One for helping. I don´t understand very well what is a const LPDIRECTDRAWSURFACE4, CreateOffScreen uses a regular LPDIRECTDRAWSURFACE4...
.-I now realize about my bad using of const.
.-Get() is implemented is the class definition, so it´s inline...
.-I get the same error if a don´t set it as const:& requires l-value...
.-Can´t do this: &_lpdds->Get() to get a pointer to LPDIRECTDRAWSURFACE4, so it´s a pointer to a pointer...How can I get the pointer´s address with my design?
.-Thank you for reading this, if you can please help me!
What the hells!
.-I now realize about my bad using of const.
.-Get() is implemented is the class definition, so it´s inline...
.-I get the same error if a don´t set it as const:& requires l-value...
.-Can´t do this: &_lpdds->Get() to get a pointer to LPDIRECTDRAWSURFACE4, so it´s a pointer to a pointer...How can I get the pointer´s address with my design?
.-Thank you for reading this, if you can please help me!
What the hells!
I don''t have my DirectX code available at the moment, because I''m at work.
I''ve looked at the DirectX7 SDK help (because it''s in the standard MSDN Library as of April this year. Woohoo) and see that while my comments on const were correct, they don''t help in this case, because the problem is something else.
I''ve done something very similar in my own DirectDraw wrapper, anyway, so I should be able to point you in the right direction later.
TheTwistedOne
http://www.angrycake.com
I''ve looked at the DirectX7 SDK help (because it''s in the standard MSDN Library as of April this year. Woohoo) and see that while my comments on const were correct, they don''t help in this case, because the problem is something else.
I''ve done something very similar in my own DirectDraw wrapper, anyway, so I should be able to point you in the right direction later.
TheTwistedOne
http://www.angrycake.com
Thank you very much for helping me,The Twisted One!
I have a surface class with a LPDIRECTDRAWSURFACE4 private variable and a method, Get(), wich returns the LPDIRECTDRAWSURFACE4 . How can I take a pointer to it? The normal way is to use &, but I cannot write the sentence without getting:& requires l-value. It should be something like:
if(FAILED(_lpdd->CreateSurface(&ddsd,&_lpddsfront->Get(),NULL)))
{
//ERROR
}
How can I write the & _lpddsfront->Get()sentence to be right?
Thank you for reading this!
What the hells!
I have a surface class with a LPDIRECTDRAWSURFACE4 private variable and a method, Get(), wich returns the LPDIRECTDRAWSURFACE4 . How can I take a pointer to it? The normal way is to use &, but I cannot write the sentence without getting:& requires l-value. It should be something like:
if(FAILED(_lpdd->CreateSurface(&ddsd,&_lpddsfront->Get(),NULL)))
{
//ERROR
}
How can I write the & _lpddsfront->Get()sentence to be right?
Thank you for reading this!
What the hells!
Oh. Tsk. I just looked at my code. I must''ve had the same problem, and not been able to fix it.
In the end, my DirectDraw wrapper is a ''friend'' of my DirectDrawSurface wrapper, so it has direct access to the private IDirectDrawSurface7* member variable.
I had a similar idea to Anon earlier, though, except it was more like
As you''re passing a pointer to the pointer into CreateSurface, it should still work. Unfortunately, you lose a bit of performance because of the pointer assignment that''s involved, but you shouldn''t really be creating surfaces the whole time anyway.
Sorry I can''t help more at the moment.
TheTwistedOne
http://www.angrycake.com
In the end, my DirectDraw wrapper is a ''friend'' of my DirectDrawSurface wrapper, so it has direct access to the private IDirectDrawSurface7* member variable.
I had a similar idea to Anon earlier, though, except it was more like
LPDIRECTDRAWSURFACE4* pSurface = _lpddsfront->Get();
_lpdd->CreateSurface(&ddsd, &pSurface, NULL);
As you''re passing a pointer to the pointer into CreateSurface, it should still work. Unfortunately, you lose a bit of performance because of the pointer assignment that''s involved, but you shouldn''t really be creating surfaces the whole time anyway.
Sorry I can''t help more at the moment.
TheTwistedOne
http://www.angrycake.com
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement