Help converting MS "C" sample code

I've been trying to convert some C code with not much luck. The C code is a sample that fades a bitmap from black to color. After completely rewriting the sample in D3(3times), spending many days, hours, and many Evariant conversion errors, I realized I'm in over my head on this one. Does any one have converted D3 source of the following of fadein.c from microsoft. The source is at http://support.microsoft.com/support/kb/articles/q149/8/55.asp It's a self extracting exe

Much thanks in advance for even considering this conversion.

I dont want a compiled component because I want to take this code method/concept a lot further.

//Steve
//sbsullivan@ucdavis.edu
     
sz3905Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZifNabCommented:
Hi,  sz3905

I went to that page, but can't find any source except for the program, namely FADEIN.EXE

Regards, Zif
0
ZifNabCommented:
Woops, don't mention, it's a self-extracting file, sorry.
0
sz3905Author Commented:
Edited text of question
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

interCommented:
Hi,

Working on it too. How is yours going on Zif?

Igor
0
interCommented:
Hi,

Working on it too. How it yours going on Zif?

Igor
0
ZifNabCommented:
Hi inter,

Haven't done anything yet. My comment was of thursday evening. Then my server went down and now I haven't got time till this evening again. So, if yours is already done, please give it as an answer. But I'm going to try it out myself too. Maybe a new article is born here?

Regards, Zif.
0
interCommented:
I have translated the half of the code already. However there is a sort routine common to c++ named qsort(I should implement such thing in Delphi-or just cut and paste). Other than that, I think this question also helps us to answer the questions like How do I convert from 24 bit to 8 bit(as you can remember).

Regards,
Igor
0
ZifNabCommented:
hi Inter,
Correct, the Quick Sort routine isn't standard implemented in Delphi. But that shouldn't be so hard.
Good luck.
0
interCommented:
Hi friends,

Now we have a translated source, BUT, just mangling the colors in the desktop!

Any comment?(I am trying to fix it)

Igor
0
ZifNabCommented:
? Don't you've to assign a handler for changing the DIBbits? Now you probable take the handle of the desktop.
0
interCommented:
Ok THATS IT!

Do I paste the code here or send it?(Or who wants the source)

Igor
0
ZifNabCommented:
You may send me the code, if you want.

But also answer this question!!

Regards, Zif.
0
interCommented:
Thanks all, I am sending it!(Just the PAS, DFM and RES files-create a new project, add fadeform.pas as mainform and run)

Regards,
Igor
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
interCommented:
My mailer still could not send the files. If you want I can paste it here. The raw code takes about 700 lines. But I may reduce it if I remove the comments from microsoft. What do you want. Also, are you there sz3905?

Igor
0
ZifNabCommented:
Inter, I received your mail 2 times. Many thanks already.
0
sz3905Author Commented:
Igor and Zif,

Yes i'm here.
I am truly impressed.
I just unzipped and am trying Igor's version(very good!)  while it while we speak. . .
I'm not sure why I'm getting a incompatible types  integer and pointer  error in:

TheBitmap := CreateDIBSection(TheDC, pbmi^, DIB_RGB_COLORS, Pointer(pBits), nil, 0);

I shoudl know in a few minutes.

"What do you want."
I can wait for another email zip or raw email. What ever is convient for you guys.
Again, truly impressed
/steve      
0
interCommented:
I am glad you receive it(by the way reject the answer if Zif also sends you the code, I want to share the points with him after the fix)

My delphi version is 2.0. So lets find the problem. First of all Do you have the source code for Delphi 3.0 components?(i.e. you have Client/Server or professional edition.) If so just open Windows.Pas from ..\source\rtl\win\ directory and search for CreateDIBSection( function. Comment it down here and we try to examine the incompatibility. My Windows.pas reports the following prototype:

function CreateDIBSection(DC: HDC; const p2: TBitmapInfo; p3: UINT;
  var p4: Pointer; p5: PHandle; p6: DWORD): HBITMAP; stdcall;

Is it same?
(Also try add adding {$X+} after interface part please)
Igor


0
interCommented:
Hi there,

If you do not have the sources of VCL please indicate. By the way if you there Zif and have Delphi 3.0 please help (I wonder if I configure my compiler to prevent such errors from compiler options?)

Igor
0
interCommented:
I think I have found. They probably fixed this in Delphi 3.0. so reports incompatible with 2.0. Please try the following variant of the code

CreateDIBSection(TheDC, pbmi^, DIB_RGB_COLORS, Pointer(pBits), 0, 0);

And please notify
Igor


0
sz3905Author Commented:
Will try
CreateDIBSection(TheDC, pbmi^, DIB_RGB_COLORS, Pointer(pBits), 0, 0);
asap and let you know
/Steve/sz3905
0
sz3905Author Commented:
removing "nil" helped
but . . .
 
 AnimatePalette(hPal, 0, 256, @pe);

gives error imcompatible type "array" and "TPaletteEntry"

probably diff betweem D2 and D3 array pointers ?
/steve
 
0
interCommented:
try
 AnimatePalette(hPal, 0, 256, pe);
or
 AnimatePalette(hPal, 0, 256, PPaletteEntry(@pe)^);

Igor
0
interCommented:
I should leave in a minute if you have a comment please present.

Igor
0
ZifNabCommented:
Sorry, was a way for a moment. Haven't D3, have D2. What's the problem at the moment?
0
interCommented:
I am back also,

No problem Zif, some of the API declarations of D2 and D3 varies like some pointers became Var etc. So, I am waiting to fix the things up from the errors reported to Steve by Delphi 3.0.

Igor(l.t. 8:49 p.m)

0
sz3905Author Commented:
I was away also, but we're back
Okay just tried but no can compile. I'll spend more time using watches:

 AnimatePalette(hPal, 0, 256, pe);=
gives error imcompatible type "array" and "PPaletteEntry"

AnimatePalette(hPal, 0, 256, PPaletteEntry(@pe)^); =
gives error imcompatible type "TPaletteEntry" and "PPaletteEntry" Note:this is where I had problems with my version

AnimatePalette(hPal, 0, 256, @pe);=
gives error imcompatible type "array" and "TPaletteEntry"
 
/steve/sz3905
0
interCommented:
Then just this

AnimatePalette(hPal, 0, 256, PPaletteEntry(@pe));

Ok?
0
ZifNabCommented:
Well, if you need some help (which I doubt), i'm still here (l.t. 20.00h)
0
interCommented:
Dear friend,

Please watch you mailbox so we clear the case tonight if you have time for it by now, or just respond to be off and we will deal it tomorow.
(If we do, would you please report all the API related errors in one or two comments so that we can fix it instant)

Regards,
Igor the watchdog timer(Just for fun friend)
0
sz3905Author Commented:
Igor, Date: 11:09AM - March, 06, 1998 PST
I do not understand your last message? Please explain.
The source compiled but does not work.
/Steve

0
interCommented:

Ok friend, forget about the last message, i just said "If you have time lets fix this thing"

Questions:

1 - Does your windows setup to 256 color?
2 - Can you see a bitmap when you press the button on the form?
3 - Can you see any color change in the desktop when you press the button?
4 - Does delphi display hints and if so what are they?

Sincerely,
Igor
0
sz3905Author Commented:
Igor,
It kinda works now.
1) It does now
2)Yes
3)Yes black to color with artifacts (desktop (everywhere)
4) No hints or warnings
/steve

0
interCommented:
Fine,

Since the palette animation uses DAC(a chip on video cards-or we used to do it with DAC) it may happen that the very high frequency pulses disturb your display. To prevent this, run your application full screen or if not, do this kind of animation with DirectX.

Do you have such a problem friend?
Igor
0
interCommented:
Dear friend,

(If you don't mind) what are you planning to do with these kind of animation?
Igor
0
sz3905Author Commented:
11:40AM - March, 06, 1998 PST
Igor,
No problem. U'm, I'm using a brand new HP Vectra.
Are you saying there is no way for a clean fade using
stock hardware and standard winapi calls?
If so, Is it that DirectX handles hardware differently?
You see, I'm from the old school and  dont want
DirectX, ActiveX, ControlX, AlphaX, BetaX, or any other X driver
set of the week. I've always written driver-less software
Using only the existing OS. I write video software.

You did convert the code, thank You both!
So how do I split points between you and Zif?
/steve

0
interCommented:
I am too friend,(from the old school, but just learn them for knowledge)

I just say few thing about video. You may probably know these, any way you may skip, sorry I just want to writedown.

The flickerless animation just use up 3 inline assembler lines in DOS days. As you may already know, the CRT traces every line and whole screen from left to right and top to bottom. The scan from left to right is called HScan(Horizontal) and from top to bottom called VScan. A 50Hz monitor scans whole the screen in every 20msecs. This setup time, between individual page scans is called Vertical Blank Period or shortly VBL. We may poll a grahic card register if it is in VBL. If we update the whole screen in that period there can be absolutely no flicker. So a simple function such as WaitVbl can prevent screen from flickering. Windows NT does not allow this(as you now is is !SECURE!) But win95 may? I can not remember the port number and mask but if you want find them. If it works on win95, your animations may works flicker free regardless of the complexity of your scene.

Thanks, have a nice day(we have a nice night here too)
and Regards
Igor
0
sz3905Author Commented:
It's a nice welcome to hear same beliefs as I have. W95 is very forgiving and implemeting
a write on vertical retrace is a snap while in Nt4.0 it is forbidden. I'll work with your solution. I can still use the code with slight mods. I'm going to try to split or give points by asking another fake question for Zif (reopen) after I close this question.
Again, I am impressed.
Best Regard,
Steve Sullivan

 

 
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.