Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
7th April 2002, 19:01 | #1 | Link |
Registered User
Join Date: Feb 2002
Posts: 1,195
|
How Using "Beesweet1.3b8.dll" with Delphi Prog ?
i hope DspGuru could help me. i try to integrate the beesweet dll with an GUI in Delphi someone could help me because i can't translate in delphi how i must call the fonction of this dll.
Thank u for helping me :-) PS: sorry for my crap english, i am a little frenchy |
7th April 2002, 19:04 | #2 | Link |
BeSweet Author
Join Date: Oct 2001
Location: On top of a supercompact cardinal
Posts: 3,506
|
@Dark-Cracker
you're english is okay i'm not a delphi programmer, so i can't help you much. please check "example2.c" that included in the package, you'll see the main idea of usage. EDIT : LigH is known to be a very good delphi programmer, mayB he could help you.
__________________
FAQs : BeSweet, Audio :readfaq: Homepage : DSPguru's Webpage http://dspguru.notrace.dk/cs.gif Guides : Multilingual Guides of my tools http://dspguru.notrace.dk/1zhelp.gif |
7th April 2002, 19:26 | #3 | Link |
Registered User
Join Date: Feb 2002
Posts: 1,195
|
Thank
Ok i will try to see in you file exemple2.c i have also the vstripGUi source (an delphi GUI who use Vstrip.dll, this will surely help me)
But if someone have an idear on how to use the beesweet dll in a Delphi prog, he can mail me an exemple :-) thank dspguru for your quick answer and very nice work with "beesweet", good luck for the next release. PS: if LIGH have an idear he can contact me. |
8th April 2002, 10:55 | #4 | Link |
Deputy
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
|
I thought I could give Dark-Cracker a hand but..
Is there *any* more docs about using besweet.dll than the 2 short examples? (For instance: Why is there a deinit as the first command in example2? I think I've looked everywhere) I was just going to check that i sent the pascal-params correctly but I don't seem to get anything working, perhaps I'm just stupid If I trace the code I can see that the first command in the array (the deinit) seems to trigger something in the MVCRT.dll but anything else just dies, somewhere in the mvcrt.dll, perhaps there something wrong with the version of that .dll in my machine? Even though besweet.exe does the job perfect? |
8th April 2002, 11:11 | #5 | Link |
Moderator
Join Date: Oct 2001
Location: England
Posts: 3,285
|
Hi ya Swede,
My changes to DVD2AVI kind of prompted DG to make the recent changes to BeSweet.DLL. So DG, (with a little input from me) invented the current interface for the DLL. So if you need a hand then shout me, (but I know nothing about pascal/delphi so im not sure how much use ill be ) Cheers, -Nic |
8th April 2002, 18:47 | #8 | Link |
Deputy
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
|
I'm not trying to keep this secret, I assure you all... It's just that I don't like to be the one standing 'caught with you're pants down'. (AC/DC anyone?)
Right, I've been trying to get the besweet.dll to work in Delphi. I've got so far that I can make an .mp3 out of a .ac3 but not without the whole thing to crash on me with 'Floating point error' right at the end. This is an part of the Delphi/Pascal-code: const argc = 18; argv: Array [1..argc] of String = ('Project1','-core(','-input','Test.ac3','-output', 'Test.mp3','-logfile','besweet.txt',')','-azid(','-z1','-b1',')','-lame(','-b','128',')',#0#0); type BSfarproc = procedure (argc: Integer; arcv: pointer); cdecl; var BeSweet: BSfarproc; hDLL: HMODULE; begin hDLL:=LoadLibrary('BeSweet.dll'); if hDLL<>0 then begin ListBox.Items.Add('dll found!'); BeSweet:=GetProcAddress(hDLL,'BeSweet'); if Assigned(BeSweet) then begin BeSweet(argc,@argv); argv[1]:='deinit'; BeSweet(argc,@argv); if not FreeLibrary(hDLL) then ListBox.Items.Add('Not Free''d!'); end; end else ListBox.Items.Add('dll not Found!'); end; The problem seems to be that somewhere inside the first BeSweet-call something goes wrong, this might be 'cause I've misunderstood something, but trace'ing the code doesn't help me. The procedure BeSweet is executed but doesn't return, at asm-level, but makes an Floating point error-fault, which is captured but Delhpi. It doesn't matter if I include the last #0#0 or not, there has to be something else that I don't see... Well, if anyone has an idea, feel free to speak up. |
8th April 2002, 18:56 | #9 | Link |
BeSweet Author
Join Date: Oct 2001
Location: On top of a supercompact cardinal
Posts: 3,506
|
1. shouldn't agrc be 14 in your case ?
2. please post logfile.
__________________
FAQs : BeSweet, Audio :readfaq: Homepage : DSPguru's Webpage http://dspguru.notrace.dk/cs.gif Guides : Multilingual Guides of my tools http://dspguru.notrace.dk/1zhelp.gif |
8th April 2002, 19:03 | #10 | Link |
Deputy
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
|
#1. 14? This is one of the things, how should I count?
-- 'Project1','-core(','-input','Test.ac3','-output', 'Test.mp3','-logfile','besweet.txt',')','-azid(','-z1','-b1',')','-lame(','-b','128',')',#0#0 -- What counts? -- #2. That's another prob. Since it crashes on me I don't get the log-file. It seems that it does'n get written until the 'deinit'-cmd..? -- |
8th April 2002, 19:09 | #11 | Link |
BeSweet Author
Join Date: Oct 2001
Location: On top of a supercompact cardinal
Posts: 3,506
|
1)
1) 'Project1', 2) '-core(', 3) '-input', 4) 'Test.ac3', 5) '-output', 6) 'Test.mp3', 7) '-logfile', 8) 'besweet.txt', 9) ')', 10) '-azid(', 11) '-z1', 12) '-b1', 13) ')', 14) '-lame(', 15) '-b', 16) '128' 17) ,')' 2) 'deinit', found in 'example2', is only relevant when using "-input ac3input". (meaning - there is NO input file, input is delievered thru AC3_Bursts. but that's not your case. what you're implementing is what appears in 'example'.
__________________
FAQs : BeSweet, Audio :readfaq: Homepage : DSPguru's Webpage http://dspguru.notrace.dk/cs.gif Guides : Multilingual Guides of my tools http://dspguru.notrace.dk/1zhelp.gif |
8th April 2002, 19:19 | #12 | Link |
Deputy
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
|
Ok, so 17 seems to be correct. Tried that.
And, yes I've been trying just to get this to work, just as fluent and simple as besweet.exe with the same cmd-line, but to no avail... It just crashes with a Floating point err. I'm quite sure that I'm doing something wrong here in my Pascal-interpretation but I've *really* tried to step through in the debugger and can't find the reason... What's the first parameter? Do you try to grab the win-handle to output anything? Or why is it there? Should I 'init' it in any way? And can I get something useful out of a SS since I don't get a return no matter how I try? |
8th April 2002, 19:24 | #13 | Link | ||
BeSweet Author
Join Date: Oct 2001
Location: On top of a supercompact cardinal
Posts: 3,506
|
Quote:
Quote:
maybe there's a problem with the calling convention.. can't help you with delphi.
__________________
FAQs : BeSweet, Audio :readfaq: Homepage : DSPguru's Webpage http://dspguru.notrace.dk/cs.gif Guides : Multilingual Guides of my tools http://dspguru.notrace.dk/1zhelp.gif |
||
8th April 2002, 19:37 | #14 | Link |
Deputy
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
|
Ok, no init. But still, what's the first param? deinit or anything else?
SS = Single Step, I've been stepping though the code to no avail. I've written a few dll's and since you all say this works, and I doubt not!, it *has* to mean that I'm doing something wrong. I just have to find out what! There are a few ways to call a C-function from a Pascal-proc but most of the errors comes from pop'ing/not pop'ing bytes from the stack. Either way the call *should* return and the err *should* emerge afterwards which is not the case here. Maybe it's got something to do with MSVCRT.DLL, which if I understand correct is a C Runtime-lib, and I might not initiate correct? |
9th April 2002, 09:06 | #15 | Link |
German doom9/Gleitz SuMo
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,784
|
There is at least one more mistake: The C construct "char **" is incorrectly translated into "array[..] of String" - instead, it must be an "array[..] of PChar", because C applications are expecting ASCIIZ strings (Char arrays closed with a trailing #0), not PASCAL strings (which have a length prefix). Exactly, "argv" is an array of Pointers to arrays of chars; because the argument count is submitted via "argc", the last 'argv member' does not need to be #0#0.
Besides that, the "cdecl" calling convention is essential, of course. (No promise, but I might try this today and post my results. Depends on my time.) Last edited by LigH; 9th April 2002 at 09:09. |
9th April 2002, 10:10 | #16 | Link |
Deputy
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
|
Strictly Pascal you're correct, but Delphi's String is (since ver 3 I think) the same as a Pchar. (You can get the Pascal-string is you excplicitly declares a String[len] or ShortString). Hence the argv: Array [1..argc] of String; is exactly the same as char ** since I deference it in the call @argv.
(And the #0#0 was just a test to see if the reason it crashes *right* at the end had something to do with #of argc.) I *do* get the mp3 but before the log-file gets flushed to disk the whole thing crashes, somewhere inside but before it returns.?. |
9th April 2002, 12:37 | #17 | Link |
German doom9/Gleitz SuMo
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,784
|
Of course, you shall try to surround the BeSweet function calls by "try...except" or "try...finally" blocks and hope to catch the exception, so that the application at least does not crash anymore. But as you are writing that the function does not really return, I'm starting to doubt it being the one and only solution...
And maybe you can try to add "argc:=1" before calling BeSweet with the "deinit" parameter. - I think I'll definitely have to try for myself; so 'til later. - (P.S.: It's a really new information to me that PChar shall be the standard for strings in Delphi - I always thought that the default for 16-bit Delphi is ShortString, the same as Turbo Pascal strings with 1 byte length prefix, and for 32-bit Delphi it's WideString - or depending on the project options; but PChar... I read the documentation so many times, I thought I would know if it was so...) Last edited by LigH; 9th April 2002 at 12:43. |
9th April 2002, 12:46 | #18 | Link | |
Deputy
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
|
If I SS I can see that the params are pushed to the stack as they should, the besweet.besweet is called and tracing that show that is just a 'wrapper' with then calls another func, and if I set a breakpt here it never returns, it just crashes, which I can try..except but it to late anyway
So the next call using deinit is never done and as DSPguru said it shouldn't be there anyway, so I deleted that part. And about the strings your'e almost correct but: Quote:
|
|
9th April 2002, 16:06 | #19 | Link |
German doom9/Gleitz SuMo
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,784
|
I just tried the same (almost - for debugging purposes, it became a bit bigger than Swede's example; especially Params2ArgVect is very "schoolish"). To my surprise, it simply returned the usual error message, as if no or a wrong parameter was submitted. Finally, the DLL simply stopped the whole application instead of returning to the function call.
Although searching for many minutes, I couldn't find substancial differences to Swede's example. So if anyone would like to look at it, here is my source (I hope you don't mind the quite huge printout too much): Code:
program BS_CLI; {$APPTYPE CONSOLE} uses Windows, SysUtils; const BeSweetFuncName = 'BeSweet'; BeSweetLibName = 'BeSweet.dll'; type TArgVect = array[Byte] of PChar; TBeSweetProc = procedure(ArgCount: Integer; ArgVPtr: Pointer); cdecl; var BeSweetProc: TBeSweetProc; GArgCount: Integer; GArgVect: TArgVect; hDLL: THandle; procedure Params2ArgVect(var ArgCount: Integer; var ArgVect: TArgVect); var ParamIdx, ArgLen: Word; ArgStr: String; ArgPC: PChar; begin ArgCount := 0; if ParamCount > 0 then begin Write(ParamCount, ' arguments: "'); for ParamIdx := 0 to Pred(ParamCount) do begin ArgStr := ParamStr(Succ(ParamIdx)); ArgLen := Length(ArgStr); ArgPC := StrAlloc(Succ(ArgLen)); ArgVect[ParamIdx] := StrPCopy(ArgPC, ArgStr); Write(ArgPC, ' ') end; WriteLn(^H'"'); ArgCount := ParamCount end end; begin WriteLn('BeSweet - Delphi CLI wrapper'); FillChar(GArgVect, SizeOf(GArgVect), 0); Params2ArgVect(GArgCount, GArgVect); hDLL := LoadLibrary(BeSweetLibName); if hDLL = 0 then WriteLn('Could not load module "'+BeSweetLibName+'"') else begin BeSweetProc := TBeSweetProc(GetProcAddress(hDLL, BeSweetFuncName)); if Assigned(BeSweetProc) then try try BeSweetProc(GArgCount, @GArgVect); WriteLn('OK') except on E:Exception do begin WriteLn(E.Message) end end finally if not FreeLibrary(hDLL) then WriteLn('Library "'+BeSweetLibName+'" could not be released.') end else WriteLn('Could not locate function "'+BeSweetFuncName +' in module "'+BeSweetLibName+'"') end end. BS_CLI.exe -core( -input H:\Programme\BeSweet\AC3TEST.AC3 -output I:\AC3TEST.MP3 -logfile I:\AC3TEST.LOG ) -ota( -g max ) -azid( -f1 -n1 ) -lame( -b 160 ) |
9th April 2002, 16:15 | #20 | Link |
German doom9/Gleitz SuMo
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,784
|
I forgot: When the package of all the required DLLs is not present, calling the BeSweet DLL resulted in an Access Violation in MSVCRT.DLL - not my preferred solution, I must say...
|
|
|