 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Greg Bullock Guest
|
Posted: Thu Mar 03, 2005 1:29 am Post subject: Calling one app's function from another app |
|
|
I've got two applications. The second one is supposed to call a function in
the first one. I must not be doing this correctly, as the line calling the
function gives an access violation. I don't even know how to debug this
sort of thing. Here's what I've got.
AppOne exports a function declared as follows:
TMyStruct __stdcall __declspec(dllimport) GetMyStruct(
const char *StrA,
const char *StrB,
const SYSTEMTIME& DateTime);
AppTwo attempts to call this function using code something like the
following:
typedef TMyStruct __stdcall (*pGetMyStruct)(const char *StrA, const char
*StrB, const SYSTEMTIME& DateTime);
void FuncA()
{
SYSTEMTIME SystemTime;
::GetSystemTime(&SystemTime);
HMODULE AppOneModule = LoadLibrary("AppOne.Exe");
pGetMyStruct GetMyStructFunc =
reinterpret_cast<pGetMyStruct>(GetProcAddress(AppOneModule,
"@GetMyStruct$qqspxct1rx11_SYSTEMTIME"));
if (!GetMyStructFunc)
return;
// --- The next line produces an Access Violation ---
TMyStruct MyStruct = (GetMyStructFunc)(
"this is string 1",
"this is string 2", SystemTime);
...
}
The line marked above produces the following Access Violation:
Project AppTwo.exe raised exception class EAccessViolation with message
'Access violation at address 01171177 in module AppOne.Exe'. Read of address
0085E880. Process stopped. Use Step or Run to continue.
In the definition of GetMyStruct(...), the first executable line is
::MessageBox(0, "Arrived in GetMyStruct", "Made it!", MB_OK);
but no such message is displayed before the access violation occurs.
Any help most appreciated.
Regards.
Greg
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Mar 03, 2005 2:08 am Post subject: Re: Calling one app's function from another app |
|
|
"Greg Bullock" <greg dot bullock at atk dot com> wrote
| Quote: | AppOne exports a function declared as follows:
TMyStruct __stdcall __declspec(dllimport) GetMyStruct(
const char *StrA,
const char *StrB,
const SYSTEMTIME& DateTime);
|
That is not an export. That is an import.
| Quote: | AppTwo attempts to call this function using code something
like the following:
|
I do not suggest you do it that way. Why do you need applications to call
each other's functions in the first place? That is not a very good design.
Shared code should be placed into a DLL instead. Otherwise, you should use
Automation or RPC to allow applications to call each others functions in a
safe manner.
Gambit
|
|
| Back to top |
|
 |
Greg Bullock Guest
|
Posted: Thu Mar 03, 2005 9:15 pm Post subject: Re: Calling one app's function from another app |
|
|
Thanks very much, Gambit.
I'll use Automation or RPC, as you recommend.
The exported function uses some objects with C++Builder language extensions
(e.g., "__published") which are off-limits to the other application. These
objects are also used elsewhere in the exporting application, so I felt the
best way to let both applications link to the same function is to export the
critical function from that application.
Thanks for pointing me to Automation and RPC.
Regards.
Greg
"Remy Lebeau (TeamB)" <no.spam (AT) no (DOT) spam.com> wrote
| Quote: |
"Greg Bullock" <greg dot bullock at atk dot com> wrote in message
news:4226686a$1 (AT) newsgroups (DOT) borland.com...
AppOne exports a function declared as follows:
TMyStruct __stdcall __declspec(dllimport) GetMyStruct(
const char *StrA,
const char *StrB,
const SYSTEMTIME& DateTime);
That is not an export. That is an import.
AppTwo attempts to call this function using code something
like the following:
I do not suggest you do it that way. Why do you need applications to call
each other's functions in the first place? That is not a very good
design.
Shared code should be placed into a DLL instead. Otherwise, you should
use
Automation or RPC to allow applications to call each others functions in a
safe manner.
Gambit
|
|
|
| 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
|
|