Jump to content
  • Advertisement


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


dx c++ question

This topic is 6064 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I program in Vb and this pointer stuff is quite difficut to deal with. Is every directdraw surface a pointer? (Why?). also i was looking over one of the .h files where i think it was declaring functions in it would have something like: DirectDrawSurface7* DDCreate(....) ok i dont have the source code in front of me but my question is why the * after the 1rst part. when i learnt c i leaned that you could declare function with paramiters like int main or void this_function but what is the purpose of this? i know if vb you could declare a function a certain value so that it returned a value to the calling function. so is that what this is and why declare it as a DirectDraw...*? and why the star? is it required. Also in the same vein what is HRESULT? it was used in the same manor to declare a function. is this really necessary? if so then why? Thanks

Share this post

Link to post
Share on other sites
The star means that it is a pointer to that type of object.

This is quicker than passing the actual object around.

And yes, for the most part, all surfaces are dealt this using pointers to that surface.

Here''s a hint for you...any variable type that starts with ''LP'' is really a pointer...but you know what...don''t worry about it.

Wait, wait, wait....who''s Nambla Fett?

Share this post

Link to post
Share on other sites
Every directdraw surface IS a pointer. Simply because, in c++, you can create an abstract class (here DirectDrawSurface7*), then create more classes which implement its functionality and yet can be passed around as a pointer to the abstract class.

The way COM works is that Windows keeps a record of the real classes, and when you request a new object of a given type, it returns a pointer to such an abstract class.

That way, even if the actual implementation changes (say, in DX 325.4), so long as the operating system can provide you with a DirectDrawSurface7*, you don''t care about what version really is installed.

Now, as for that pointer thingy, when you type "Foo *Bar", you declare that Bar can hold the adress of a variable of type Foo. Now, C didn''t support pass-by reference (C++ does, but it''s really a pointer trick). Which means that the parameter you pass is copied, and the original cannot be modified. Yet, if what you pass is the address of an object (i.e. a pointer), while you may not modify the pointer itself from within the function, you can do whatever you want to the object you are given the address of. (Think, if I give you my email address, you cannot change it, but you can send me mail. To change my email address, you''d have to know where it is stored and change it there... a pointer to a pointer).

As to why the star, well, that''s just syntax, the C Gods chose the star, we are stuck with it. So, yes, it is required.

HRESULT is an ''obscure'' Windows API type, meaning you are not supposed to care what it really is. Yes, you need to use it where the API says so : dialing an email address where a phone number is required cannot possibly work. Why ? Because that''s what the function expects. Since C++ is strongly typed, the compiler will barf, but, if it didn''t, well, it''s like converting the letters of my email address into the numbers written on your phone''s key, dialing them, and then expecting to reach me. Plus you won''t find an @ on your phone, which would translate as garbage for your function.

I hope my drug-addled brain managed to produce an understandable explanation.

Share this post

Link to post
Share on other sites
Original post by BASSOFeeSH
Here's a hint for you...any variable type that starts with 'LP' is really a pointer...but you know what...don't worry about it.

Don't trust hungarian notation : take wParam for example. w means WORD, 16 bits type. However it is a 32 bit variable, a DWORD and should be named dwParam.

Hungarian notation is a comment technique.
Comments in code turn into lies as code evolve.
Hungarian notation turns into lies as code evolve.

Check *this

Edit: link added.

Edited by - Fruny on December 8, 2001 1:49:17 PM

Share this post

Link to post
Share on other sites
The HRESULT is the return type of the function. By testing this value you can tell whether the function succeeded or not.

Herb M. (Lord Flashfire)

Share this post

Link to post
Share on other sites
When you write a COM method in C++ you would usually pass the pointer to an object to be returned as one of the method parameters and have your method return HRESULT. Also to create C++ COMponents you have to have MIDL files and for every method you must specify the type of the input parameter for example

HRESULT GetSurface([in] IDirect3DDevice8* device, [out, retval] IDirectDrawSurface8* surface);

note the [out, retval]. This is your output value. When you use this component in VisualBasic you would do this:

Dim surface as IDirectDrawSurface8

Set surface = YourObj.GetSurface(d3ddevice)

Notice how the parameter marked [out,retval] becomes what you "set" your own variable to and the HRESULT disappears.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!