Sign in to follow this  
NegativeGeForce

LPDIRECTDRAW7 cant pass by reference?

Recommended Posts

Hey im making a surface creation function, and Im having issues with the pointer not wanting to pass by reference, any other LP variables like surfaces pass with no issues. Was directx designed this way? This is what I get... error C2664: 'DD_Make_Surface' : cannot convert parameter 3 from 'LPDIRECTDRAW7 *__w64 ' to 'LPDIRECTDRAW7' This is my function call...
figure.frame[figure.counter] = DD_Make_Surface( 68, 100, &lpdd, 0, 0 );


Is there ANY way to make the LPDIRECTDRAW7 pointer global or able to pass into functions by reference? I tried by value, and the program crashes...probably because its being copied and im trying to make a surface on a interface that doesnt exist or is valid. Any help is appreciated

Share this post


Link to post
Share on other sites
9.0 Summer 2003

heres the definition

LPDIRECTDRAWSURFACE7 DD_Make_Surface( int x, int y, LPDIRECTDRAW7 lpdd, int flags, int transparant = 0){
DDSURFACEDESC2 ddsd;
LPDIRECTDRAWSURFACE7 lpdds;
memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | flags;
ddsd.dwWidth = x;
ddsd.dwHeight = y;

lpdd->CreateSurface( &ddsd, &lpdds, NULL );

DDCOLORKEY color;
color.dwColorSpaceHighValue = 0;
color.dwColorSpaceLowValue = 0;

lpdds->SetColorKey( DDCKEY_SRCBLT, &color );

return(lpdds);
}

Share this post


Link to post
Share on other sites
like normally LPDIRECTDRAW7 lpdd. Its already a pointer...it wouldnt make a difference how I declare it right? Im confused that when i use the dereference operator it wont pass it, but on any other LP types it works fine.

Share this post


Link to post
Share on other sites
Quote:
Original post by Jedite
Hmm.. try adding this after u use memset...

ddsd.dwSize = sizeof(ddsd);


O CRAP! =-o

OK that was the problem! OH MAN I totally forgot about that! I guess that makes sense since im giving the wrong size of the ddsd structure! OMG thanks!

OH. One more thing. Why do i need to use the defreference operator (&) with some LP types? for example:


lpdd->CreateClipper( 0 , &lpddclipper, NULL);


Share this post


Link to post
Share on other sites
I havent read over it verywell. I would check out the SDk it will probably have info on why it needs it that way. Might be that it may change the address of the pointer if needed .. but thats just speculation..

Oh and no problem with the help.. anything else just let me know

Share this post


Link to post
Share on other sites
When you pass LPDIRECTDRAW Like that when you return it it will be by value so it won't change anything it would be best if you do LPDIRECTDRAW* then when you return it you will get the address instead

Share this post


Link to post
Share on other sites
Quote:
Original post by Jedite
OH. One more thing. Why do i need to use the defreference operator (&) with some LP types?


That's not the dereference operator. In that case, it's the address-of operator, and it returns the memory location of the variable you are trying to take the address of (in that case lpddclipper).

The straight up answer as to why you need to do that is because CreateClipper requires an LPDIRECTDRAWCLIPPER* (a pointer to a pointer type, e.g., int**) rather than just an LPDIRECTDRAWCLIPPER (just a pointer type).

The reason as to why many DirectX functions and methods require a pointer to a pointer type has to do with the fact that passing a pointer regularly passes the actual pointer variable by value, just like any other data type. If things like LPDIRECTDRAW7 (a pointer to a DirectDraw7 COM object) were passed by value to, say, DirectDrawCreateEx (function which initializes DirectDraw7), the pointer received by DirectDrawCreateEx would be set to point to a DirectDraw7 object, but the LPDIRECTDRAW7 pointer in the original calling function would not point to same location (because it was passed by value). By passing a pointer to the LPDIRECTDRAW7 pointer (or any other DirectX function that requires a pointer to a pointer type), the DirectX functions can modify the original pointer in the calling function and set it correctly.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this