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.

 

Go Back   Doom9's Forum > Programming and Hacking > Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 7th April 2002, 19:01   #1  |  Link
Dark-Cracker
Registered User
 
Dark-Cracker's Avatar
 
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
Dark-Cracker is offline   Reply With Quote
Old 7th April 2002, 19:04   #2  |  Link
DSPguru
BeSweet Author
 
DSPguru's Avatar
 
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.
DSPguru is offline   Reply With Quote
Old 7th April 2002, 19:26   #3  |  Link
Dark-Cracker
Registered User
 
Dark-Cracker's Avatar
 
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.
Dark-Cracker is offline   Reply With Quote
Old 8th April 2002, 10:55   #4  |  Link
Swede
Deputy
 
Swede's Avatar
 
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?
Swede is offline   Reply With Quote
Old 8th April 2002, 11:11   #5  |  Link
Nic
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
Nic is offline   Reply With Quote
Old 8th April 2002, 11:35   #6  |  Link
Swede
Deputy
 
Swede's Avatar
 
Join Date: Jan 2002
Location: Sthlm, Sweden
Posts: 1,453
Thnx, I've sent a mail to you. It's easier for me (at least) to move this discussion.
Swede is offline   Reply With Quote
Old 8th April 2002, 14:03   #7  |  Link
Dark-Cracker
Registered User
 
Dark-Cracker's Avatar
 
Join Date: Feb 2002
Posts: 1,195
I you try to use this dll with a frontend in Delphi think to mail me an exemple too :-)

Bye
Dark-Cracker is offline   Reply With Quote
Old 8th April 2002, 18:47   #8  |  Link
Swede
Deputy
 
Swede's Avatar
 
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.
Swede is offline   Reply With Quote
Old 8th April 2002, 18:56   #9  |  Link
DSPguru
BeSweet Author
 
DSPguru's Avatar
 
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.
DSPguru is offline   Reply With Quote
Old 8th April 2002, 19:03   #10  |  Link
Swede
Deputy
 
Swede's Avatar
 
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..?
--
Swede is offline   Reply With Quote
Old 8th April 2002, 19:09   #11  |  Link
DSPguru
BeSweet Author
 
DSPguru's Avatar
 
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'.
DSPguru is offline   Reply With Quote
Old 8th April 2002, 19:19   #12  |  Link
Swede
Deputy
 
Swede's Avatar
 
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?
Swede is offline   Reply With Quote
Old 8th April 2002, 19:24   #13  |  Link
DSPguru
BeSweet Author
 
DSPguru's Avatar
 
Join Date: Oct 2001
Location: On top of a supercompact cardinal
Posts: 3,506
Quote:
Originally posted by Swede
Should I 'init' it in any way?
in mode one - no.

Quote:
And can I get something useful out of a SS since I don't get a return no matter how I try?
what's SS ?

maybe there's a problem with the calling convention..
can't help you with delphi.
DSPguru is offline   Reply With Quote
Old 8th April 2002, 19:37   #14  |  Link
Swede
Deputy
 
Swede's Avatar
 
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?
Swede is offline   Reply With Quote
Old 9th April 2002, 09:06   #15  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,781
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.
LigH is offline   Reply With Quote
Old 9th April 2002, 10:10   #16  |  Link
Swede
Deputy
 
Swede's Avatar
 
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.?.
Swede is offline   Reply With Quote
Old 9th April 2002, 12:37   #17  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,781
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.
LigH is offline   Reply With Quote
Old 9th April 2002, 12:46   #18  |  Link
Swede
Deputy
 
Swede's Avatar
 
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:
In the default {$H+} state, the compiler interprets string (when it appears without a bracketed number after it) as AnsiString.
And AnsiString is a null-term array of chars. Voila!
Swede is offline   Reply With Quote
Old 9th April 2002, 16:06   #19  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,781
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.
My calling command line was:

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 )
LigH is offline   Reply With Quote
Old 9th April 2002, 16:15   #20  |  Link
LigH
German doom9/Gleitz SuMo
 
LigH's Avatar
 
Join Date: Oct 2001
Location: Germany, rural Altmark
Posts: 6,781
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...
LigH is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 19:44.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.