Re: Using Dll created with Delphi in Excel



hasu wrote:

Hi all,

Delphi's Dll:

library ProjektiList;

type
...
function GetProjectText(Nro:Integer):String;

function GetProjectText(Nro:Integer):String;
begin
...
Showmessage(IntToStr(Nro));
result:='Hello?!'
end;



Excel macro:

Private Declare Function GetProjectText Lib "ProjektiList.dll" _
(ByVal nProNro As Integer) As String
Private Const nProNro = 7223

Public Function GetProjectName() As String

ActiveCell.Value = GetProjectText(nProNro )

End Function


It does not work! Showmessage shows something totally different than 7223.
And after excel crashes...

Program versions; Delphi = 2006, Excel = 2007

Does anyone has simple enough example even for me to understand?

-Hasu


You must declare the Exported function in the DLL as STDCALL.

also, Delphi native string is not compatible with other lauguages.

I'm sure that language uses Double wide characters..
try passing back a PWideChar instead..
Var
SomeGlobelString:Widestring;
Function MydllCall(SomeINteger:Integer):PWideChar;Stdcall;
Begin
SomeGlobelString := 'What the Crap';
result := PWidechar(SomeBlobelString);
End;



http://webpages.charter.net/jamie_5";

.