: Hi there,
:
: I was trying to think about how this is done, but cannot really get my head round it - wondering if anyone could share a minute.
:
: I have a LAN Chat program for use with housemates on a LAN, and they then have it installed on their machine (a simple copy of the exe suffices). Now, when I make updates to this exe, is there a way I can make other copies of my program automatically update?
:
: I can set registry settings and check that "my copy of chat program version number = master copy of chat program's version number", but then how would i go about editing the code within the exe?
:
: My other train of thought was about perhaps the main exe is a simple script loader, where it simply reads from pre-compiled scripts (DLLs?) and all it does is copy latest versions of these. Therefore no need of copying the main exe is required.
:
: Can anyone confirm this for me please? How would I go about transfering a module (or PAS) into a DLL file if that is the method I am to take?
:
: Thanks in advance
: - James
:
There are two simple ways of performing this kind of things:
- a DLL module
- an external update program
The latter is quite simple to implement. Just write a small program, which downloads the new version and writes it over the old version. Since this is a completely independant processs, you don't have to worry about updating it. The trick lies in the call. If your chat-program detects a new version, it calls the updater (see ShellExecute() and older posts for examples) and terminates itself. This way the chat-program can be overwritten. After the update is completed, the update program restarts the chat program.
The former means that you need to recompile your program into a DLL. Luckily this isn't as hard as it sounds. All programs have a .dpr file, which looks something like ths:
program DD3Valid;
uses
Forms,
mainwin in 'mainwin.pas' {Form1};
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
All you need to do is to change that into this:
library DD3Valid;
uses
Forms,
Windows,
mainwin in 'mainwin.pas' {Form1};
{$R *.RES}
procedure RunChatProgram(AppHandle: THandle); StdCall;
begin
Application.Handle := AppHandle;
Form1 := TForm1.Create(Application);
Form1.ShowModal;
end;
exports
RunChatProgram;
begin
end.
This will automatically compile it as a library. Now you need to write a program, which calls the RunProgram() procedure. Here is a sample code:
type
TRunChatProgram = procedure(AppHandle: THandle); StdCall;
var
DLLHandle: THandle;
ProcPointer: pointer;
begin
...
DLLHandle := LoadLibrary('ChatDLL.DLL'); // Load the DLL
if DLLHandle > HINSTANCE_ERROR then
begin
ProcPointer := GetProcAddress(DLLHandle, 'RunChatProgram');
// Obtain the correct procedure pointer
if ProcPointer <> nil then
TRunChatProgram(ProcPointer)(Application.Handle)
// Run the procedure = run the program
else
ShowMessage('Cannot run code (possibly wrong library)');
FreeHandle(DLLHandle); // Unload the DLL
end else
ShowMessage('Cannot load DLL');
...
end.
This process will run the chat-window as a dialog. This code is error-trapping, so if the chat doesn't load the user will see a message box.
I hope this helps you to decide which way you wish to go.