Can an exe export functions same as a dll?

Windows specific questions.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Can an exe export functions same as a dll?

Post by D.J.Peters »

the situation:

app1 load dll1
app1 call's dll1->doanything
dll1 start app2
dll1 call's app2->ScreenRes w,h

app1 call's dll1->getValueFromUser
dll1 return(app2->getValueFromWindow))
...
...

app1 call's dll1->Deactivate
dll1 call's app2->CloseWindowAndExit
app1 freedll(dll1)

is it posible?

thanx for infos

Joshy
fsw
Posts: 260
Joined: May 27, 2005 6:02

Post by fsw »

Yes. Victor implemented it many, many moons ago.

Look in your freebasic directory under freebasic\examples\export .
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

hello fsw that is not the same
it will only import a function from other module (compile time)
not from other .exe (runtime) you know.

Joshy
fsw
Posts: 260
Joined: May 27, 2005 6:02

Post by fsw »

Some years ago (when I first started out with fb) I created a exe file calling the glade dll, and the glade dll called a function inside the exe.
I thought this is what you are after, a way that a dll can call a function in a exe file.

If not, sorry for the confusion...
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

ok you wrote in your exe ?

function please_call_me(arg as integer) export
? "arg=" & arg
end function

now how can i call it from my dll?

type please_call_me as function (arg as integer)
extern call_me as please_call_me
call_me(10)

thanx for your infos

Joshy
zerospeed
Posts: 227
Joined: Nov 04, 2005 15:29

Re: Can an exe export functions same as a dll?

Post by zerospeed »

D.J.Peters wrote:the situation:

app1 load dll1
app1 call's dll1->doanything
dll1 start app2
dll1 call's app2->ScreenRes w,h
Ok, wait a minute... how is supposed dll1 will start app2?

AFAIk, exporting functions in executables and loading them with DyLibLoad + DyLibSymbol works.

Maybe you need to establish some API/Plugin interface to support the RPC you're looking for.
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

This loads an exe dynamically and calls a function in it. I think the exe could determine how it was loaded if it had a functional DLL entry point function, but using DyLibLoad I have never found a way to do that, even for a DLL.
app1.bas:

Code: Select all

dim target as function( byval arg as integer ) as integer
dim hndl as any ptr
hndl = dylibload( "app2.exe" )
print hex( hndl )
target = dylibsymbol( hndl, "target" )
print hex( target )
print target( 1 )
print target( 123 )
dylibfree hndl
sleep
app2.bas:

Code: Select all

function target alias "target" (byval arg as integer) as integer export
  return arg + 1
end function
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

the key is dylibload("the.exe")
i was thinking it's only for *.dll's

by the way i write an plugin for TrueSpace 3.2 (the free version)
and the plugin is simple a renamed plugin.dll plugin.tsx
but if you create a dll you can't link to fbgfx but i need
screenres so i must call a exe from the plugin dll.

or exist a way to use screenres inside a DLL?

thanx Joshy
marcov
Posts: 3462
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Post by marcov »

D.J.Peters wrote:the key is dylibload("the.exe")
i was thinking it's only for *.dll's
In general afaik yes. If only because .exe's all relocate to the same address.

Exported symbols in end-binaries are usually only used for debugging
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

For LoadLibrary and LoadLibraryEx Microsoft clearly states that the executable module can be a DLL or an EXE. If a FB EXE exports a function, then a base relocation table is included in the EXE and Windows will relocate ("rebase") it as necessary. For the code above, both modules have the same image base, 400000h. The module handle returned by DyLibLoad, which is usually the base address of the module, and the procedure address returned by DyLibSymbol, which is always an address in the module, show that the loaded module has been rebased.
etko
Posts: 113
Joined: May 27, 2005 7:55
Location: Slovakia
Contact:

Post by etko »

Maybe you have problem with name mangling or what. FB is not in reality very windows friendly regarding function exports. Download DependencyWalker open your EXE, with that you can check what functions got exported and how. DLL, SYS, OCX, ACM, SCR or EXE have the same PE file format on windows. If you use CreateProcess you can give it name even BLAH and it will got loaded and linked correctly.

At least Half-Life-s 1.1.1.0 EXE exports VGUI methods as MSVC++ mangled names and it seems to work. Check it using Dependency walker and get the idea.
Post Reply