Results 1 to 6 of 6

Thread: Alphablending DLL

  1. #1
    DamnedMoose
    Guest

    Alphablending DLL

    ...Hey all,

    I've been experimenting with ASM in C++, but whenever I use it in my DLL, I can't call any of the functions in the DLL :P

    Here's the source

    Code:
    #include <windows.h>
    
    #ifndef _RWSTD_NO_NAMESPACE
    using namespace std;
    #endif
    
    extern "C" {
    INT CALLBACK _export ColorBlend(LONG BlendColor, HBITMAP BitmapHandle);
    }
    
    int LibMain()
    {
    return 1;
    }
    
    INT CALLBACK _export ColorBlend(LONG BlendColor, HBITMAP BitmapHandle)
    {
    BYTE rBit; BYTE gBit; BYTE bBit;
    BYTE* Bits = NULL;
    
    rBit = RedOf(BlendColor);
    gBit = GreenOf(BlendColor);
    bBit = BlueOf(BlendColor);
    
    Bits = new BYTE[32*32*3];
    GetBitmapBits(BitmapHandle, 32*32*3, Bits);
    
    _asm
    {
    mov esi,Bits
    mov ecx,32*32
    mov ah,0
    mov dh,0
    
    @MixColors:
    mov al,[esi]
    mov dl,rBit
    add ax,dx
    sar ax,1
    mov [esi],al
    
    mov al,[esi+1]
    mov dl,gBit
    add ax,dx
    sar ax,1
    mov [esi+1],al
    
    mov al,[esi+2]
    mov dl,bBit
    add ax,dx
    sar ax,1
    mov [esi+2],al
    
    add esi,3
    ; add ecx,-1 - Taken out thanks to Kedaman's advice (i forgot loop auto-decreases ecx...
    loop @MixColors
    }
    
    SetBitmapBits(BitmapHandle, 32*32*3, Bits);
    
    delete(Bits);
    return 1;
    }
    I also have a feeling the ASM is wrong (it should stop looping when ecx = 0...) Help please?

    Oh, and RedOf, GreenOf, BlueOf functions I use:

    Code:
    BYTE RedOf(LONG inColor)
    {
      return (byte)(inColor & 255);
    }
    
    
    BYTE GreenOf(LONG inColor)
    {
      return (byte)((inColor >> 8) & 255);
    }
    
    
    BYTE BlueOf(LONG inColor)
    {
      return (byte)(inColor >> 16);
    }
    Thanks alot! Also, if any of the code is wrong for Alphablending a picture with BlendColor by 50%, please can someone correct it??

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    add ecx,-1
    loop @MixColors
    I think loop decrement ecx automatically, dunno though, never coded asm.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Have you the extern "C" also in the header you include in your app?
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    What's the deal with _export and LibMain? I thought both of those were obsolete?
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    True. It is DllMain and _declspec(dllexport) now.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    From looking closer, it appears that _export is happily used by Borland, which is what they're using (further to the MSN conversation).

    DllMain is definitely replacing LibMain, though...however __declspec(anything) is MSVC specific.

    As a guide, if it has more than two preceding underscores, it's a compiler specific thing.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width