Hi, I have this piece of code in the onJoin event of an Indy IRC Client:
It basically allows me to do basic scripting via a DLL. It all works fine except that after this code has ran once, the client appears to ignore any new incoming messages and disconnecting results in a socket error. After a lot of testing and swearing I managed to narrow it down to the FreeLibrary call, if I comment that out then it works perfectly and nothing dies. Is there anything blatently wrong with that code? I can't see it for the life of me.
Code:
procedure TfrmMain.ircJoin(Sender: TObject; AUser: TIdIRCUser; AChannel: TIdIRCChannel);
type
TonJoin = function(AUser: TIdIRCUser; AChannel: TIdIRCChannel):String;
var
Temp:PChar;
LibraryID:THandle;
proc:pointer;
command:String;
begin
displayEvent(AUser.Nick, 'has joined the chat');
listUsers;
Temp := PChar(ExePath + dll);
LibraryID := LoadLibrary(Temp);
If LibraryID <> null then
begin
proc := GetProcAddress(LibraryID, 'onJoin');
if proc <> nil then
begin
command := TonJoin(proc)(AUser, AChannel);
displayChat(irc.Nick, command);
irc.Say(currChannel, command);
end;
freeLibrary(LibraryID);
end;
end;
It basically allows me to do basic scripting via a DLL. It all works fine except that after this code has ran once, the client appears to ignore any new incoming messages and disconnecting results in a socket error. After a lot of testing and swearing I managed to narrow it down to the FreeLibrary call, if I comment that out then it works perfectly and nothing dies. Is there anything blatently wrong with that code? I can't see it for the life of me.