BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

LoadPackage. Who calls Register function? (no #pragma startu

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development)
View previous topic :: View next topic  
Author Message
raulmola
Guest





PostPosted: Tue Jan 23, 2007 9:10 pm    Post subject: LoadPackage. Who calls Register function? (no #pragma startu Reply with quote



When I create a component inside a package, i make a namespace and the
typical Register function. All it's ok if you build with runtime
packages. Controls are installed in the palette perfectly and i can
design them. Hence,Register function is called perfectly in each
namespace of my units

Now what if i want to use that package by means if LoadPackage. Who
calls Register function of my controls ?. Do i have to call it myself
(GetProcAddress) in order to register my classes?. I say this because
next code doesn't work though the package is correctly loaded

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

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


If i'm right, who calls Register when loadpackage is not used but
insted the application is compiled with runtime packages

I know that you can use those pragma in the subject in order to
initialize packages and call register methods. But i want to understand
how packages work.

Thanks in advance.
Back to top
Dmitry
Guest





PostPosted: Wed Jan 24, 2007 12:01 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote



Raulmola,

Quote:
Now what if i want to use that package by means if LoadPackage. Who
calls Register function of my controls ?.

You should care about registering your components in packages.

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
RegisterClass(__classid(TMyComponent));
return 1;
}

All the best!

Dmitry Konnov
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Jan 24, 2007 2:18 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote



"raulmola" <raulmola (AT) gmail (DOT) com> wrote in message
news:1169565024.839002.222880 (AT) l53g2000cwa (DOT) googlegroups.com...

Quote:
Now what if i want to use that package by means if LoadPackage.
Who calls Register function of my controls ?

Noone. The IDE loops through a package's units looking for exported
Register() functions, and then calls them if present. Multiple units
in a package can have their own Register() calls. But when you load a
package youself, there are no autmated calls to Register().

Quote:
Do i have to call it myself (GetProcAddress) in order to register my
classes?


Yes. Look at GetPackageInfo() to determine which units are
availalble. You will have to build up a list of exported Register()
names (they are mangled when exported) in order to pass them to
GetProcAddress() correctly.

Quote:
If i'm right, who calls Register when loadpackage is not used but
insted the application is compiled with runtime packages

Noone.


Gambit
Back to top
raulmola
Guest





PostPosted: Thu Jan 25, 2007 9:30 pm    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

Thank you very much for your answers.

Sorry lemy... i don't understand what you say about...

"You will have to build up a list of exported Register()
names (they are mangled when exported) "

I thought that preceding function names with PACKAGE was enough to call
GetProcAddress and call that function later.

This arises another question. How would you call GetProcAddress to call
a function defined inside a namespace?. Something like this

namespace mynamespace
{
void PACKAGE register(void)
{
//fn src.
}
}

One more question.
While i was waiting for your answers I looked an article form delphi
tips about building a framework plugin. I think it appears in several
group's discussions .

http://www.obsof.com/delphi_tips/DL613.html

samples use pragmas but anyway, As far as i understand it, it seems a
strict way to build a plugin framework. An interfaced way. Could you
advice me how would you make a more relaxed way to make a plugin
framework?. Or simply can you tell me another site related to this in
order to contrast different ways to do this?

Thank you very much.







On 23 ene, 21:18, "Remy Lebeau \(TeamB\)" <no.s...@no.spam.com> wrote:
Quote:
"raulmola" <raulm...@gmail.com> wrote in messagenews:1169565024.839002.222880 (AT) l53g2000cwa (DOT) googlegroups.com...

Now what if i want to use that package by means if LoadPackage.
Who calls Register function of my controls ?Noone. The IDE loops through a package's units looking for exported
Register() functions, and then calls them if present. Multiple units
in a package can have their own Register() calls. But when you load a
package youself, there are no autmated calls to Register().

Do i have to call it myself (GetProcAddress) in order to register myclasses?

Yes. Look at GetPackageInfo() to determine which units are
availalble. You will have to build up a list of exported Register()
names (they are mangled when exported) in order to pass them to
GetProcAddress() correctly.

If i'm right, who calls Register when loadpackage is not used but
insted the application is compiled with runtime packagesNoone.

Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Jan 26, 2007 12:42 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

"raulmola" <raulmola (AT) gmail (DOT) com> wrote in message
news:1169739038.080541.15790 (AT) l53g2000cwa (DOT) googlegroups.com...

Quote:
I thought that preceding function names with PACKAGE was
enough to call GetProcAddress and call that function later.

It is. But you still have to know what the function is actually
exported as in order for GetProcAddress() to find it. The exported
name is prefixed with the unit/namespace that the function belongs to,
and suffix characters to indicate the parameter and return types. For
example, here is the exported name of a Register() function from one
of my own components:

@Regextideregister@Register$qqrv.

That is the name that has to be passed to GetProcAddress().

Quote:
How would you call GetProcAddress to call a function defined
inside a namespace?

See above.

Quote:
While i was waiting for your answers I looked an article form
delphi tips about building a framework plugin. I think it appears
in several group's discussions .

http://www.obsof.com/delphi_tips/DL613.html

Personlly, I like this approach myself:

http://www.techvanguards.com/com/tutorials/plugin.asp

The benefit of this approach is that people can write plugins in any
COM-enabled language they want (BCB, VC++, VB, etc). The articl you
point out is strictly Borland VCL only.


Gambit
Back to top
Dmitry
Guest





PostPosted: Fri Jan 26, 2007 6:11 pm    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

Remy,

Quote:
Yes. Look at GetPackageInfo() to determine which units are
availalble. You will have to build up a list of exported Register()
names (they are mangled when exported) in order to pass them to
GetProcAddress() correctly.

please show a piece of code , how you call Register() procedure
inside of other bpl.
I have some problems with declaration of __declspec(dllimport)

thank you
Dmitry.
Back to top
Michael Harris
Guest





PostPosted: Sat Jan 27, 2007 1:10 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

excuse me for butting in.. But doesn't loadpackage call 'Initialize' and
initialize call 'infoproc' for each..

so making your own LoadPackage function is the same as
::LoadLibrary
::GetProcAddess( handle, 'Initialize')

Unload doing the reverse with 'Finalize'

see source / sysutil.pas / were'how loadpackage works' is detailed
LoadPackage
SafeLoadLibrary
InitializePackage
CheckForDuplicateUnits
UnloadPackage

--
Michael
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Jan 27, 2007 2:26 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

"Michael Harris" <techonos-NO-SPAM-@attbi.com> wrote in message
news:45ba5204$1 (AT) newsgroups (DOT) borland.com...

Quote:
doesn't loadpackage call 'Initialize'

Yes, it does.

Quote:
so making your own LoadPackage function is the same
as
::LoadLibrary
::GetProcAddess( handle, 'Initialize')

Unload doing the reverse with 'Finalize'

Which is exactly what (Un)LoadPackage() already does (amongst other
things) so there would be no point in duplicating what already exists.

In any case, that still does not address the issue of calling the
package's Register() functions at runtime.


Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sat Jan 27, 2007 2:37 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

"Dmitry" <dmitry (AT) pikalevo (DOT) com> wrote in message
news:45b9efb3$1 (AT) newsgroups (DOT) borland.com...

Quote:
please show a piece of code , how you call Register() procedure

Untested:

typedef void __fastcall (*TRegisterProc)(void);

void __fastcall PackageInfoProc(const AnsiString Name, TNameType
NameType, Byte Flags, void *Param)
{
if( NameType == ntContainsUnit )
{
AnsiString RegisterProcName = "@" + AnsiUpperCase(Name[1])
+ AnsiLowerCase(Name.SubString(2, MaxInt)) + "@Register$qqrv";

TRegisterProc RegisterProc = (TRegisterProc)
GetProcddress(Param, RegisterProcName.c_str());
if( RegisterProc )
RegisterProc();
}
}

{
int Flags = 0;
HINSTANCE hInst = LoadPackage("filename.bpl");
GetPackageInfo(hInst, hInst, Flags, PackageInfoProc);
}

Quote:
I have some problems with declaration of __declspec(dllimport)

Such as?


Gambit
Back to top
Dmitry
Guest





PostPosted: Sat Jan 27, 2007 6:11 pm    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

Remy
Quote:
I have some problems with declaration of __declspec(dllimport)

Such as?

in my executable i do:
typedef void __declspec(dllimport) TRun();
TRun *g_Run;
THandle g_Handle;
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
g_Handle = LoadPackage("dima.bpl");
g_Run = (TRun *)GetProcAddress((HINSTANCE)g_Handle, "_Run");
g_Run();
Application->Run();
UnloadPackage(g_Handle);
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}

in my bpl i do:

extern "C" void __declspec(dllexport) Run();
//--------------------------------------------------------------------------
-
void Run()
{
//Starting application...
}
//--------------------------------------------------------------------------
-


How can i make declaration of the: void Run() function
as
void __fastcall Run()
?

Cos i want to be able to call
void __fastcall PACKAGE Register() function in other packages.

Dima
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Sun Jan 28, 2007 7:11 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

"Dmitry" <dmitry (AT) pikalevo (DOT) com> wrote in message
news:45bb4106$1 (AT) newsgroups (DOT) borland.com...

Quote:
in my executable i do:
typedef void __declspec(dllimport) TRun();

Don't put import/export statements in a typedef like that. Besides,
you are importing the function dynamically anyway, so the import
statement has no effect at all since it is a compile-time feature, not
a runtime feature.

Use this instead:

typedef void (*TRun)();

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
HINSTANCE g_Handle = LoadPackage("dima.bpl");
try
{
TRun g_Run = (TRun) GetProcAddress(g_Handle, "_Run");
if( g_Run )
g_Run();
Application->Run();
}
__finally
{
UnloadPackage(g_Handle);
}
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;
}


Gambit
Back to top
Dmitry
Guest





PostPosted: Mon Jan 29, 2007 10:53 pm    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

Remy

Quote:
typedef void __declspec(dllimport) TRun();

Don't put import/export statements in a typedef like that. Besides,
you are importing the function dynamically anyway, so the import
statement has no effect at all since it is a compile-time feature, not
a runtime feature.

OK.

Then how would look like declatation of this function in module where it
impllemented?


Quote:
HINSTANCE g_Handle = LoadPackage("dima.bpl");

btw. does not work since LoadPackage returns THandle or unsigned int.

Dima
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Jan 30, 2007 12:49 am    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

"Dmitry" <dmitry (AT) pikalevo (DOT) com> wrote in message
news:45be261a (AT) newsgroups (DOT) borland.com...

Quote:
Then how would look like declatation of this function in
module where it impllemented?

Exactly as you already showed earlier.


Gambit
Back to top
raulmola
Guest





PostPosted: Tue Jan 30, 2007 9:35 pm    Post subject: Re: LoadPackage. Who calls Register function? (no #pragma st Reply with quote

I made a package of components and i separated it in two packages :
Design package, and Runtime package. The design package contains all
register functions. I thought i was doing the best, but as Remy's code
shows maybe the best solution could be a unique Design and runtime
package, because one could reuse the code of register functions in
order to load the library dinamically and let both, me and the IDE,
register the components with the same source code(the register
functions). Maybe i'm tripping.

On 27 ene, 13:11, "Dmitry" <dmi...@pikalevo.com> wrote:
Quote:
Remy

I have some problems with declaration of __declspec(dllimport)

Such as?in my executable i do:
typedef void __declspec(dllimport) TRun();
TRun *g_Run;
THandle g_Handle;
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
g_Handle = LoadPackage("dima.bpl");
g_Run = (TRun *)GetProcAddress((HINSTANCE)g_Handle, "_Run");
g_Run();
Application->Run();
UnloadPackage(g_Handle);
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
return 0;

}in my bpl i do:

extern "C" void __declspec(dllexport) Run();
//-------------------------------------------------------------------------­-
-
void Run()
{
//Starting application...}//-------------------------------------------------------------------------­-
-

How can i make declaration of the: void Run() function
as
void __fastcall Run()
?

Cos i want to be able to call
void __fastcall PACKAGE Register() function in other packages.

Dima
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Development) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.