🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.nativeapi
5 messages
5 total messages Started by Pere Mateu Wed, 04 Oct 2006 21:55
Dynamic package loading
#3100
Author: Pere Mateu
Date: Wed, 04 Oct 2006 21:55
9 lines
1186 bytes
Hi,

I want to create a class in a C++ Builder 2006 package, and be able to 
dynamically load and use it from another application. How can I do it? I 
register the class in the package (in the DllEntryPoint), but when I call 
GetClass() in the external application I get a null pointer.

Thanks very much for your help,
Pere
Re: Dynamic package loading
#3101
Author: Remy Lebeau (TeamB)
Date: Wed, 04 Oct 2006 22:18
18 lines
1607 bytes
"Pere Mateu" <pmateu@siam.es> wrote in message
news:45242db4@newsgroups.borland.com...

> I want to create a class in a C++ Builder 2006 package, and be
> able to dynamically load and use it from another application. How
> can I do it? I register the class in the package (in the DllEntryPoint),
> but when I call GetClass() in the external application I get a null
pointer.

The class is being registered into the package's class list, not the
application's class list.  A Package is a DLL, and thus has its own data and
memory that is separate from the application.  To make them share the same
class list, the application would have to enable the use of runtime packages
in the Project Options. My guess is that you do not have that enabled.


Gambit
Re: Dynamic package loading
#3102
Author: Remy Lebeau (TeamB)
Date: Wed, 04 Oct 2006 22:58
14 lines
1338 bytes
"Pere Mateu" <pmateu@siam.es> wrote in message
news:45242db4@newsgroups.borland.com...

> I register the class in the package (in the DllEntryPoint)

Incidently, you should not be calling RegisterClass() from DllEntryPoint()
directly.  Each of your that wants to register classes should be exporting
its own Register() function instead.  The VCL automatically calls the
Register() functions when loading the package.  Call RegisterClass() from
inside of Register().


Gambit
Re: Dynamic package loading
#3115
Author: Pere Mateu
Date: Wed, 11 Oct 2006 10:24
55 lines
2323 bytes
Hi Remy,
Thanks for your kind answer, but I still can't get it to work.

This is what I'm exactly doing in the package (named MyPackage.bpl):

namespace Mypackage

{
  void __fastcall PACKAGE Register()
  {
 RegisterClass(__classid(TForm1));
  }
}

In the main app (Build with runtime packages checked), I do this:

 try {
  int bpl=LoadPackage("Mypackage.bpl");
  if (!bpl) { ShowMessage("error"); return; }
  TMetaClass* p=GetClass("TForm1");
  if (!p) { ShowMessage("No class"); return; }
  UnloadPackage(bpl);

 } catch (...) {
     ShowMessage("error");
 }

I always get a "No class" error, because the GetClass() can't find the 
TForm1 class.
Am I doing anything wrong?

Thanks very much again,
Pere




"Remy Lebeau (TeamB)" <no.spam@no.spam.com> escribi� en el mensaje 
news:45243d18@newsgroups.borland.com...
>
> "Pere Mateu" <pmateu@siam.es> wrote in message
> news:45242db4@newsgroups.borland.com...
>
>> I register the class in the package (in the DllEntryPoint)
>
> Incidently, you should not be calling RegisterClass() from DllEntryPoint()
> directly.  Each of your that wants to register classes should be exporting
> its own Register() function instead.  The VCL automatically calls the
> Register() functions when loading the package.  Call RegisterClass() from
> inside of Register().
>
>
> Gambit
>
> 
Re: Dynamic package loading
#3116
Author: Pere Mateu
Date: Wed, 11 Oct 2006 22:09
40 lines
1927 bytes
Problem solved!!!

It worked ok after registering the class like this:

-----------------------------
void Init()
{
 Classes::RegisterClass(__classid(TForm1));
}

void Finalize()
{
 Classes::UnRegisterClass(__classid(TForm1));
}

#pragma startup Init
#pragma exit Finalize
-----------------------------

Thanks very much,
Pere

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> escribi� en el mensaje 
news:45243d18@newsgroups.borland.com...
>
> "Pere Mateu" <pmateu@siam.es> wrote in message
> news:45242db4@newsgroups.borland.com...
>
>> I register the class in the package (in the DllEntryPoint)
>
> Incidently, you should not be calling RegisterClass() from DllEntryPoint()
> directly.  Each of your that wants to register classes should be exporting
> its own Register() function instead.  The VCL automatically calls the
> Register() functions when loading the package.  Call RegisterClass() from
> inside of Register().
>
>
> Gambit
>
> 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads