Direct2D Quickstart for Windows 8


I am trying to draw a simple rectangle in Direct2D since GDI is no longer used with Xojo. The following code. I wasn’t able to find an example in Xojo with Google to draw with Direct2D so I am trying some code.

There is an Example in C++ that I would like to draw by using declares: Direct2D Quickstart for Windows 8

There are two parts of code that I am just starting with:

Sub Action() Handles Action //Create a Direct2D factory Dim pD2DFactory as New MemoryBlock(8) Dim hr as Integer = 1 hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, pD2DFactory) If hr = 0 then System.DebugLog "D2D1CreateFactory success" Else System.DebugLog "D2D1CreateFactory error:" + hr.ToText End If End Sub

The above starts to create a new ID2D1Factory. The method is overloaded and I think I have the right one - maybe not :slight_smile:

Here is the declare code:

Public Function D2D1CreateFactory(factorytype as UInt32, ppIFactory as Ptr) as Integer #If TargetWindows // Dim hResult as Integer Declare Function D2D1CreateFactory Lib "D2d1.dll" (factorytype as Integer, ppIFactory as Ptr) as Integer If System.IsFunctionAvailable("D2D1CreateFactory","D2d1.dll") then Return D2D1CreateFactory(factorytype, ppIFactory) Else System.DebugLog "Error calling D2D1CreateFactory" End if #Endif End Function

The program doesn’t call an error, and GetLastError doesn’t show anything and the IDE just shuts down. After a couple of days with this code, I am no further ahead. Does anyone have some helpful suggestions?

:wink: Just something I put together for someone on the forum.

However, just a quick look at at D2D1CreateFactory, it takes 4 params and you’re only giving it 2 ?

I’ve not taken a super in depth look at D2D yet as I don’t believe Xojo has taken the right path in their implementation, I’m in two mind about arguing against how its been done.

Oh you’re using the one from here:

Thats as ptr to a ptr so you need in the delare ByRef

Let me have a tinker a mo.

LOL, I love this forum </sarcasm off>. I just wrote a response and it showed two versions - and I deleted one of the duplicate responses and the forum deleted both responses… lol…

Hehe yeah :frowning: I see that and I always refresh the page before I do anything

Here is a link to the program that was modified to a pointer with ByRef:


I was also hunting for datatype conversions that are similar to your helpful C++ to Xojo datatype declares, and hadn’t found one yet. I randomly tried a few different datatypes and this didn’t help either - but I was just guessing.

This should start things up:

I just use my reformatcode script to do the conversions these days, same difference, just quicker. C++ enums are Int32 thats the only thing I need to add to my list to get that code going.

oops, grab it again, fixed that enum typo after changing it from the const I was temporarily using.

Wow, that was fast Julian - and Thank you.

I am going to dig into this some more and see what you did. I see that a COM is referenced which piques my interest.

Thanks again!

No probs. Just glancing over it, I think it’ll be a bit of a slog but it should be doable.

If you get stuck with it, take a look at this and if you can understand those then you’re on the right path.