Externally Linking

P

Paul Kirby

Hello All

I am writing an application and a dll file and I was wondering how I would
access functions within the exe file from the dll?

Example:
/* EXE File */

long GetUserCount(void)
{
long count;
....
....
return count;
}

And I want to access the GetUserCount() function from in the dll.
Will I have to copy the exeapp.h to the folder with the dll project in and
link to it that way?
Or is their an easier way to do it?

I know that Half-Life connect to external functions with the mods that are
written for it but I just cant understand how to do it :(

Thanks in advance
Paul Kirby
 
A

Andre Kostur

Hello All

I am writing an application and a dll file and I was wondering how I
would access functions within the exe file from the dll?

You're in the wrong group. Standard C++ has no concept of a DLL. You
should wander over to the Microsoft groups and ask over there (look on the
news.microsoft.com news server).
 
P

Peter van Merkerk

Paul said:
Hello All

I am writing an application and a dll file and I was wondering how I would
access functions within the exe file from the dll?

Example:
/* EXE File */

long GetUserCount(void)
{
long count;
...
...
return count;
}

And I want to access the GetUserCount() function from in the dll.
Will I have to copy the exeapp.h to the folder with the dll project in and
link to it that way?
Or is their an easier way to do it?

I know that Half-Life connect to external functions with the mods that are
written for it but I just cant understand how to do it :(

Standard C++ (the only thing that is topical here) has no functions for
dealing with DLL's. To do what you want you will need platform specific
functions which are off-topic here.

See also:
http://www.slack.net/~shiva/welcome.txt
http://home.wanadoo.nl/efx/c++-faq/

<offtopic>
Since you are probably using MS-Windows, you might want to look on MSDN
for the following topics: "LoadLibrary", "GetProcAddress" and "import
libraries"
</offtopic>
 
J

John Harrison

Paul Kirby said:
Hello All

I am writing an application and a dll file and I was wondering how I would
access functions within the exe file from the dll?

The need to do this indicates poor program design.
Example:
/* EXE File */

long GetUserCount(void)
{
long count;
...
...
return count;
}

And I want to access the GetUserCount() function from in the dll.
Will I have to copy the exeapp.h to the folder with the dll project in and
link to it that way?

That does not work (as you'd find out if you tried it).
Or is their an easier way to do it?

An easier way, was the last way difficult?

First you have to clarify exactly what you want. Do you want to access the
self same code that is in the exe file, or would you be happy with an
identical copy of that code in you dll?

If its the later then it simply a matter of finding the code that contains
GetUserCount and adding that file and all its dependent files (this may not
be trivial) to your dll 'project'.

If it is the former (i.e. you want the dll to call the code that physically
exists in the exe file) then that is a difficult thing to do and you should
ask on a Windows programming groups where they will be able to tell you how
to do it on the Windows operating system, try
for instance. It may not be
possible at all (I'm not a Windows expert).

john
 
J

JKop

Paul Kirby posted:
Hello All

I am writing an application and a dll file and I was wondering how I
would access functions within the exe file from the dll?

Example:
/* EXE File */

long GetUserCount(void)
{
long count;
...
...
return count;
}

And I want to access the GetUserCount() function from in the dll.
Will I have to copy the exeapp.h to the folder with the dll project in
and link to it that way?
Or is their an easier way to do it?

I know that Half-Life connect to external functions with the mods that
are written for it but I just cant understand how to do it :(

Thanks in advance
Paul Kirby


First create the DLL. You'll also have to make a library file, .lib, out of
it. Then you'll have to make the header file. In the header file you'll have
to put:

extern "C" long GetUserCount(void);

Include the header file in the source file of you EXE prog. Set the linker
for the EXE to include .lib file for the DLL.

But ofcourse this is all OFF-TOPIC here.

Or, instead of using a .lib file, you could go the "LoadLibrary"
"GetProcAddress" route.

-JKop
 
J

JKop

JKop posted:
extern "C" long GetUserCount(void);

Correction,

long GetUserCount(void);


I'm just so used to seeing it in Windows header files, even though its
unneccesary!

-JKop
 
H

Howard

EXE's in general do not provide any way to link to them externally. They're
not source code, and they're not libraries, they're stand-alone, binary
executables. Also, there is very seldom a single header file that describes
a program of any significance. You need the source code itself, so you can
compile with it, or else some documentation that tells you that you *can* do
this and how to do it on your system. The only common way that I've seen
for a DLL to call back to an EXE is for the DLL to have a function that the
EXE calls, and a parameter of that function is a pointer to a "callback"
function in the EXE. If the EXE is not written to call your DLL's function
that expects a callback function pointer, then you have no way to make use
of that feature. (Are you writing the EXE, or does it already exist as a
stand-alone app?)

-Howard
 
P

Paul Kirby

Hello All

Thanks for all the replies :)

Sorry for being off topic for this group.
Paul Kirby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top