|
-
Dec 12th, 2001, 11:18 PM
#1
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??
-
Dec 12th, 2001, 11:39 PM
#2
transcendental analytic
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.
-
Dec 13th, 2001, 11:06 AM
#3
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.
-
Dec 13th, 2001, 12:07 PM
#4
Monday Morning Lunatic
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
-
Dec 14th, 2001, 07:44 AM
#5
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.
-
Dec 14th, 2001, 01:40 PM
#6
Monday Morning Lunatic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|