Solved

Help converting MS "C" sample code

Posted on 1998-03-05
37
225 Views
Last Modified: 2010-04-06
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
     
0
Comment
Question by:sz3905
  • 19
  • 9
  • 9
37 Comments
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi,  sz3905

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

Regards, Zif
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Woops, don't mention, it's a self-extracting file, sorry.
0
 

Author Comment

by:sz3905
Comment Utility
Edited text of question
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
Hi,

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

Igor
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
Hi,

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

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
hi Inter,
Correct, the Quick Sort routine isn't standard implemented in Delphi. But that shouldn't be so hard.
Good luck.
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
? Don't you've to assign a handler for changing the DIBbits? Now you probable take the handle of the desktop.
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
Ok THATS IT!

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

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
You may send me the code, if you want.

But also answer this question!!

Regards, Zif.
0
 
LVL 5

Accepted Solution

by:
inter earned 300 total points
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Inter, I received your mail 2 times. Many thanks already.
0
 

Author Comment

by:sz3905
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 

Author Comment

by:sz3905
Comment Utility
Will try
CreateDIBSection(TheDC, pbmi^, DIB_RGB_COLORS, Pointer(pBits), 0, 0);
asap and let you know
/Steve/sz3905
0
 

Author Comment

by:sz3905
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
try
 AnimatePalette(hPal, 0, 256, pe);
or
 AnimatePalette(hPal, 0, 256, PPaletteEntry(@pe)^);

Igor
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
I should leave in a minute if you have a comment please present.

Igor
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Sorry, was a way for a moment. Haven't D3, have D2. What's the problem at the moment?
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 

Author Comment

by:sz3905
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
Then just this

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

Ok?
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Well, if you need some help (which I doubt), i'm still here (l.t. 20.00h)
0
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 

Author Comment

by:sz3905
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility

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
 

Author Comment

by:sz3905
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
Dear friend,

(If you don't mind) what are you planning to do with these kind of animation?
Igor
0
 

Author Comment

by:sz3905
Comment Utility
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
 
LVL 5

Expert Comment

by:inter
Comment Utility
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
 

Author Comment

by:sz3905
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now