Board index » delphi » classes in Dll

classes in Dll

I have a class build in c++ in a Dll.
Can anyone tell me how can i use it in delphi 2.0?
Thank you.

Nuno Alves
nm...@centaurus.dee.fct.unl.pt

 

Re:classes in Dll


In article <01bc6090$63706a40$0f7b8...@pc-4.dee.fct.unl.pt>,
   "Nuno Alves" <nm...@centaurus.fct.unl.pt> wrote:

Quote
>I have a class build in c++ in a Dll.
>Can anyone tell me how can i use it in delphi 2.0?

I don't think this is possible.

You can pass objects back and forth that are defined using C++ virtual
semantics, but that is about the extent. for example, how would you
create an instance? C++ objects can't have virtual constructors, and Object
pascal would have no way of getting the constructor code.

--
Brad Aisa     web archive: http://www.interlog.com/~baisa/
email (anti-spam encoded): baisa"AT SYMBOL"interlog.com

"The highest responsibility of philosophers is to serve as the
guardians and integrators of human knowledge."   -- Ayn Rand

Re:classes in Dll


On Thu, 15 May 97 03:16:16 GMT, ba...@ERASETHISinterlog.com (Brad

Quote
Aisa) wrote:
>In article <01bc6090$63706a40$0f7b8...@pc-4.dee.fct.unl.pt>,
>   "Nuno Alves" <nm...@centaurus.fct.unl.pt> wrote:
>>I have a class build in c++ in a Dll.
>>Can anyone tell me how can i use it in delphi 2.0?

>I don't think this is possible.

It's often possible with a little assistance from the DLL.  There is
code in Delphi Magazine that shows how to do it.  You need for the DLL
to export two special functions, one to create and return a new
instance, and one to destroy an instance, but the rest can be handled
by defining a COM-like object (a Delphi class with all "virtual
abstract" routines that map exactly to the C++ class's routines).

If you have no source code for the C++ DLL you will have a lot more
trouble, because you have to know the sequence of the DLL's routines.
And if there's no exported "create an instance" routine (known in the
COM lingo as a "class factory") you're SOL.
J. Merrill / Analytical Software Corp

Re:classes in Dll


Nuno Alves <nm...@centaurus.fct.unl.pt> wrote in article
<01bc6090$63706a40$0f7b8...@pc-4.dee.fct.unl.pt>...

Quote
> I have a class build in c++ in a Dll.
> Can anyone tell me how can i use it in delphi 2.0?
> Thank you.

> Nuno Alves
> nm...@centaurus.dee.fct.unl.pt

Easily; here is some code to show you how to do it; it includes
project1.dpr (the exe that will instantiate the class) and test.dpr (the
DLL which will provide the class) - my example uses a delphi-created DLL
but it shouldn't be difficult to xlate into C++.

If you have any questions, e-mail me.

Joubert

begin 600 Project1.~dp
M<')O9W)A;2!0<F]J96-T,3L-"@T*=7-E<PT*("!&;W)M<RP-"B @56YI=#$@
M:6X@)U5N:70Q+G!A<R<@>T9O<FTQ?3L-"@T*>R12("HN4D53?0T*#0IB96=I
M;@T*("!!<'!L:6-A=&EO;BY);FET:6%L:7IE.PT*("!!<'!L:6-A=&EO;BY#
M<F5A=&5&;W)M*%1&;W)M,2P@1F]R;3$I.PT*("!!<'!L:6-A=&EO;BY2=6X[
)#0IE;F0N#0H@
`
end
end

begin 600 Project1.dpr
M<')O9W)A;2!0<F]J96-T,3L-"@T*=7-E<PT*("!&;W)M<RP-"B @56YI=#$@
M:6X@)U5N:70Q+G!A<R<@>T9O<FTQ?3L-"@T*>R12("HN4D53?0T*#0IB96=I
M;@T*("!!<'!L:6-A=&EO;BY);FET:6%L:7IE.PT*("!!<'!L:6-A=&EO;BY#
M<F5A=&5&;W)M*%1&;W)M,2P@1F]R;3$I.PT*("!!<'!L:6-A=&EO;BY2=6X[
)#0IE;F0N#0H@
`
end
end

begin 600 Project1.dsk
<uuencoded_portion_removed>
9"EM"<F5A:W!O:6YT<UT-"D-O=6YT/3 -"FQL
`
end

begin 600 Project1.res
M`````" ```#__P``__\```````````````````````#H`@``( ```/__`P#_
M_P$``````! 0"1P``````````"@````@````0 ````$`! ````````(`````
M``````````````````````````" ``" ````@( `@ ```( `@ " @ ``@("
M`,# P ```/\``/\```#__P#_````_P#_`/__``#___\```?X=X:&A_AW8/@X
M-W ````'^'=H:&?X=X#X.#=P````!_AWAH:'^'=@^#@W< ````?X=VAH9_AW
M@/@X-W ````'^'>&AH?X=V#X.#=P````!_AW:&AG^'> ^#@W< ``=W=W=W=W
M=W=W</@X-W!W`'B(B(B(B'=W=W#X.#=PAP!W=W=W=W=W=W=P^#@W<'<``'?_
MB(B(B(B(@/@X-W!P````=_^'=W=W=W#X.#=P``````!W_X=XB(=P\X=S< ``
M`````'?_AXAX#SAX=S<`````````=_]W@/.'@ =S< ````````!W_P\X>(B(
M=S<``````````'#SAX,#`P>'< ````````!P.'@`````=S ````````````!
M$1$1$1$`````````````F;F9N9F9`````````````)FYN9NYN0``````````
M``F;N;N9NYD````````````)FYF;F9F9````````````"9N;F[F[F0``````
M``````";FYNYF9 `````````````FYFYNYL```````````````F9N9F0````
M````````````F;N9D ````````````````F9N0``````````````````"9D`
M``````````````````"9````````````````````D ``````````````````
M``````#@```/X ``#^ ```_@```/X ``#^ ```\````#`````P````/ ```'
M\ ``#_P```__```'_\ !@__P``'__ *@__P/\/_^``#__\ #___ `___@ /_
M_X #__^ `___P ?__\ /___@'___\!____@____^/____S____]______Q0`
M```P````__\.`$T`00!)`$X`20!#`$\`3@```````````! 0"1P`````````
5`````0`!`" @! `!``0`Z (```$`
`
end

begin 600 test.~dp
<uuencoded_portion_removed>
'#0H@#0H-"@T*
`
end

begin 600 test.dpr
<uuencoded_portion_removed>
(+@T*( T*#0H-
`
end

begin 600 test.dsk
<uuencoded_portion_removed>
F97-=#0I#;W5N=#TP#0I;0G)E86MP;VEN='-=#0I#;W5N=#TP#0H*
`
end

begin 600 test.res
M`````" ```#__P``__\```````````````````````#H`@``( ```/__`P#_
M_P$``````! 0"1P``````````"@````@````0 ````$`! ````````(`````
M``````````````````````````" ``" ````@( `@ ```( `@ " @ ``@("
M`,# P ```/\``/\```#__P#_````_P#_`/__``#___\```?X=X:&A_AW8/@X
M-W ````'^'=H:&?X=X#X.#=P````!_AWAH:'^'=@^#@W< ````?X=VAH9_AW
M@/@X-W ````'^'>&AH?X=V#X.#=P````!_AW:&AG^'> ^#@W< ``=W=W=W=W
M=W=W</@X-W!W`'B(B(B(B'=W=W#X.#=PAP!W=W=W=W=W=W=P^#@W<'<``'?_
MB(B(B(B(@/@X-W!P````=_^'=W=W=W#X.#=P``````!W_X=XB(=P\X=S< ``
M`````'?_AXAX#SAX=S<`````````=_]W@/.'@ =S< ````````!W_P\X>(B(
M=S<``````````'#SAX,#`P>'< ````````!P.'@`````=S ````````````!
M$1$1$1$`````````````F;F9N9F9`````````````)FYN9NYN0``````````
M``F;N;N9NYD````````````)FYF;F9F9````````````"9N;F[F[F0``````
M``````";FYNYF9 `````````````FYFYNYL```````````````F9N9F0````
M````````````F;N9D ````````````````F9N0``````````````````"9D`
M``````````````````"9````````````````````D ``````````````````
M``````#@```/X ``#^ ```_@```/X ``#^ ```\````#`````P````/ ```'
M\ ``#_P```__```'_\ !@__P``'__ *@__P/\/_^``#__\ #___ `___@ /_
M_X #__^ `___P ?__\ /___@'___\!____@____^/____S____]______Q0`
M```P````__\.`$T`00!)`$X`20!#`$\`3@```````````! 0"1P`````````
5`````0`!`" @! `!``0`Z (```$`
`
end

begin 600 Unit1.~df
M_PH`5$9/4DTQ`# 0'P$``%101C &5$9O<FTQ!49O<FTQ!$QE9G0#_0`#5&]P
M`Z\`!5=I9'1H`[,!!DAE:6=H= ,L`0=#87!T:6]N!@5&;W)M,0I&;VYT+D-O
M;&]R!PQC;%=I;F1O=U1E>'0+1F]N="Y(96EG:'0"\PE&;VYT+DYA;64&#4U3
M(%-A;G,@4V5R:68*1F]N="Y3='EL90L`#5!I>&5L<U!E<DEN8V@"> I497AT
M2&5I9VAT`A `!U1"=71T;VX'0G5T=&]N,01,969T`F$#5&]P`C(%5VED=&@#
MVP`&2&5I9VAT`DL'0V%P=&EO;@852&]W(&]L9"!I<R!T:&4@0VQA<W,_"%1A
A8D]R9&5R`@`'3VY#;&EC:P<,0G5T=&]N,4-L:6-K````
`
end
end

begin 600 Unit1.~pa
M=6YI="!5;FET,3L-"@T*:6YT97)F86-E#0H-"G5S97,-"B @5VEN9&]W<RP@
M365S<V%G97,L(%-Y<U5T:6QS+"!#;&%S<V5S+"!'<F%P:&EC<RP@0V]N=')O
M;',L($9O<FUS+"!$:6%L;V=S+ T*("!3=&1#=')L<SL-"@T*='EP90T*("!4
M1F]R;3$@/2!C;&%S<RA41F]R;2D-"B @("!"=71T;VXQ.B!40G5T=&]N.PT*
M(" @('!R;V-E9'5R92!"=71T;VXQ0VQI8VLH4V5N9&5R.B!43V)J96-T*3L-
M"B @<')I=F%T90T*(" @('L@4')I=F%T92!D96-L87)A=&EO;G,@?0T*("!P
M=6)L:6,-"B @("![(%!U8FQI8R!D96-L87)A=&EO;G,@?0T*("!E;F0[#0H-
M"G1Y<&4-"B @=$UY1&QL0VQA<W,@/2!C;&%S<PT*(" @(&9U;F-T:6]N('=H
M871)<UEO=7)!9V4Z(&EN=&5G97([('9I<G1U86P[(&%B<W1R86-T.R O+VUU
M<W0@8F4@9&5C;&%R960@87,@=FER='5A;#L@86)S=')A8W0[#0H@(&5N9#L-
M"@T*<')O8V5D=7)E(&=E=$-L87-S*'9A<B!O8FI0;VEN=&5R*3L@97AT97)N
M86P@)W1E<W0N9&QL)SL-"@T*=F%R#0H@($9O<FTQ.B!41F]R;3$[#0H-"FEM
M<&QE;65N=&%T:6]N#0H-"GLD4B J+D1&37T-"@T*<')O8V5D=7)E(%1&;W)M
M,2Y"=71T;VXQ0VQI8VLH4V5N9&5R.B!43V)J96-T*3L-"G9A<B!M>41L;$-L
M87-S.B!T37E$;&Q#;&%S<SL-"F)E9VEN#0H@('1R>0T*(" @(&=E=$-L87-S
M*&UY1&QL0VQA<W,I.PT*(" @(&UE<W-A9V5$;&<H:6YT5&]3='(H;7E$;&Q#
M;&%S<RYW:&%T27-9;W5R06=E*2P@;71);F9O<FUA=&EO;BP@6VUB3VM=+" P
K*3L-"B @97AC97!T#0H@(&5N9#L-"B @(" -"F5N9#L-"@T*96YD+@T*(" P
`
end

begin 600 Unit1.dcu
<uuencoded_portion_removed>
`
end

begin 600 Unit1.dfm
M_PH`5$9/4DTQ`# 0'P$``%101C &5$9O<FTQ!49O<FTQ!$QE9G0#_0`#5&]P
M`Z\`!5=I9'1H`[,!!DAE:6=H= ,L`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