Using Delphi 2010, I am trying to write a dll for mIRC. Here is some information from the mIRC help file
Technical notes
This section contains technical information for programmers who want to create DLLs for use with mIRC.
The routine in the DLL being called must be of the form:
int __stdcall procname(HWND mWnd, HWND aWnd, char *data, char *parms, BOOL show, BOOL nopause)
mWnd is the handle to the main mIRC window.
aWnd is the handle of the window in which the command is being issued, this might not be the currently active window if the command is being called by a remote script.
data is the information that you wish to send to the DLL. On return, the DLL can fill this variable with the command it wants mIRC to perform if any.
The DLL can return an integer to indicate what it wants mIRC to do:
0 means that mIRC should /halt processing
1 means that mIRC should continue processing
2 means that it has filled the data variable with a command which it wants mIRC to perform, and has filled parms with the parameters to use, if any, when performing the command.
3 means that the DLL has filled the data variable with the result that $dll() as an identifier should return.
The following code, which is supposed to reverse input text, compiles OK, but the results of using the dll are not what I expected.
function Reverse(mWnd, aWnd: hWnd; Data, Parms: PChar; Show, NoPause: Boolean): Integer; stdcall;
var
Temp: String;
I: Integer;
begin
SetLength(Temp, Length(Data));
for I := 0 to Length(Data) do
begin
Temp[I] := Data[Length(Data)- I]; // Reversing string by retrieving characters from Data one at a time
end;
StrCopy(Data, PChar(Temp)); // Putting reversed string back into data
Result := 3;
end;
exports
Reverse;
begin
end.
For example calling the dll from mIRC as //say $dll(mydll,Reverse,hello)
gives an output of just 'o'. If the parameter is 'hello sailor' the output is 'orilsao llhe'. I have tried unsuccessfully to trace the operation of the code, but I cannot make sense of how the Data value changes. I suspect it my own limited knowledge of PChar behaviour is a contributing factor. I welcome any advice that may help. Cheers