Archived

This topic is now archived and is closed to further replies.

BergB

How to pass a surface?

Recommended Posts

BergB    122
Hi, I have a question regarding passing DirectDraw Surfaces to a function. For example if I declare a LPDIRECTDRAWSURFACE7 as a variable and I want to pass it to a function, how do I do it correctly? I tried it like this: void foo(LPDIRECTDRAWSURFACE7 lpDDS) and called the function like LPDIRECTDRAWSURFACE7 lpDDSurface; foo(lpDDSurface); and it didn''t really work if I try to do something with the surface in the function. I hope someone can help me with this problem

Share this post


Link to post
Share on other sites
JoeyBlow2    100
A LPDIRECTDRAWSURFACE7 is no different than saying DirectDrawSurface7*

If we change what you said around a bit, it would look like:


void foo(DirectDrawSurface7* lpDDS)
{

lpDDS->Dosomething(); // KABOOM


}



void main(void)
{
DirectDrawSurface7* lpDDSurface;

foo(lpDDSurface);
}


----

The foo function would be taking a pointer which is not initialized. You will need to make sure you do the CreateSurface command on that pointer in order to be able to use it. But otherwise your calling syntax is correct. You are just trying to access a bad pointer.

Share this post


Link to post
Share on other sites
BergB    122
Thanks for your help.

I did initialize it with CreateSurface in a seperate function, but obviously I did a mistake in this function which I didn''t found, so I was thinking the problem was the passing of the surface

Share this post


Link to post
Share on other sites