creating dlls

BlitzPlus Forums/BlitzPlus Programming/creating dlls

Gladclef - Ben B(Posted 2009) [#1]
Hey, I'm trying to make a dll for blitz in dev c++, but I can't even get a simple hello_world function to work (returns "Hello World!\0" as a char *).

Even modeling my c code off of the example code, I'm still having difficulties.

So, my question is... how to create dll's that work with blitz?


Gladclef - Ben B(Posted 2009) [#2]
Ok, got the dll part figured out.
Using the standard dll package that dev gives you, modify it slightly.
The format for the dev package is:

DLLIMPORT char* HelloWorld

when it needs to look like this for blitz:

DLLEXPORT char* BBCALL HelloWorld
.
.
.
And, like in the blitz basic example, you must define
#define BBCALL _stdcall
in the dll.h file.

.
.
.

With that said, I now have a new problem:
How are images stored in memory in Blitz, and how do I access them if I'm writing my own dll?


Floyd(Posted 2009) [#3]
The LockedPixels command returns a Blitz bank which represents the image data. You would pass that bank to the DLL.

The associated commands LockedFormat and LockedPitch also give important information which would have to be passed to the DLL.

This is fairly complicated if you've never dealt with such issues before. For example, with 32-bit graphics a pixel needs 4 bytes. You would think a 200 pixel wide image would use 200 * 4 = 800 bytes per row. And that might be true in some cases. But with my graphics card there are 832 bytes per row. Further experimentation shows that the block of memory representing the image is padded so that it is a multiple of 16 pixels wide. Thus widths from 1 to 16 all use 64 bytes per row. Then widths 17 to 32 use 128, etc.

32-bit graphics are the easiest, each color value being 0 to 255. With 16-bit graphics the color values are stored in 5 or 6 bits. A stored value of 12 would then represent a displayed value of 4+8*12 or 2+4*12, respectively. I'm writing this from distant memories of when BlitzPlus was new. You will have to check the details.

Here's an example to get you started:




Gladclef - Ben B(Posted 2009) [#4]
Alright. Thanks for the help. I'm working out the program now.
Will post when I've got the code working...