flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > High Level Languages > C header for DirectDraw7?

Author
Thread Post new topic Reply to topic
borbonhause



Joined: 18 Oct 2015
Posts: 23
C header for DirectDraw7?
Hello. I really like how simple and readable the DDRAW.INC file (from examples coming with fasm) is. And I want something as simple, but for C programming language. Really confused about this COM thing.

Tried to just get ddraw.h from another project, but it requires objbase.h, which in turn requires something else, and I'm really don't think I'll manage to find, read and understand those headers. Also, they are written for C++, so they probably ain't fully compatible with C.
Post 18 Oct 2015, 08:41
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
Moved to High Level Languages.
Post 18 Oct 2015, 09:16
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
Write a proxy library (DLL/LIB) in FASM and you'll be set. Wink
Post 19 Oct 2015, 00:06
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23

typedef wrote:
Write a proxy library (DLL/LIB) in FASM and you'll be set. Wink



That sounds really painful for some reason Smile

For starters I have to find out what each word in this line means:


Code:
extern HRESULT WINAPI DirectDrawCreateExGUID FAR * lpGuidLPVOID  *lplpDDREFIID  iid,IUnknown FAR *pUnkOuter );



In this line, GUID, FAR and IUnknown are main mysteries. Have to get this down to the basic C types somehow.
Post 19 Oct 2015, 21:21
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
I'll just use this for now, I guess...


Code:
extern int DirectDrawCreatevoidlpGuidvoidlplpDDvoidpUnkOuter );



Since lpGuid and pUnkOuter will always be NULL, they don't even matter. But lplpDD on the other hand, is there the fun starts. lplpDD is, let's see, is a pointer to an array of function pointers? How to describe it in C?

Found good hints in header about how it should look like in the end, look at these lines:

Code:

STDMETHOD(SetCooperativeLevel)(THIS_ HWNDDWORDPURE;


#if !defined(__cplusplus) || defined(CINTERFACE)
#define IDirectDraw_SetCooperativeLevel(pab)    (p)->lpVtbl->SetCooperativeLevel(pab)
#else
#define IDirectDraw_SetCooperativeLevel(pab)    (p)->SetCooperativeLevel(ab)
#endif




Post 20 Oct 2015, 09:05
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
Um, no, lplpDD is a pointer to a structure of function pointers, but each member of this structure still takes exactly 4 bytes, so it's not that different from an array...
Post 20 Oct 2015, 09:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699
I am surprised that there is not already header/library files for C available for download.

borbonhause: Are you sure that they are not already available?
Post 20 Oct 2015, 09:33
View user's profile Send private message Visit poster's website Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23

revolution wrote:
I am surprised that there is not already header/library files for C available for download.

borbonhause: Are you sure that they are not already available?



They are available, they are just too scary to look at. Well, look for yourself: ftp://sccn.ucsd.edu/pub/LSL/lsl-dependencies/external_libs/EmbarcaderoXE/shared/4.4.0-msvc/include/ddraw.h http://blogs.msdn.com/b/oldnewthing/archive/2004/10/05/238050.aspx

You may ask why the hell I even look inside instead of just including it. The reason is, well, I'm moving to a different compiler, and there are problems. So instead I'm just trying to copypaste bare minimum of stuff necessary.

_________________
If you found bad grammar in my post, please PM me about it.
Post 20 Oct 2015, 09:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14469
Location: ?                               Posts: 6699

borbonhause wrote:
They are available, they are just too scary to look at.

I find that one is not so bad actually. I've seen worse. But in general I do agree they can get quite ugly sometimes.

If you want to create a new simpler one then I think that is a good idea. If you have the time and energy to do that. But specifically what problems are you having with your compiler? Is it some incompatibility? I ask because maybe you should be looking more closely at your compiler instead to make sure it is going to give you a good output.
Post 20 Oct 2015, 09:58
View user's profile Send private message Visit poster's website Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23

revolution wrote:

borbonhause wrote:
They are available, they are just too scary to look at.

I find that one is not so bad actually. I've seen worse. But in general I do agree they can get quite ugly sometimes.

If you want to create a new simpler one then I think that is a good idea. If you have the time and energy to do that. But specifically what problems are you having with your compiler? Is it some incompatibility? I ask because maybe you should be looking more closely at your compiler instead to make sure it is going to give you a good output.



Well, in fact, I'm doing the same thing with a compiler itself. I'm trying to delete or rewrite stuff I don't need, don't understand or don't like. I'm editing TCC in this way right now. Sooner or later I'll have to dig into all headers, why not to do this now.

_________________
If you found bad grammar in my post, please PM me about it.
Post 20 Oct 2015, 16:00
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
So, I need to turn this:


Code:

#undef INTERFACE
#define INTERFACE IDirectDraw
DECLARE_INTERFACE_IDirectDrawIUnknown )
{
    /*** IUnknown methods ***/
    STDMETHOD(QueryInterface) (THIS_ REFIID riidLPVOID FAR * ppvObjPURE;
    STDMETHOD_(ULONG,AddRef) (THIS)  PURE;
    STDMETHOD_(ULONG,Release) (THISPURE;
    /*** IDirectDraw methods ***/
    STDMETHOD(Compact)(THISPURE;
    STDMETHOD(CreateClipper)(THIS_ DWORDLPDIRECTDRAWCLIPPER FAR*, IUnknown FAR * ) PURE;
    STDMETHOD(CreatePalette)(THIS_ DWORDLPPALETTEENTRYLPDIRECTDRAWPALETTE FAR*, IUnknown FAR * ) PURE;
    STDMETHOD(CreateSurface)(THIS_  LPDDSURFACEDESCLPDIRECTDRAWSURFACE FAR *, IUnknown FAR *) PURE;
    STDMETHOD(DuplicateSurface)( THIS_ LPDIRECTDRAWSURFACELPDIRECTDRAWSURFACE FAR * ) PURE;
    STDMETHOD(EnumDisplayModes)( THIS_ DWORDLPDDSURFACEDESCLPVOIDLPDDENUMMODESCALLBACK ) PURE;
    STDMETHOD(EnumSurfaces)(THIS_ DWORDLPDDSURFACEDESCLPVOID,LPDDENUMSURFACESCALLBACK ) PURE;
    STDMETHOD(FlipToGDISurface)(THISPURE;
    STDMETHOD(GetCaps)( THIS_ LPDDCAPSLPDDCAPSPURE;
    STDMETHOD(GetDisplayMode)( THIS_ LPDDSURFACEDESCPURE;
    STDMETHOD(GetFourCCCodes)(THIS_  LPDWORDLPDWORD ) PURE;
    STDMETHOD(GetGDISurface)(THIS_ LPDIRECTDRAWSURFACE FAR *) PURE;
    STDMETHOD(GetMonitorFrequency)(THIS_ LPDWORDPURE;
    STDMETHOD(GetScanLine)(THIS_ LPDWORDPURE;
    STDMETHOD(GetVerticalBlankStatus)(THIS_ LPBOOL ) PURE;
    STDMETHOD(Initialize)(THIS_ GUID FAR *) PURE;
    STDMETHOD(RestoreDisplayMode)(THISPURE;
    STDMETHOD(SetCooperativeLevel)(THIS_ HWNDDWORDPURE;
    STDMETHOD(SetDisplayMode)(THIS_ DWORDDWORD,DWORDPURE;
    STDMETHOD(WaitForVerticalBlank)(THIS_ DWORDHANDLE ) PURE;
};



into something like this:


Code:
struct IDirectDraw {
        /*HRESULT*/ int (*QueryInterface)(struct IDirectDraw *this, /*REFIID*/ int riid , voidppvObj );
        /*ULONG*/ int (*AddRef)(struct IDirectDraw *this);
        /*ULONG*/ int (*Release)(struct IDirectDraw *this);
        
        /*HRESULT*/ int (*Compact)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*CreateClipper)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*CreatePalette)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*CreateSurface)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*DuplicateSurface)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*EnumDisplayModes)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*EnumSurfaces)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*FlipToGDISurface)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*GetDisplayMode)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*GetFourCCCodes)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*GetGDISurface)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*GetMonitorFrequency)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*GetScanLine)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*GetVerticalBlankStatus)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*Initialize)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*RestoreDisplayMode)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*SetCooperativeLevel)(struct IDirectDraw *thisHWND aint b);
        /*HRESULT*/ int (*SetDisplayMode)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
        /*HRESULT*/ int (*WaitForVerticalBlank)(struct IDirectDraw *thisint __XXXXXXXXXXXX__);
};




hm... Looks like that's it. It doesn't work yet, but at least it compiles.

_________________
If you found bad grammar in my post, please PM me about it.
Post 22 Oct 2015, 07:39
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
By the way, anyone knows where to download DirectX SDK for version 7 or 8? Currently I don't care that much about the newer versions.
Post 22 Oct 2015, 10:17
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23

_________________
If you found bad grammar in my post, please PM me about it.
Post 24 Oct 2015, 02:26
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
Also make sure you get the calling convention right.
Post 25 Oct 2015, 05:15
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23

typedef wrote:
Also make sure you get the calling convention right.


Yeah, thanks for a reminder.

I found out about the existence of the IDirectDrawVtbl structure. Vtbl stands for Vtable, https://en.wikipedia.org/wiki/Virtual_method_table. Also look here, he reverce engeneered one directdraw game and gave some interesting and simple to digest info http://f0dder.reteam.org/essay02.htm.

IDirectDraw and IDirectDrawVtbl even filled automatically for you on creation, if you add them in IDA. I wonder where IDA holds the definitions of a structures it's familiar with...

What is a preferrable name, lpDD or lplpDD? What's used more often? These are the same thing, don't they?

My objective is: get a simple C program with a working DDraw in it.

_________________
If you found bad grammar in my post, please PM me about it.
Post 02 Nov 2015, 11:50
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
Tomorrow I'll try to bring all directdraw code examples I managed to find into one. One is very simple, but it only opens black window, no real way to see if anything actually works. Another one is good, but too complex for me. Third works in fullscreen, which somehow bugs everything and had forced me to reload a few times.
Post 03 Nov 2015, 16:36
View user's profile Send private message Reply with quote
borbonhause



Joined: 18 Oct 2015
Posts: 23
Can somebody write an example of drawing green square in the black DirectDraw window? I'm kind of stuck here.

Anybody here knows DirectDraw?
Post 08 Nov 2015, 10:46
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.