Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2001, 09:12 AM
Zeno Zeno is offline
Junior Member
 
Join Date: Jan 2001
Posts: 29
Default Exporting funcs from EXE (not exactly same as DLL !!!)

I am trying to export function from EXE file. It schould be done in the same way as the export from DLL, BUT when I tried to export a function working with strings, I have got some weird access violation errors. (the EXE module is dynamicaly linked, and when it has got 'library' instead of 'program' as the first word in source code - and DLL extension of course - it works without problems). Strange thing is that, I can not even allocate memory (GetMem function) for local variables in such function.

SO if anyone has got the experience or knowledge to solve this problem, I would be very very happy )))

Thanx

Zdeno
Reply With Quote
  #2  
Old 08-27-2001, 03:08 PM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: Exporting funcs from EXE (not exactly same as DLL !!!)

You can simply compile it as a library you just have to change the extension from .DLL to .EXE...I think this can be done in Project/Options/Application/Target file extension or something like that...

gLes

Always Coca-Cola!

gLes@hab.hu
Reply With Quote
  #3  
Old 08-28-2001, 12:05 AM
Zeno Zeno is offline
Junior Member
 
Join Date: Jan 2001
Posts: 29
Default RE: Exporting funcs from EXE (not exactly same as DLL !!!)

that is not working - i don't want a dll with exe extension, but a working program that will export function. When I use your advice, it says ERROR when I run the 'EXE'

Zdeno
Reply With Quote
  #4  
Old 08-28-2001, 09:08 AM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: Exporting funcs from EXE (not exactly same as DLL !!!)

Would you mind trying these projects then yourself?

program DLLExe;

uses
Windows;

{$E exe}

{$R *.RES}

procedure GetMem2(var P: PChar; Size: Integer);
begin
GetMem(P, Size);
end;

function ExportProc: PChar; stdcall;
var
ResultString: PChar;
begin
GetMem2(ResultString, 13);
Result := ResultString;
MessageBox(0, 'ExportProc successfuly called from external app!', 'DLL Exe', MB_ICONINFORMATION);
end;

exports
ExportProc;

begin
MessageBox(0, 'DLL Exe loaded successfuly!', 'DLL Exe', MB_ICONINFORMATION);
end.


I'm not very good at using GetMem...but this didn't give me any error messages...but I'm not sure if this is what you want...here's the caller app:

program CallerApp;

uses Windows;

type TFunc = function: PChar;

var
hLib: hModule;
ExportProc: TFunc;
begin
hLib := LoadLibrary('DLLEXE.EXE');
if hLib = 0 then
begin
MessageBox(0, 'Can''t load DLLEXE.EXE', 'CallerApp', MB_ICONSTOP);
Exit;
end;
@ExportProc := GetProcAddress(hLib, 'ExportProc');
if @ExportProc = nil then
begin
MessageBox(0, 'Can''t import ExportProc from DLLEXE.EXE', 'CallerApp', MB_ICONSTOP);
FreeLibrary(hLib);
Exit;
end;
MessageBox(0, ExportProc, 'CallerApp', 0);
FreeLibrary(hLib);
end.


hope that helps...

gLes

"Small step for me, but large step for all Delphi developers!"
/gLes@hab.hu/
Reply With Quote
  #5  
Old 08-29-2001, 05:27 AM
Zeno Zeno is offline
Junior Member
 
Join Date: Jan 2001
Posts: 29
Default RE: Exporting funcs from EXE (not exactly same as DLL !!!)

Please send me your compiled EXEs and tell me which version of delphi are you using. I have pasted the code from webpage to my projects, and I have got still errors (little bit different, but still errors). Or mayby supply the code with theese .dof and .cfg files, because maybe it is something with compiler settings.

Thanx



Zdeno

z.hrib@aquasoft.cz
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 10:07 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.