First, I said you needed to allocate and free the memory in the EXE not in the DLL.
Second, I would suggest you do not use Result as the name of your parameter as it has a specific meaning in Delphi
as the return value of a function.
This is untested but should be nearer to what you want:
Code:- [b]EXE[/b]
- procedure TForm1.Button1Click(Sender: TObject);
- var
- RetVal : PChar;
- arrayIndexReq: Integer;
- begin
- retVal := AllocMem(46);
- arrayIndexReq := 2; // Or whatever
- try
- getURL(46,arrayIndexReq, retVal);
- ShowMessage(String(retVal));
- finally
- FreeMem(retVal);
- end;
- end;
- [b]DLL[/b]
- procedure getURL(const bufSize, index: Integer; msg: PChar);
- begin
- StrPLCopy(msg,myArray[index],bufSize);
- end;
Copy Code Of course, in the real world you will need a lot of additional code
to make sure you do not get AV's or buffer overflows or "index out of bounds".
Also a way of knowing how large the string was.
One way is to make the procedure a function again 
But the function returns the length of the string.
Just like many Windows API's you could add code in the DLL function so that if you pass in Nil for msg the it simply returns
the size of the string at array[index] after which you can
set everything up for the second call with msg allocated.
WARNING: Always make sure you allocate enough memory for the terminating null!
Clive |