C++ DLL Wrapper for Delphi, code design thoughts?
Hello everyone..
I'm opening up this thread w/ a C++ topic 8O Well, here goes nothing.. if anything, some new threads will begin to poor in, in addtion to this and so on.. Flow for DLL Wrapper Design.. Code:
C++ DLL Wrapper for Delphi ----------------------------------- *** Mind you, this is VERY rough. 1 * if we could use the frame as a guide.. get the frame to be ... read in our DLL imported into Delphi, and as a test, under ... delphi, place an Image control on the form. Passing the ... C++ frame structure DLL, Delphi reads in the contents, and ... if all goes well, our Image control should NOW have an video ... image in our frame (our movie, yaeh) 2 * if an image IS finally displayed, we have passed the first ... test!! 3 * NOW, we can do what we want, ie, use our home-made Delphi ... noise remover, cropper, or whatever.. 4 * next, after processing the frame, we continue by releasing ... the massaged data back into the DLL for further parameter passing ... into AVIsynth's own processing engine.. moving on.. Come on guys, I can't think of everything.. Correct me if I'm wrong, but isn't the mojority of the frameserving dealing with Video BITMAP Images ?? If I'm missing any important steps/methods etc., please advise. This is a learning experience. I believe that it is very important to undertand the AVI stream structure or RIFF, followed by the Header and Chunks etc. That is another topic for discussion, but deserves to be mentioned here, followed by other items of interest.. perhaps in later threads, if not topics. Start your CODE snips engines.. Well, class is OPEN !! Shall we begin !! -vhelp |
Ok, I'm in.
I don't know much about C++ but I've been doing some reading. I already have a new filter prototyped in Delphi that I want/need in Avisynth. By tomorrow, I'll have a copy of MSVC to play with (so far we can only make dll's for Avisynth in MSVC) and I'll take a quick and dirty crack at the problem. My thoughts about this very thing was to make a Delphi DLL loader. This way, the MSVC DLL would be compiled once and free for anyone to build Delphi plugins. The avs script would look like this: -------------------------------------------- LoadPlugin("C:\AviSynth\DelphiPlugin.dll") bla bla bla..... DelphiPlugin("myDelphifilter.dll","param1,param2,p aram3") ---------------------------------------------- Anyway, which ever system is best, I'm all for. While we are at it, lets make one for Borland C++ and MinGW. |
hay MrTibs...
I think you got the idea going.. he, he... ..hence, the Wrapper. Yes, this is my approach. If we can figure on a good C++ template, perhaps to come up with a few for certain conditions or approaches, or something like that, once the C++ DLL is finally inside Delphi, the coder is ready for any sort of action. What I mean by tempalte, is a common format or structure if you call it. For example, I'm working on a simple snipplet, (remember, we want to first debug the DLL to make sure that it is accepted by C++ or AVIsynth.. Code:
type If the above could be passed back and forth in C/C++ then we are headed in the right direction. And, finally, to be tested in AVIsynth. Notice how I'm not making anything too complex. No sense on going over board w/ complexities.. less debugging. If the above code (give or take a few more coding and whatnot) works, the next step is to try a pass w/ an image (another buffer, but with actual data, like a chunk from a BITMAP or Frame or something. #include <avisynth.h> ..has the vfw.h which has ALL the AVI structures, which is what we need for these DLL demos. Once we have a better understanding (calling too) we can get closer to a final outcome. vfw.h has ALL the AVI structures, and it's not a pretty site. You really have to know what all the structure and functions mean and do and how to call them and with proper parameters etc. Add to that, the color conversion process ie YUV/Pallette table etc. Did I leave anything out. Code:
TBuffer = ^TGetFrame; self a little excited. But, if we can get the DLL's to talk w/out issues, we're just accross the street from success. And, once in, it's no holds bar!! quite exciting, ain't it though ? I'm actually thinking re-imaging my 2nd pc as a 2nd setup just for: * Visual Basic, and * C++ What I would do is write my code on my main pc here in Delphi, and then, through LAN connects, debug the DLL's on my 2nd pc, but since the 2nd pc is ONLY for Visual Basic and C++, there is no chance of any issues w/ Delphi. Hmm.. Let me think about some more.. I'll sleep on it to night.. I'm exhausted w/ all this DLL endeavors. I love this hobby though. I sense we are just around the corner from actually coding this. Could be tomorrow !! We shall see. -vhelp |
I will try and stay up just a wee be more, so I can throw up some code
snips. Just some small and simple excercises. what I want to do is pass a Delphi DLL, and see if you C/C++ guys can use the DLL. Small steps. Well, let me see if I can come up with some. If I do, I'll post in the Delphi thread. -vhelp |
Well, as promised, here is it is, and I'm pooped.
Ok, here is the simple and small Delphi DLL excercise I was talking about in my last post. The Delphi Source Code is included for your reference. Download: 33.(dll)-simpledll.rar Files you should see in your .RAR kit: 1, mathminmax.dpr 2, mathminmax.dll 3, mathminmax.cfg 4, mathminmax.dof DELPHI SOURCE CODE: Code:
Library mathminmax; two functions, following these instructions. Note, these snips were taken via the net, so I'm saving some typing here: Excercise #1: C/C++ utilizing Delphi's DLL routines Quote:
up and running on my 2nd pc (haven't gone to sleep yet) Please let me know if they worked. Thanks. Good night all. -vhelp |
I guess the problem is not only porting the Avisynth headers to Delphi - tht would be relatively easy!
The big catch is that Avisynth needs MSVC, not just any C++ compiler!! If you try it with Borland C++ Builder or Dev-C++ it does not compile :( It seems MSVC provides some extra stuff you need. From Doom9: Quote:
http://wwwtcs.inf.tu-dresden.de/~dc1/conditional/ |
Hay GFR,
Sorry for taking so long to respond to your post. I've ben busy w/ many ideas and things. Anyways.. Yes, I agree w/ you. I don't doubt the validity of your statement.. that being, porting AVIsynth's header "avysnth.h" file. It would be nice (great) if someone had ported it to Delphi. I'm going to do some searches on this (perhaps some exhausted ones, when I go to work tomorrow, while using my fast connects) These 56k phone lines suck big-time.. ruins the moments, if you know what I mean. DLL's. . . I've ben playing around (or more like hacking around) w/ some of my DLL's that I created in Delphi. I've also included other DLL's as well, from other users and apps. Trying to bring them into AVIsynth to see what would happen. Most of my attempts would produce an error message or too. But, yesterday (2.8.03) I had a few of mine working when I opened in vdub. Problem is, today, I can't get those same DLL's to load in AVIsynth anymore. I don't know what had happend since yesterday, but for all I know, my system could have ben sick, (down to 7% CPU) and just took everything in w/out any warning messages popping up. But, I'm more curious then ever, because for whatever it's worth, those DLL's got in w/ out issues. Vdub would be nice too, to write DLL's for (mainly filters) and I know it is equipt to share it's VBitmap structure but you still have to be C/C++ user. But, maybe it's more forgiving. Requires MS C. Anyways, I don't have any graphical C/C++, only those GPL/GNU versions which are DOS/COMMANDline only versions (as far as I know) as I did try and compile a few short .h header files, but all I got was a bunch of errors. So, I may have to go on-line tomorrow (today by now) and order a copy of either MS or Borland C++.. Don't know what the price is on those two popular ones $$ Well, I'll look into them anyways.. Quote:
Well, I've ben working on a few more DLL ideas. I've also posted a few DLL excercises under the Delphi section of this FORUM. I've managed to develop a simple DLL for Delphi and VB/VBA, and the apps are avail for D/L, as well as the source code to them. These are just simple excercises if anything. Actually, I saved myself a bit of headacke, by not installing VB 3.0 (again) By using VBA included in Office 97, I was able to get the Excercise to work (but not w/out some headackes, as I forgot about the proper param passing syntax, etc) But, they both work. So, anyways.. Well, have a good night, and see you tomorrow or so. -vhelp |
I did find someone on doom9 who said that they had ported the Avisynth.h file to Delphi but I haven't been able to find him/her again.
One option for us is to modify the "LoadPlugin" routine in Avisynth to accept native Delphi, BCC and MinGW dlls. (I've posted a feature request on avisynth.org.) I'm sorry I haven't been active in the thread but I decided to upgrade my CPU (on my video development machine) and well...it didn't go well. Right now my Asus A7V MB won't boot [insert 7 page rant on Asus motherboards here] but I'll do some work on my laptop for a while. |
hay MrTibs..
bummer about your "video development machine" issues :cry: Hope you got it all straighten out. Today, I made my first doom9 post. When I first joined, someone had posted an issue about a Demux for VOB files (something I am also very interested in [opening an MPEG2 or VOB and reading a frame]) , and he wanted to have a few peoples try it out. I was one of them. Anyways, I went to post a response, and shore enought, blastid FORUM had a 5 day hold over. Anyways, I've sense moved on. I did mention my DLL Wrapper theory there as well. I tried to keep to the same script (for what it's worth) but it was hard, as I always have ideas going on upstairs he, he.. When I begin to get tired of this, I look for something else to do. I'm always juggling multiple projects and things, quite routinely. Anyways, hope you got your pc issues straighten out, if not, post your issues here, and I'm sure someone will get back to you w/ some assistance. Maybe I can help.. (ADVC) ..Good luck with that pc though. -vhelp |
Thanks for the offer for help on my PC. Basically, I flashed my MB and now it won't boot. It looks like I'll have to do a "hot-flash" to get it working again.
As for this issue, here is an article I found on the web that talks about using C++ objects in Delphi (complete with example code): http://rvelthuis.bei.t-online.de/art...es-cppobjs.htm |
This is an interesting idea, but you must remember that a Delphi filter would almost certainly be extremely slow. C++ is slow enough when you get even slightly algorithmically complicated. To match the performance of, say, Flux you'd end up with about 10% of the code in Delphi and 90% in assembler, which kinda negates the point :).
That said, I do think it's a worthwhile endeavour. |
You are probably right on the speed issue with Delphi but I haven't done any tests so I can't say for sure.
I think you eluded to the bigger issue which is expanding the plugin support of Avisynth beyond MSVC. There is no reason that the Delphi "loader" couldn't be used with a Borland C++ plugin or a Dev-C++ plugin either. I don't know C++ so my code is quite brutal but I'm hoping to have the DLL "loader" in beta in a few weeks. Presently I am writing a [my first] filter to fix the VHS over-sharp problem. Perhaps when I am done, someone who knows C++ can improve the code to make it faster and better. |
Quote:
The most important thing to remember when writing an Avisynth filter is that if your frame is, say, 528x480, your main loop will be processing roughly 400,000 bytes per frame (at least with YUY2), so do as much work outside the loop as possible (initialization of variables, tables, etc.). Also be careful with your pointers, and remember to use GetReadPtr for read-only access and GetWritePtr otherwise. Adding asserts to your code can be very helpful in detecting buffer overruns, which crop up an awful lot when you're new to this kind of coding. When I was first learning I spent quite a bit of time reading other peoples' source code. Stay away from anything involving MMX at first (it's very confusing for the Avisynth/C++ beginner) -- stick to tracing through the C++ versions of all the filter source you can find. Other than that it's definitely worth learning assembler/general optimization techniques if you intend to release your filters to the public, since you'll find a great number of people will complain about the speed ;). If you have any questions about filter coding then post them in here and I'll try my best to help. |
Site design, images and content © 2002-2024 The Digital FAQ, www.digitalFAQ.com
Forum Software by vBulletin · Copyright © 2024 Jelsoft Enterprises Ltd.