Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Compiling a DLL from a .c file

Awww dumb mistake ;/ It compiles now :) But it still doesn't work in RM and the functions look the same when I open the dll in a text file.
 
lol, I was about to go through and compile and test it msyelf, and then I remembered I don't have RPG Maker installed on this computer :x

EDIT: Can you show us your RGSS code?
 
I can use my code only if I open the dll into a text editor and use the weird function name in it. I tried with BitmapSteelEffect, renamed to _Z17BitmapSteelEffectl after compilation.
 
I think that you have to create a .def file in order to name your functions correctly.
I can't help you with that because I never have this problem with VC++... Sorry...
 
If you are willing to post your most up to date code, I'll take a look through it. I have a couple .dll files with source codes, and all of them have the proper names for functions.

Edit: It actually looks like we used the same original source for our dll files, since I'm using the same basic bitmap editing functions, and identical bitmap structures. Anyway, since that's the case, lemme post the exact source for one of them:

C:
<div class="c" id="{CB}" style="font-family: monospace;"><ol><span style="color: #339933;">#include <cstdlib>

<span style="color: #339933;">#include <ctime>

<span style="color: #339933;">#include <ctype.h>

<span style="color: #339933;">#include <math.h>

<span style="color: #339933;">#include <stddef.h>

<span style="color: #339933;">#include <stdio.h>

<span style="color: #339933;">#include <stdlib.h>

<span style="color: #339933;">#include <string.h>

<span style="color: #339933;">#include <windows.h>

 

BOOL APIENTRY DllMain( HMODULE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved) {

    <span style="color: #b1b100;">switch (ul_reason_for_call) {

        <span style="color: #b1b100;">case DLL_PROCESS_ATTACH:

        <span style="color: #b1b100;">case DLL_THREAD_ATTACH:

        <span style="color: #b1b100;">case DLL_THREAD_DETACH:

        <span style="color: #b1b100;">case DLL_PROCESS_DETACH:

        <span style="color: #000000; font-weight: bold;">break;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #993333;">typedef <span style="color: #993333;">struct {

    DWORD flags;

    DWORD klass;

    <span style="color: #993333;">void (*dmark) (<span style="color: #993333;">void*);

    <span style="color: #993333;">void (*dfree) (<span style="color: #993333;">void*);

    <span style="color: #993333;">double *data; //red is index 1, green is index 2, blue 3, alpha 0

} RGSSCOLOR;

 

<span style="color: #993333;">typedef <span style="color: #993333;">struct{

    DWORD unk1;

    DWORD unk2;

    BITMAPINFOHEADER *infoheader;

    RGSSCOLOR *firstRow;

    RGBQUAD *lastRow;

} RGSSBMINFO;

 

<span style="color: #993333;">typedef <span style="color: #993333;">struct{

    DWORD unk1;

    DWORD unk2;

    RGSSBMINFO *bminfo;

} BITMAPSTRUCT;

 

<span style="color: #993333;">typedef <span style="color: #993333;">struct{

    DWORD flags;

    DWORD klass;

    <span style="color: #993333;">void (*dmark) (<span style="color: #993333;">void*);

    <span style="color: #993333;">void (*dfree) (<span style="color: #993333;">void*);

    BITMAPSTRUCT *bm;

} RGSSBITMAP;

 

<span style="color: #339933;">#define ASSERT(x) if(!x){DebugOut("Failed: %s: %d", #x, __LINE__);}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL AlienTwo(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row, pixel1, pixel2, pixel3, pixel4;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">double red, green, blue;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE) (bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        pixel1 = row;

        pixel2 = row;

        pixel3 = row;

        pixel4 = row;

        <span style="color: #b1b100;">if((y >= <span style="color: #cc66cc;">0) && ((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height)) {

            pixel2 -= rowsize;

            pixel3 -= rowsize;

        }

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            <span style="color: #b1b100;">if(((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height) && ((x + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) width)) {

                pixel2 += <span style="color: #cc66cc;">4;

                pixel4 += <span style="color: #cc66cc;">4;

                red = sqrt(pow(((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">2] - pixel2[<span style="color: #cc66cc;">2]), <span style="color: #cc66cc;">2) + pow(((<span style="color: #993333;">double) pixel3[<span style="color: #cc66cc;">2] - pixel4[<span style="color: #cc66cc;">2]), <span style="color: #cc66cc;">2));

                green = sqrt(pow(((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">1] - pixel2[<span style="color: #cc66cc;">1]), <span style="color: #cc66cc;">2) + pow(((<span style="color: #993333;">double) pixel3[<span style="color: #cc66cc;">1] - pixel4[<span style="color: #cc66cc;">1]), <span style="color: #cc66cc;">2));

                blue = sqrt(pow(((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">0] - pixel2[<span style="color: #cc66cc;">0]), <span style="color: #cc66cc;">2) + pow(((<span style="color: #993333;">double) pixel3[<span style="color: #cc66cc;">0] - pixel4[<span style="color: #cc66cc;">0]), <span style="color: #cc66cc;">2));

            }

            <span style="color: #b1b100;">else <span style="color: #b1b100;">if(((y + <span style="color: #cc66cc;">1) >= (<span style="color: #993333;">int) height) && ((x + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) width)) {

                pixel2 += <span style="color: #cc66cc;">4;

                pixel4 += <span style="color: #cc66cc;">4;

                red = sqrt(pow((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">2], <span style="color: #cc66cc;">2) + pow((<span style="color: #993333;">double) pixel4[<span style="color: #cc66cc;">2], <span style="color: #cc66cc;">2));

                green = sqrt(pow((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">1], <span style="color: #cc66cc;">2) + pow((<span style="color: #993333;">double) pixel4[<span style="color: #cc66cc;">1], <span style="color: #cc66cc;">2));

                blue = sqrt(pow((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">0], <span style="color: #cc66cc;">2) + pow((<span style="color: #993333;">double) pixel4[<span style="color: #cc66cc;">0], <span style="color: #cc66cc;">2));

            }

            <span style="color: #b1b100;">else <span style="color: #b1b100;">if(((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height) && ((x + <span style="color: #cc66cc;">1) >= (<span style="color: #993333;">int) width)) {

                red = sqrt(pow((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">2], <span style="color: #cc66cc;">2) + pow((<span style="color: #993333;">double) pixel3[<span style="color: #cc66cc;">2], <span style="color: #cc66cc;">2));

                green = sqrt(pow((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">1], <span style="color: #cc66cc;">2) + pow((<span style="color: #993333;">double) pixel3[<span style="color: #cc66cc;">1], <span style="color: #cc66cc;">2));

                blue = sqrt(pow((<span style="color: #993333;">double) pixel1[<span style="color: #cc66cc;">0], <span style="color: #cc66cc;">2) + pow((<span style="color: #993333;">double) pixel3[<span style="color: #cc66cc;">0], <span style="color: #cc66cc;">2));

            }

            <span style="color: #b1b100;">else {

                red = pixel1[<span style="color: #cc66cc;">2];

                green = pixel1[<span style="color: #cc66cc;">1];

                blue = pixel1[<span style="color: #cc66cc;">0];

            }

            <span style="color: #b1b100;">if((red + green + blue) > (<span style="color: #993333;">double) <span style="color: #cc66cc;">60) {

                <span style="color: #b1b100;">if((red >= green) && (red >= blue)) {

                    red += <span style="color: #cc66cc;">20;

                }

                <span style="color: #b1b100;">else <span style="color: #b1b100;">if((green >= red) && (green >= blue)) {

                    green += <span style="color: #cc66cc;">20;

                }

                <span style="color: #b1b100;">else {

                    blue += <span style="color: #cc66cc;">20;

                }

                <span style="color: #b1b100;">if(red > <span style="color: #cc66cc;">255) red = <span style="color: #cc66cc;">255;

                <span style="color: #b1b100;">if(green > <span style="color: #cc66cc;">255) green = <span style="color: #cc66cc;">255;

                <span style="color: #b1b100;">if(blue > <span style="color: #cc66cc;">255) blue = <span style="color: #cc66cc;">255;

                pixel1[<span style="color: #cc66cc;">2] = (BYTE) red;

                pixel1[<span style="color: #cc66cc;">1] = (BYTE) green;

                pixel1[<span style="color: #cc66cc;">0] = (BYTE) blue;

            }

            <span style="color: #b1b100;">else {

                pixel1[<span style="color: #cc66cc;">2] = <span style="color: #cc66cc;">0;

                pixel1[<span style="color: #cc66cc;">1] = <span style="color: #cc66cc;">0;

                pixel1[<span style="color: #cc66cc;">0] = <span style="color: #cc66cc;">0;

            }

            pixel1 += <span style="color: #cc66cc;">4;

            pixel3 += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL BlackAndWhite(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">int shade;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE) (bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            shade = ((thisrow[<span style="color: #cc66cc;">2] + thisrow[<span style="color: #cc66cc;">1] + thisrow[<span style="color: #cc66cc;">0]) / <span style="color: #cc66cc;">3);

            thisrow[<span style="color: #cc66cc;">2] = shade;

            thisrow[<span style="color: #cc66cc;">1] = shade;

            thisrow[<span style="color: #cc66cc;">0] = shade;

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL BlackAndWhite2(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">int red, green, blue, shade;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE)(bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            red = (thisrow[<span style="color: #cc66cc;">1] - thisrow[<span style="color: #cc66cc;">0] + thisrow[<span style="color: #cc66cc;">1] + thisrow[<span style="color: #cc66cc;">2]);

            red = (red * thisrow[<span style="color: #cc66cc;">2] / <span style="color: #cc66cc;">256);

            <span style="color: #b1b100;">if(red > <span style="color: #cc66cc;">255) red = <span style="color: #cc66cc;">255;

            green = (thisrow[<span style="color: #cc66cc;">0] - thisrow[<span style="color: #cc66cc;">1] + thisrow[<span style="color: #cc66cc;">0] + thisrow[<span style="color: #cc66cc;">2]);

            green = (green * thisrow[<span style="color: #cc66cc;">1] / <span style="color: #cc66cc;">256);

            <span style="color: #b1b100;">if(green > <span style="color: #cc66cc;">255) green = <span style="color: #cc66cc;">255;

            blue = (thisrow[<span style="color: #cc66cc;">0] - thisrow[<span style="color: #cc66cc;">1] + thisrow[<span style="color: #cc66cc;">0] + thisrow[<span style="color: #cc66cc;">2]);

            blue = (blue * thisrow[<span style="color: #cc66cc;">0] / <span style="color: #cc66cc;">256);

            <span style="color: #b1b100;">if(blue > <span style="color: #cc66cc;">255) blue = <span style="color: #cc66cc;">255;

            shade = ((red + green + blue) / <span style="color: #cc66cc;">3);

            thisrow[<span style="color: #cc66cc;">2] = shade;

            thisrow[<span style="color: #cc66cc;">1] = shade;

            thisrow[<span style="color: #cc66cc;">0] = shade;

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL Emboss(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">int red, green, blue;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE)(bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        LPBYTE nextrow = row;

        <span style="color: #b1b100;">if((y > <span style="color: #cc66cc;">0) && ((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height)) {

            nextrow -= (width * <span style="color: #cc66cc;">4);

        }

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            <span style="color: #b1b100;">if(((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height) && ((x + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) width)) {

                nextrow += <span style="color: #cc66cc;">4;

                red = (thisrow[<span style="color: #cc66cc;">2] - nextrow[<span style="color: #cc66cc;">2] + <span style="color: #cc66cc;">128);

                green = (thisrow[<span style="color: #cc66cc;">1] - nextrow[<span style="color: #cc66cc;">1] + <span style="color: #cc66cc;">128);

                blue = (thisrow[<span style="color: #cc66cc;">0] - nextrow[<span style="color: #cc66cc;">0] + <span style="color: #cc66cc;">128);

            }

            <span style="color: #b1b100;">else {

                red = (thisrow[<span style="color: #cc66cc;">2] + <span style="color: #cc66cc;">128);

                green = (thisrow[<span style="color: #cc66cc;">1] + <span style="color: #cc66cc;">128);

                blue = (thisrow[<span style="color: #cc66cc;">0] + <span style="color: #cc66cc;">128);

            }

            red = abs(red);

            green = abs(green);

            blue = abs(blue);

            <span style="color: #b1b100;">if(red > <span style="color: #cc66cc;">255) red = <span style="color: #cc66cc;">255;

            <span style="color: #b1b100;">if(green > <span style="color: #cc66cc;">255) green = <span style="color: #cc66cc;">255;

            <span style="color: #b1b100;">if(blue > <span style="color: #cc66cc;">255) blue = <span style="color: #cc66cc;">255;

            thisrow[<span style="color: #cc66cc;">2] = red;

            thisrow[<span style="color: #cc66cc;">1] = green;

            thisrow[<span style="color: #cc66cc;">0] = blue;

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL MinusTwo(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">double color1, color2;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE)(bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        LPBYTE nextrow = row;

        <span style="color: #b1b100;">if((y > <span style="color: #cc66cc;">0) && ((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height)) {

            nextrow -= (width * <span style="color: #cc66cc;">4);

        }

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            <span style="color: #b1b100;">if(((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height) && ((x + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) width)) {

                nextrow += <span style="color: #cc66cc;">4;

                color2 = (((nextrow[<span style="color: #cc66cc;">2] * <span style="color: #cc66cc;">0.3) + (nextrow[<span style="color: #cc66cc;">1] * <span style="color: #cc66cc;">0.6) + (nextrow[<span style="color: #cc66cc;">0] * <span style="color: #cc66cc;">0.1)) / <span style="color: #cc66cc;">10);

            }

            <span style="color: #b1b100;">else {

                color2 = <span style="color: #cc66cc;">0;

            }

            color1 = (((thisrow[<span style="color: #cc66cc;">2] * <span style="color: #cc66cc;">0.3) + (thisrow[<span style="color: #cc66cc;">1] * <span style="color: #cc66cc;">0.6) + (thisrow[<span style="color: #cc66cc;">0] * <span style="color: #cc66cc;">0.1)) / <span style="color: #cc66cc;">10);

            <span style="color: #b1b100;">if((color1 - color2) > <span style="color: #cc66cc;">0.2) {

                thisrow[<span style="color: #cc66cc;">2] = <span style="color: #cc66cc;">0;

                thisrow[<span style="color: #cc66cc;">1] = <span style="color: #cc66cc;">0;

                thisrow[<span style="color: #cc66cc;">0] = <span style="color: #cc66cc;">0;

            }

            <span style="color: #b1b100;">else {

                thisrow[<span style="color: #cc66cc;">2] = <span style="color: #cc66cc;">255;

                thisrow[<span style="color: #cc66cc;">1] = <span style="color: #cc66cc;">255;

                thisrow[<span style="color: #cc66cc;">0] = <span style="color: #cc66cc;">255;

            }

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL Sepia(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">double red, green, blue;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE)(bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            red = ((thisrow[<span style="color: #cc66cc;">2] * <span style="color: #cc66cc;">0.393) + (thisrow[<span style="color: #cc66cc;">1] * <span style="color: #cc66cc;">0.769) + (thisrow[<span style="color: #cc66cc;">0] * <span style="color: #cc66cc;">0.189));

            green = ((thisrow[<span style="color: #cc66cc;">2] * <span style="color: #cc66cc;">0.349) + (thisrow[<span style="color: #cc66cc;">1] * <span style="color: #cc66cc;">0.686) + (thisrow[<span style="color: #cc66cc;">0] * <span style="color: #cc66cc;">0.168));

            blue = ((thisrow[<span style="color: #cc66cc;">2] * <span style="color: #cc66cc;">0.272) + (thisrow[<span style="color: #cc66cc;">1] * <span style="color: #cc66cc;">0.534) + (thisrow[<span style="color: #cc66cc;">0] * <span style="color: #cc66cc;">0.131));

            <span style="color: #b1b100;">if(red > <span style="color: #cc66cc;">255) red = <span style="color: #cc66cc;">255;

            <span style="color: #b1b100;">if(green > <span style="color: #cc66cc;">255) green = <span style="color: #cc66cc;">255;

            <span style="color: #b1b100;">if(blue > <span style="color: #cc66cc;">255) blue = <span style="color: #cc66cc;">255;

            thisrow[<span style="color: #cc66cc;">2] = (BYTE) red;

            thisrow[<span style="color: #cc66cc;">1] = (BYTE) green;

            thisrow[<span style="color: #cc66cc;">0] = (BYTE) blue;

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL Sharpen(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">double red, green, blue, ap;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE)(bitmap -> firstRow);

    red = <span style="color: #cc66cc;">0;

    green = <span style="color: #cc66cc;">0;

    blue = <span style="color: #cc66cc;">0;

    ap = <span style="color: #cc66cc;">0.8;

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        LPBYTE nextrow = row;

        <span style="color: #b1b100;">if((y > <span style="color: #cc66cc;">0) && ((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height)) {

            nextrow -= (width * <span style="color: #cc66cc;">4);

        }

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            <span style="color: #b1b100;">if(((y + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) height) && ((x + <span style="color: #cc66cc;">1) < (<span style="color: #993333;">int) width)) {

                nextrow += <span style="color: #cc66cc;">4;

                red += nextrow[<span style="color: #cc66cc;">2];

                green += nextrow[<span style="color: #cc66cc;">1];

                blue += nextrow[<span style="color: #cc66cc;">0];

            }

            red = (((thisrow[<span style="color: #cc66cc;">2] - (red / <span style="color: #cc66cc;">3)) * ap) + thisrow[<span style="color: #cc66cc;">2]);

            green = (((thisrow[<span style="color: #cc66cc;">1] - (green / <span style="color: #cc66cc;">3)) * ap) + thisrow[<span style="color: #cc66cc;">1]);

            blue = (((thisrow[<span style="color: #cc66cc;">0] - (blue / <span style="color: #cc66cc;">3)) * ap) + thisrow[<span style="color: #cc66cc;">0]);

            <span style="color: #b1b100;">if(red > <span style="color: #cc66cc;">255) red = <span style="color: #cc66cc;">255;

            <span style="color: #b1b100;">if(green > <span style="color: #cc66cc;">255) green = <span style="color: #cc66cc;">255;

            <span style="color: #b1b100;">if(blue > <span style="color: #cc66cc;">255) blue = <span style="color: #cc66cc;">255;

            <span style="color: #b1b100;">if(red < <span style="color: #cc66cc;">0) red = <span style="color: #cc66cc;">0;

            <span style="color: #b1b100;">if(green < <span style="color: #cc66cc;">0) green = <span style="color: #cc66cc;">0;

            <span style="color: #b1b100;">if(blue < <span style="color: #cc66cc;">0) blue = <span style="color: #cc66cc;">0;

            thisrow[<span style="color: #cc66cc;">2] = (BYTE) red;

            thisrow[<span style="color: #cc66cc;">1] = (BYTE) green;

            thisrow[<span style="color: #cc66cc;">0] = (BYTE) blue;

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL Soften(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y, xoffset, yoffset;

    <span style="color: #993333;">int red, green, blue;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE) (bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            red = <span style="color: #cc66cc;">0;

            green = <span style="color: #cc66cc;">0;

            blue = <span style="color: #cc66cc;">0;

            <span style="color: #b1b100;">for ( xoffset = <span style="color: #cc66cc;">-1; xoffset <= <span style="color: #cc66cc;">1; xoffset++) {

                <span style="color: #b1b100;">for ( yoffset = <span style="color: #cc66cc;">-1; yoffset <= <span style="color: #cc66cc;">1; yoffset++) {

                    <span style="color: #b1b100;">if ((y > <span style="color: #cc66cc;">0) && ((y + yoffset) < (<span style="color: #993333;">int) height) && ((y + yoffset) > <span style="color: #cc66cc;">0) && ((x + xoffset) > <span style="color: #cc66cc;">0) && ((x + xoffset) < (<span style="color: #993333;">int) width)) {

                        LPBYTE newrow = thisrow;

                        newrow -= (yoffset * (width * <span style="color: #cc66cc;">4));

                        newrow += (xoffset * <span style="color: #cc66cc;">4);

                        red += newrow[<span style="color: #cc66cc;">2];

                        green += newrow[<span style="color: #cc66cc;">1];

                        blue += newrow[<span style="color: #cc66cc;">0];

                    }

                }

            }

            red /= <span style="color: #cc66cc;">9;

            green /= <span style="color: #cc66cc;">9;

            blue /= <span style="color: #cc66cc;">9;

            thisrow[<span style="color: #cc66cc;">2] = red;

            thisrow[<span style="color: #cc66cc;">1] = green;

            thisrow[<span style="color: #cc66cc;">0] = blue;

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL Splatter(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">int randomx, randomy;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE) (bitmap -> firstRow);

    srand((<span style="color: #993333;">unsigned)time(<span style="color: #cc66cc;">0));

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            randomx = ((rand() % <span style="color: #cc66cc;">3) + <span style="color: #cc66cc;">1);

            randomy = ((rand() % <span style="color: #cc66cc;">3) + <span style="color: #cc66cc;">1);

            <span style="color: #b1b100;">if((y > <span style="color: #cc66cc;">0) && ((y + randomy) < (<span style="color: #993333;">int) height) && ((x + randomx) < (<span style="color: #993333;">int) width)) {

                LPBYTE newrow = thisrow;

                newrow -= (randomy * (width * <span style="color: #cc66cc;">4));

                newrow += (randomx * <span style="color: #cc66cc;">4);

                thisrow[<span style="color: #cc66cc;">2] = newrow[<span style="color: #cc66cc;">2];

                thisrow[<span style="color: #cc66cc;">1] = newrow[<span style="color: #cc66cc;">1];

                thisrow[<span style="color: #cc66cc;">0] = newrow[<span style="color: #cc66cc;">0];

                thisrow[<span style="color: #cc66cc;">3] = newrow[<span style="color: #cc66cc;">3];

            }

            <span style="color: #b1b100;">else {

                thisrow[<span style="color: #cc66cc;">2] = <span style="color: #cc66cc;">0;

                thisrow[<span style="color: #cc66cc;">1] = <span style="color: #cc66cc;">0;

                thisrow[<span style="color: #cc66cc;">0] = <span style="color: #cc66cc;">0;

                thisrow[<span style="color: #cc66cc;">3] = <span style="color: #cc66cc;">0;

            }

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

}

 

<span style="color: #000000; font-weight: bold;">extern "C" _declspec (dllexport) BOOL Blank(<span style="color: #993333;">long object){

    RGSSBMINFO *bitmap = ((RGSSBITMAP*) (object<<<span style="color: #cc66cc;">1)) -> bm -> bminfo;

    DWORD rowsize;

    DWORD width, height;

    LPBYTE row;

    <span style="color: #993333;">long x, y;

    <span style="color: #993333;">int red, green, blue;

    <span style="color: #b1b100;">if(!bitmap) <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">false;

    width = bitmap -> infoheader -> biWidth;

    height = bitmap -> infoheader -> biHeight;

    rowsize = width * <span style="color: #cc66cc;">4;

    row = (LPBYTE) (bitmap -> firstRow);

    <span style="color: #b1b100;">for ( y = <span style="color: #cc66cc;">0; y < (<span style="color: #993333;">int) height; y++) {

        LPBYTE thisrow = row;

        <span style="color: #b1b100;">for ( x = <span style="color: #cc66cc;">0; x < (<span style="color: #993333;">int) width; x++) {

            red = thisrow[<span style="color: #cc66cc;">2];

            green = thisrow[<span style="color: #cc66cc;">1];

            blue = thisrow[<span style="color: #cc66cc;">0];

            thisrow += <span style="color: #cc66cc;">4;

        }

        row -= rowsize;

    }

    <span style="color: #b1b100;">return <span style="color: #000000; font-weight: bold;">true;

 

By the way, I have a tidbit of info you might not have realized. RMXP stores the colors for a bitmap in the BGRA format, instead of RGBA format.
 
I tried your source Glitch, and it works like a charm! There's a couple of functions from the original source that doesn't seem to work but it shouldn't be a problem. I'm sure I can make them work if I spend a little more time on it. Oh and, thanks for the info about the colors. It's definitely useful to know this!

I guess everything is good now. I can compile my source file, I can use the DLL in RM and call a function with it.
Now all I need is to learn more about C and make some cool effects!

Thanks a lot guys, you all were very helpful. :)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top