Board index » cppbuilder » Using VCL components in a DLL

Using VCL components in a DLL

Hello all,

A beginner's question for those wizards out there:

I'm trying to write a dll that uses a (third-party) component for
serial IO. The component needs a call back-function for it's OnReceive
event. The dll itself uses no forms. The component defines this event
as:

typedef void __fastcall (__closure *TCommRXCharEvent) (DWORD Count)

When I write my code like this:

SetRxEvent(CommRxChar);

the compiler complains with:
 E2034 Cannot convert 'void (_fastcall *)(unsigned long)' to 'void
(_fastcall * (_closure )(unsigned long))(unsigned long)'.

I can't figure out how to use __closure from the online help. Perhaps
someone is able to help me, I'm completely stuck ;-(.

Thanks in advance,

Johan.

 

Re:Using VCL components in a DLL


By using the __closure, the component is expecting a member function as an
event handler, but you are not passing a member function to it.  Member
functions have a hidden 'this' pointer passed as the first parameter, that's
what __closure is about.  Your function doesn't have this.

Gambit

Quote
Johan Kwisthout <j.kwisth...@observator.com> wrote in message

news:3974642b.28460784@obsserver...
Quote
> The component defines this event as:

> typedef void __fastcall (__closure *TCommRXCharEvent) (DWORD Count)

> When I write my code like this:

> SetRxEvent(CommRxChar);

> the compiler complains with:

>  E2034 Cannot convert 'void (_fastcall *)(unsigned long)' to 'void
> (_fastcall * (_closure )(unsigned long))(unsigned long)'.

Re:Using VCL components in a DLL


Johan,

What Remy's answer means, in terms of what you have to do about it, is make
your function a member of whatever class you will have manage the data that
comes from the serial port.  I add this because you identify yourself as a
beginner, so it isn't clear whether you're new to C++ programming or just
the magic of a RAD tool like BCB.  I was bit by this this morning, and since
I have been programming for a while, it didn't take too long for me to
figure out that this very cryptic message meant that BCB doesn't like event
handlers that are not member functions of some class (although I don't know
if that applies in all contexts or just in the context of the application
framework components), and what to do about it.  But I'd wager that someone
who is a beginner may have a little more trouble with it.

HTH

Ted
R.E. Byers
rtby...@bconnex.net

Quote
Remy Lebeau <gambi...@gte.net> wrote in message

news:8l2091$14e14@bornews.borland.com...
Quote
> By using the __closure, the component is expecting a member function as an
> event handler, but you are not passing a member function to it.  Member
> functions have a hidden 'this' pointer passed as the first parameter,
that's
> what __closure is about.  Your function doesn't have this.

> Gambit

> Johan Kwisthout <j.kwisth...@observator.com> wrote in message
> news:3974642b.28460784@obsserver...
> > The component defines this event as:

> > typedef void __fastcall (__closure *TCommRXCharEvent) (DWORD Count)

> > When I write my code like this:

> > SetRxEvent(CommRxChar);

> > the compiler complains with:

> >  E2034 Cannot convert 'void (_fastcall *)(unsigned long)' to 'void
> > (_fastcall * (_closure )(unsigned long))(unsigned long)'.

Re:Using VCL components in a DLL


On Tue, 18 Jul 2000 15:48:32 -0400, "Ted Byers" <rtby...@bconnex.net>
wrote:

Quote
>Johan,

>What Remy's answer means, in terms of what you have to do about it, is make
>your function a member of whatever class you will have manage the data that
>comes from the serial port.  I add this because you identify yourself as a
>beginner, so it isn't clear whether you're new to C++ programming or just
>the magic of a RAD tool like BCB.  I was bit by this this morning, and since
>I have been programming for a while, it didn't take too long for me to
>figure out that this very cryptic message meant that BCB doesn't like event
>handlers that are not member functions of some class (although I don't know
>if that applies in all contexts or just in the context of the application
>framework components), and what to do about it.  But I'd wager that someone
>who is a beginner may have a little more trouble with it.

>HTH

>Ted
>R.E. Byers
>rtby...@bconnex.net

Thank you Remy and Ted, I encapsulated the event in a class and it
works fine.

I have experience in C and MS-DOS, and know object orientated
programming thru Java; the combination of a) C++, b) Windows
programming and c) BCB and the VCL is sometimes just to much. I'm
programming in BCB for half a year now, and while I usally get things
done, the lack of experience in the concepts of Windows programming
makes it a black box often: things are getting done, but don't ask me
why...

Greetings Johan.

Other Threads