🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #7208

Calling one app's function from another app

#7208
From: Greg Bullock
Date: Thu, 03 Mar 2005 01:29
53 lines
2717 bytes
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 
Technical Details
Message-ID: <4226686a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,ce3b76f66924fcaa,start
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Greg Bullock" <greg dot bullock at atk dot com>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Calling one app's function from another app
Date: Wed, 2 Mar 2005 17:29:14 -0800
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
NNTP-Posting-Host: 138.64.190.39
Message-ID: <4226686a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1109813354 138.64.190.39 (2 Mar 2005 17:29:14 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail