<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
I almost forgot to tell you, AFAIK there's no common way to use
external variables from C libraries within Delphi (I use version 5), i
recommend you to define a function in the library that returns you a
pointer to that variable, and with that function initialize your delphi
variable in the "initialization" section of your import unit.<br>
The best method to convert C headers to Delphi Units is <b>good'ol
human translation</b>, that Dr.Bob tool you used is very basic, and
fails a lot to understand some common C semantics.<br>
<br>
Regards,<br>
<pre class="moz-signature" cols="72">John Villar
Projects Manager
Computadores Flor Hard Soft 2058 C.A.
<a class="moz-txt-link-abbreviated" href="http://www.florhard.com">www.florhard.com</a>
</pre>
<br>
John Villar wrote:
<blockquote cite="mid425FA899.9040701@florhard.com" type="cite">
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
Hi, here are the translations (there's a copy&pasteable chunk in
the end of this message):<br>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef void *(*encoder_init_func)(const
struct SpeexMode *mode);<br>
</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TEncoderInitFunc = function (const mode:
TSpeexMode): pointer; cdecl;<br>
</span></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef void (*encoder_destroy_func)(void
*st);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TEncoderDestroyFun = procedure(st: pointer);</span></font><font
face="Courier New, Courier, monospace"><font size="2"><span
style="font-size: 10pt;"> cdecl;</span></font></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef int (*encode_func)(void *state, void
*in, SpeexBits *bits);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TEncodeFunc = function(state, in: pointer;
var bits: TSpeexBits): integer; cdecl;</span></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef int (*encoder_ctl_func)(void *state,
int request, void *ptr);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TEncoderCtlFunc = function(state: pointer;
request: integer; ptr: pointer): integer; cdecl;</span></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef void *(*decoder_init_func)(const
struct SpeexMode *mode);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TDecoderInitFunc = function(const mode:
TSpeexMode): pointer; cdecl;</span></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef void (*decoder_destroy_func)(void
*st);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TDecoderDestroyFunc = procedure(st: pointer);
cdecl;</span></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef int (*decode_func)(void *state,
SpeexBits *bits, void *out);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TDecodeFunc = function(state: pointer; var
bits: TSpeexBits; out: pointer): integer; cdecl;</span></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef int (*decoder_ctl_func)(void *state,
int request, void *ptr);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TDecoderCtlFunc = function(state: pointer;
request: integer; ptr: pointer): integer; cdecl;</span></font></li>
</ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">typedef int (*mode_query_func)(const void
*mode, int request, void *ptr);</span></font></li>
<ul>
<li><font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;">TModeQueryFunc = function(const mode:
pointer; request: integer; ptr: pointer): integer; cdecl;</span></font></li>
</ul>
</ul>
<br>
Last but not least, the definition of TSpeexMode:<br>
<blockquote><font face="Courier New, Courier, monospace">TSpeexMode =
<b>record</b><br>
mode: pointer;<br>
query: TModeQueryFunc;<br>
modeName: PChar;<br>
modeID: integer;<br>
bitstream_version: integer;<br>
enc_init: TEncodeInitFunc;<br>
enc_destroy: TEncoderDestroyFunc;<br>
enc: TEncodeFunc;<br>
dec_init: TDecoderInitFunc;<br>
dec_destroy: TDecoderDestroyFunc;<br>
dec: TDecodeFunc;<br>
enc_ctl: TEncoderCtlFunc;<br>
dec_ctl: TDecoderCtlFunc;<br>
<b>end;</b><br>
</font><br>
</blockquote>
The issue with<font face="Times New Roman" size="2"><span
style="font-size: 10pt;"> extern
const SpeexMode speex_nb_mode;<o:p></o:p></span></font>
<font face="Times New Roman" size="2"><span style="font-size: 10pt;"></span></font>is
solved with a global variable in your unit, see below.<br>
<br>
Putting it all togheter in one big-fat-single-n-nice copy&paste
chunk:<br>
<blockquote><small><font face="Courier New, Courier, monospace"
size="2"><small><span style="font-size: 10pt;">type<br>
TEncoderInitFunc = function (const mode: TSpeexMode): pointer;
cdecl;</span></small></font><font face="Courier New, Courier, monospace"
size="2"><small><span style="font-size: 10pt;"></span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TEncoderDestroyFun = procedure(st:
pointer);</span></small></font><font
face="Courier New, Courier, monospace"><font size="2"><small><span
style="font-size: 10pt;"> cdecl;</span></small></font></font><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TEncodeFunc = function(state, in:
pointer; var bits: TSpeexBits): integer; cdecl;</span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TEncoderCtlFunc = function(state:
pointer; request: integer; ptr: pointer): integer; cdecl;</span></small></font><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TDecoderInitFunc = function(const
mode: TSpeexMode): pointer; cdecl;</span></small></font><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TDecoderDestroyFunc = procedure(st:
pointer); cdecl;</span></small></font><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TDecodeFunc = function(state:
pointer; var bits: TSpeexBits; out: pointer): integer; cdecl;</span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TDecoderCtlFunc = function(state:
pointer; request: integer; ptr: pointer): integer; cdecl;</span></small></font></small><br>
<small><font face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"> TModeQueryFunc = function(const
mode: pointer; request: integer; ptr: pointer): integer; cdecl;<br>
<br>
</span></small></font></small><small><font
face="Courier New, Courier, monospace" size="2"><small><span
style="font-size: 10pt;"></span></small></font><font
face="Courier New, Courier, monospace"> TSpeexMode = record</font></small><br>
<small><font face="Courier New, Courier, monospace">
mode: pointer;</font></small><br>
<small><font face="Courier New, Courier, monospace">
query: TModeQueryFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
modeName: PChar;</font></small><br>
<small><font face="Courier New, Courier, monospace">
modeID: integer;</font></small><br>
<small><font face="Courier New, Courier, monospace">
bitstream_version: integer;</font></small><br>
<small><font face="Courier New, Courier, monospace">
enc_init: TEncodeInitFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
enc_destroy: TEncoderDestroyFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
enc: TEncodeFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
dec_init: TDecoderInitFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
dec_destroy: TDecoderDestroyFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
dec: TDecodeFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
enc_ctl: TEncoderCtlFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace">
dec_ctl: TDecoderCtlFunc;</font></small><br>
<small><font face="Courier New, Courier, monospace"> end;<br>
<br>
var<br>
speex_nb_mode: TSpeexMode;<br>
</font></small></blockquote>
<font face="Courier New, Courier, monospace" size="2"><span
style="font-size: 10pt;"><b><br>
</b></span></font>Cheers, and good luck,<br>
<br>
<pre class="moz-signature" cols="72">John Villar
Projects Manager
Computadores Flor Hard Soft 2058 C.A.
<a class="moz-txt-link-abbreviated" href="http://www.florhard.com">www.florhard.com</a>
</pre>
<br>
<br>
H. Serdar Karahan wrote:
<blockquote cite="mid425fb5e3.5c7d20c6.05c0.ffff971e@mx.gmail.com"
type="cite">
<meta http-equiv="Content-Type" content="text/html; ">
<meta name="Generator" content="Microsoft Word 11 (filtered medium)">
<o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="place"><!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
p
        {mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:Arial;
        color:windowtext;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
/* List Definitions */
@list l0
        {mso-list-id:1586911404;
        mso-list-template-ids:-1223425872;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:.5in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:1.0in;
        mso-level-number-position:left;
        text-indent:-.25in;
        mso-ansi-font-size:10.0pt;
        font-family:"Courier New";
        mso-bidi-font-family:"Times New Roman";}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
-->
</style></o:SmartTagType>
<div class="Section1">
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;">Hello Mr. Villar,</span></font><o:p></o:p></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;">I want to ask you a few
questions. I'm trying to write the
wrapper class of Speex in <st1:place w:st="on">Delphi</st1:place> for
your
no-working project to get it worked. I merged the .h files under
include/speex
directory at one file and I used the header converter program (<a
href="http://www.drbob42.com/delphi/..%5Ctools%5Cheadconv.htm">http://www.drbob42.com/delphi/..%5Ctools%5Cheadconv.htm</a>)
to create the LibSpeex.pas file which will be wrapper. But it does not
convert
some parts. For example in header file the following part:</span></font><o:p></o:p></p>
<ul type="disc">
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef void
*(*encoder_init_func)(const
struct SpeexMode *mode); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef void
(*encoder_destroy_func)(void
*st); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef int
(*encode_func)(void *state, void
*in, SpeexBits *bits); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef int
(*encoder_ctl_func)(void *state,
int request, void *ptr); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef void
*(*decoder_init_func)(const
struct SpeexMode *mode); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef void
(*decoder_destroy_func)(void
*st); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef int
(*decode_func)(void *state,
SpeexBits *bits, void *out); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef int
(*decoder_ctl_func)(void *state,
int request, void *ptr); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef int
(*mode_query_func)(const void
*mode, int request, void *ptr); <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">typedef struct SpeexMode { <o:p></o:p></span></font></li>
<ul type="circle">
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">const void *mode; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">mode_query_func query; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;"><o:p> </o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">char *modeName; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">int modeID; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">int bitstream_version; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">encoder_init_func enc_init; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">encoder_destroy_func
enc_destroy; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">encode_func enc; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">decoder_init_func dec_init; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">decoder_destroy_func
dec_destroy; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">decode_func dec; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">encoder_ctl_func enc_ctl; <o:p></o:p></span></font></li>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">decoder_ctl_func dec_ctl;<o:p></o:p></span></font></li>
</ul>
<li class="MsoNormal" style=""><font face="Times New Roman"
size="2"><span style="font-size: 10pt;">} SpeexMode;<o:p></o:p></span></font></li>
</ul>
<p class="MsoNormal"><font face="Times New Roman" size="2"><span
style="font-size: 10pt;">I had trouble here, I cannot define and
compile the SpeexMode type. How
did you do that, please help me. Also the part <o:p></o:p></span></font></p>
<p><font face="Times New Roman" size="2"><span
style="font-size: 10pt;">extern
const SpeexMode speex_nb_mode;<o:p></o:p></span></font></p>
<p><font face="Times New Roman" size="2"><span
style="font-size: 10pt;">that I
could not access this variable. I think you create a SpeexNbMode type
but how
did you reach it from the dll? Did you use the GetProcAddress or
different
thing? <o:p></o:p></span></font></p>
<p><font face="Times New Roman" size="2"><span
style="font-size: 10pt;">Do you
know is there a good way to convert or generate wrapper file of the
dll? I
don’t want to use all the functionalities of the Speex, only in low
bitrate, encoding and decoding. Please help me in writing this wrapper.
I’m
not so good in <st1:place w:st="on">Delphi</st1:place>.<o:p></o:p></span></font></p>
<p><font face="Times New Roman" size="2"><span
style="font-size: 10pt;">If you
answer and help me I will be very happy.<o:p></o:p></span></font></p>
<p><font face="Times New Roman" size="2"><span
style="font-size: 10pt;">Thanks in
advance.<o:p></o:p></span></font></p>
<p><font face="Times New Roman" size="2"><span
style="font-size: 10pt;">H. Serdar
Karahan<o:p></o:p></span></font></p>
<p class="MsoNormal"><font face="Arial" size="2"><span
style="font-size: 10pt; font-family: Arial;"><o:p> </o:p></span></font></p>
</div>
</blockquote>
<pre wrap="">_______________________________________________
Speex-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Speex-dev@xiph.org">Speex-dev@xiph.org</a>
<a class="moz-txt-link-freetext" href="http://lists.xiph.org/mailman/listinfo/speex-dev">http://lists.xiph.org/mailman/listinfo/speex-dev</a>
</pre>
</blockquote>
</body>
</html>