 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
salamander1965 Guest
|
Posted: Wed Aug 24, 2005 12:01 pm Post subject: resolving externals between app and package |
|
|
I'm trying to move code from a class in the main application into a
package, but am running into 'unresolved external' linker errors.
I've done OK in the past with declaring package functions properly so
they can be called from the main app, but I can't figure out how to
modify the declarations in this case. Any suggestions would be
appreciated.
Here's an abbreviated form of the code:
///MAINUNIT.H///
class Module {
private:
int FCurrChar;
int __fastcall GetCurrentChar(void);
public:
__property int CurrChar = {read=GetCurrentChar};
};
///MAINUNIT.CPP///
#include "MAINUNIT.H"
#include "PACKAGE.H"
int __fastcall Module::GetCurrentChar(void) {
return FCurrChar;
}
///PACKAGE.H///
extern "C" __stdcall PACKAGE void PkgFunc(Module* ModPtr);
///PACKAGE.CPP///
#include "MAINUNIT.H"
void __stdcall PkgFunc(Module* ModPtr) {
int MainCurrChar=ModPtr->CurrChar;
}
I'm trying to compile the package at this point. The compilation goes
OK, but the linker complains about 'unresolved external
Module::GetCurrentChar referenced from ...'
I've #included MAINUNIT.H in the package .cpp, so it knows the
structure of the Module class, and it can dereference ModPtr passed as
a parameter. But it doesn't know what to do about the GetCurrentChar
function back in the main app accessed through the CurrChar property,
and I have not been able to figure out where to put 'extern', or if
other modifiers might be needed. Also, does the main app have
anything equivalent to an import library that the linker can use to
resolve the external references?
BTW: Although it's not shown in the shortened example, PkgFunc() is
itself called from the main app, so I have the main app using external
functions in the package, and the package using external classes in
the main app.
Thanks -- salamander
|
|
| Back to top |
|
 |
salamander1965 Guest
|
Posted: Thu Aug 25, 2005 12:58 am Post subject: Re: resolving externals between app and package |
|
|
After thinking on it for awhile, is it even possible to access
variables/functions in an executable from a package using the usual
'extern' way of doing things; or is this where callback functions
passed as pointers to the package functions are useful?
If it is possible, I'm not sure how the linker could ever resolve the
external references since (as far as I know) compiling a .exe does not
produce any kind of import library-type file the linker could use.
Am I looking at this the right way?
-- salamander
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Aug 25, 2005 6:21 am Post subject: Re: resolving externals between app and package |
|
|
"salamander1965" <salamander1 (AT) verizon (DOT) net> wrote
| Quote: | I'm trying to compile the package at this point. The compilation
goes OK, but the linker complains about 'unresolved external
Module::GetCurrentChar referenced from ...'
|
As well it should be.
| Quote: | I've #included MAINUNIT.H in the package .cpp, so it knows the
structure of the Module class, and it can dereference ModPtr passed
as a parameter. But it doesn't know what to do about the GetCurrentChar
function back in the main app accessed through the CurrChar property,
|
You cannot declare a function in a package and then put the implementation
of the function in the application. The implementation has to be in the
package as well.
| Quote: | and I have not been able to figure out where to put 'extern'
|
It has nothing to do with 'extern'. Your code is in the wrong place to
begin with.
| Quote: | Also, does the main app have anything equivalent to an import library
that the linker can use to resolve the external references?
|
No.
Gambit
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Aug 25, 2005 6:22 am Post subject: Re: resolving externals between app and package |
|
|
"salamander1965" <salamander1 (AT) verizon (DOT) net> wrote
| Quote: | After thinking on it for awhile, is it even possible to access
variables/functions in an executable from a package using
the usual 'extern' way of doing things
|
No.
| Quote: | or is this where callback functions passed as pointers to
the package functions are useful?
|
Yes.
| Quote: | Am I looking at this the right way?
|
No.
Gambit
|
|
| Back to top |
|
 |
salamander1965 Guest
|
Posted: Thu Aug 25, 2005 10:54 am Post subject: Re: resolving externals between app and package |
|
|
| Quote: | You cannot declare a function in a package and then put the implementation
of the function in the application. The implementation has to be in the
package as well.
|
That's pretty much the conclusion I had come to, but it's good to have
someone who actually knows confirm it.
The code I was moving could be shared among multiple instances of the
app (the rationale for moving it to a package), but the code itself is
so tied in with accessing the app's data that the number of callback
functions needed would defeat the intent of moving the code in the
first place.
Thanks -- salamander
|
|
| Back to top |
|
 |
|
|
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
|
|