Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DLL Talk / Can anyone help get a SDK dll working in DBP?

Author
Message
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th Feb 2011 18:00
I have an advertising SDK and I don't even know if it is possible to get it working in DBP.

I was hoping someone could take a quick look at the documentation or the SDK and let me know if it's even possible to make it work?

Attached is the full SDK.

Sorry my knowledge of making/using dll's is rubbish despite several attempts...

Attachments

Login to view attachments
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 28th Feb 2011 20:44
The API looks fairly simple, and I think it could be used from DBPro directly with IanM's plugins and either a windows GUI plugin like BlueGUI or if you manually add the WS_CLIPCHILDREN style to the dbpro window.

The example C++ code:


Would look something like this in DBPro if you decorate the names correctly:


[b]
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 28th Feb 2011 21:25
Thanks Diggsey! That's great news!

I just don't quite understand how to
Quote: "add the WS_CLIPCHILDREN style to the dbpro window."


I do have BlueGUI though...

I'm not very experienced calling dll's manually from DBP, sorry.

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Mar 2011 01:11 Edited at: 1st Mar 2011 01:12
Yeah, I wasn't expecting you to know, it's just that there's quite a lot to explain all at once

WS_CLIPCHILDREN is a constant defined by the windows API. All GUI controls are known as windows when dealing with the windows API, including buttons etc. although buttons are child windows as opposed to top level windows which is what the term is usually used for. This ad API works by creating a child window on another window which contains the advert. Usually you want it to be created on the DBPro window, but there is a problem with this.

Because you update what's in the window every time you call "sync" all the children of that window will also need to be redrawn. The end result of this is that GDI (the standard drawing API in windows used for all the normal stuff like buttons and windows) can't keep up, and so the child controls disappear or flicker. To solve this, windows supplies the WS_CLIPCHILDREN style which you can choose to apply to a window. It does what its name implies: it stops regions of the DBPro window containing a child control from being drawn over, ie. they are clipped.

To apply the WS_CLIPCHILDREN style to a window you need to use a couple of functions from "user32.dll" (this dll handles most of the things to do with the windows GUI). The functions are called "GetWindowLongA" and "SetWindowLongA". These two functions are used to set and get some of the properties belonging to windows. In this case we want to set and get the style of the window.

GetWindowLong takes two parameters, the window handle which is simply an identifier telling it which window you are referring to. (get dbpro window() will get you the dbpro window handle) The second parameter is which property to get. We need GWL_STYLE which has a value of -16. The return value is the current style of the window.

SetWindowLong is almost identical but has a third parameter which specifies the new value of the style, and the return value is the previous style.

All that's left to do is call GetWindowLong to get the old style. Change the style to include WS_CLIPCHILDREN (it is a set of bit flags so a bitwise OR should be used to combine them). Then you need to call SetWindowLong to update the actual window.

Here's some code showing how to do it:


Once you've done this you can create controls (such as the ad) on the main dbpro window without fear of them disappearing or flickering.

[b]
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2011 09:52
Quote: "Valued Member"

Indeed!

Thanks Diggsey, I'll try making a simple app that uses this and see how I get on... if I get it working I'll post some info on the AppUp Dev Group thread as it's designed to work with AppUp so free apps can still make money from advertising.

Ideally it would be great to make some money while producing free apps, even if it means they have some advertising in the menu...

The full version of a game could be ad free of course, so maybe you pay $1-2 for an ad free version with a few 'extras'

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Mar 2011 12:20
I should warn you that the example ad code I gave you is only the sort of thing you should be doing, not a complete solution. From what documentation there is online there appears to be an initialisation function which needs to be called first.

The code also allocates strings using "alloc string" but doesn't keep track of them. This is fine if the code is only ever called once, but if you need to call it more than once or change the value of the strings you should keep track of the pointers to them. Before allocating new ones you should free the old ones.

I'll install the SDK later, then I can actually try stuff out

[b]
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Mar 2011 12:23
OK thanks for the warning Diggsey! I'll try to have a look today at some point and do a bit more reading on the SDK.

You're a legend!

Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Mar 2011 21:44 Edited at: 1st Mar 2011 21:50
OK, I've installed the SDK. First I suggest that you download dll export viewer if you don't have it already. You can then open mOceanCore.dll with it and see all the commands available. Open the dll with and without the "undecorate function names" option as you need the decorated name (ie. "?CreateBanner@@YAPAVCAdViewControl@@PAUHWND__@@HHHH@Z") to get the address of the function, and you'll need the undecorated name ("class CAdViewControl * __cdecl CreateBanner(struct HWND__ *,int,int,int,int)") to know how to call it.

The first problem I see is that many of the exported functions use the __thiscall calling convention and IanM's plugins only support __stdcall and __cdecl calling conventions. A calling convention defines how the parameters are passed to a function when you call it, how the return value is passed back, and who's in charge of restoring the stack.

__stdcall and __cdecl work like this: the calling code pushes the parameters onto the stack one by one from right to left. The function puts the return value in the EAX register. The difference between them is that in __cdecl the calling code pops the parameters back off the stack at the end, whereas in __stdcall the function itself does that. __thiscall is similar to __stdcall in this respect, but the first parameter is stored in the ECX register rather than on the stack.

The only way to get around this that I can see is generating some code on the fly and calling that with __cdecl. On top of the stack will be the return address (so when the function returns it knows to start where it left off), and immediately below that is the first parameter which should actually be in ECX for __thiscall. We need to remove this and put it into ECX but leave the return address intact, so we could first pop the return address in EAX, then pop the first parameter into ECX, and finally push EAX back onto the stack. Then we can jump to the real code and everything *SHOULD* work

The assembly will look like this:


From here I found out that the machine code for that should look like this if the address is 0x12345678:
58 59 50 EA 78 56 34 12

See how the last four bytes are the jump address.

I checked it using this tool. (Try pasting in the previous line and clicking disasm)

That's only 8 bytes altogether, so this code:



Should successfully call a __thiscall function successfully This is untested btw

The reason the bytes are the opposite way around (I write 0xEA505958 to get 58 59 50 EA in memory) is that PCs use little endian byte order (meaning that the least significant byte of a number appears as the first byte in memory).

[b]
Diggsey
13
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 1st Mar 2011 22:53 Edited at: 1st Mar 2011 22:54
I've just tried putting this all into practice:


The mOceanCore.dll should be in the same folder as the dbpro executable. At the moment I get the error "The ADP runtime was unable to initialize" which I think is due to the application ID being invalid. It would really help if I could see inside "adpcppf.h" but that's part of the intel AppUp SDK which I don't have.

[b]
baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2011 09:58
Aah, could be because you aren't running the AppUp debugger...

I'll have a try at this end when I get a chance, my wife is out tonight so that might be possible.

Can't tell you how much I appreciate all this help Diggsey!

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Apr 2011 11:55 Edited at: 14th Apr 2011 11:56
After doing a lot of fruitless playing with this I sent Lee Bamber an Email and this is his response:
Quote: "
Unfortunately I implemented mOcean in the Goals app (which is C++ with DarkGDK). The component itself needs around 20-30 lines of code to set-up and have in your app, and towards the end of the work I did mOcean sent me an example which sends the advert to a texture, which works out much better for potential DBP users I think at some point a third party module which can accept the mOcean developer profile (zone id, app id, site id) and spit out an image so the user can place it anywhere (paste it, put it on a 3D object, e.t.c.) would be the best way to go.

I have copied the code I used below in case you want to expand on the DarkGDK approach (or to suggest someone write a small module for DBP which embodies the code)...
"


Quote: "
And you will also need this function:
"


Quote: "
As I say, mOcean have an example which streams the ad to a texture instead of an ATL window (which is a thousand times better as you don't need to cut a hole in the present layer. Hopefully the above is some help (for someone)

If I get strong interest from the AppUp community, and from mOcean and Intel, I might spend a few days creating an extension to the AppUp DLL to include this ad component.

Best Regards,
Lee.
"


If anyone can help get this into some kind of simple dll I (and the community) would be really greatfull! My efforts at making dlls have been pretty poor.

Frankly if someone could make me a template for a DBP project solution in Visual Studio 2008 that would be enough for me to at least try to get this working as I seem to have some kind of block getting any kind of DBP dll (made by me) to work.

It's crazy that I write C# dlls every day at work and yet for some reason I can't seem to wrap my head around the C++ setup for DBP...

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Jun 2011 18:27 Edited at: 1st Jun 2011 18:29
I'm still working on this and trying to integrate it into the AppUpdll...

I don't suppose you are able to help with this again Diggsey?

If so attached is the file you were wanting to look at.

I'm working on the C++ code to try to integrate it into a dll but any insight anyone can give would be great.

EDIT: clicked "post" by accident...

Attachments

Login to view attachments
Matty H
11
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 8th Jun 2011 18:20
When I get around to submitting Hot Goblins again I will be looking at putting adverts in. I may be able to do a DBPro dll, I'm not sure, I certainly will try.

That might not be for a while yet though as I am rewriting some of it, you may have sorted it by then.

Sorry I can't help more right now as I've got lots on

baxslash
Valued Member
Bronze Codemaster
12
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 8th Jun 2011 18:28
Thanks Matty! I'm getting a little help on this already and may have something soon to add into the AppUp dll I'm working on.

I'll keep you posted here or in the Google AdSense thread I started... or in the AppUp DBP Dev Group sticky...

Login to post a reply

Server time is: 2019-10-18 22:12:18
Your offset time is: 2019-10-18 22:12:18