PDA

View Full Version : Create a DLL for AMS



davels
10-23-2007, 04:33 AM
Hello,

I need to create and link a DLL with AMS.

What's the better language to do it?
Is there any specify structure to use?

I already to create a DLL with Delphi and C# but I can't read the string send by AMS.

Does someone can help me?

Thx in advance

Brett
10-23-2007, 07:11 AM
I have written articles on how to build a DLL using C in Visual Studio:

How to Create a Simple Win32 DLL Using Visual C++ 2005 (http://www.kapilik.com/2007/09/17/how-to-create-a-simple-win32-dll-using-visual-c-2005/)

Waldo
10-23-2007, 08:24 AM
I have written articles on how to build a DLL using C in Visual Studio:

How to Create a Simple Win32 DLL Using Visual C++ 2005 (http://www.kapilik.com/2007/09/17/how-to-create-a-simple-win32-dll-using-visual-c-2005/)

Brett,
When I click on the link to continue reading on this article [i.e. go to another page], a new window opens but it is blank...even if I press "refresh" the page remains blank. Is there an issue with your blogging software? THANKS.

reteset
10-25-2007, 12:14 PM
I already to create a DLL with Delphi and C# but I can't read the string send by AMS.


---------------------------
Hi
in Delphi you must use pointer variables, allways use PChar

for example :


Library Project1

uses Windows;

function Myfunction(AmsString,AmsNumber:PChar):PChar;stdcal l;
var
ReturnVal:PChar;
DelphiString:String;
DelphiNumber:Integer;
begin
DelphiString:=String(AmsString); // convert ams string to delphi string
DelphiNumber:=StrToInt(AmsNumber); //convert ams number to delphi integer
ReturnVal:= PChar(DelphiString)+PChar(IntToStr(DelphiNumber)); //convert each to string type pointer and asign to ReturnVal
Result:=PChar(ReturnVal); // pass DelphiNumber and DelphiString to Ams
end;

exports Myfunction;
end.

To Call From Ams:


AmsString ="Hello";
AmsNumber = 12;
Vars = "\""..AmsString.."\",\""..AmsNumber.."\"";
result = DLL.CallFunction("DllPath", "Myfunction",Vars,DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);

davels
11-19-2007, 09:30 AM
---------------------------
Hi
in Delphi you must use pointer variables, allways use PChar

for example :


Library Project1

uses Windows;

function Myfunction(AmsString,AmsNumber:PChar):PChar;stdcal l;
var
ReturnVal:PChar;
DelphiString:String;
DelphiNumber:Integer;
begin
DelphiString:=String(AmsString); // convert ams string to delphi string
DelphiNumber:=StrToInt(AmsNumber); //convert ams number to delphi integer
ReturnVal:= PChar(DelphiString)+PChar(IntToStr(DelphiNumber)); //convert each to string type pointer and asign to ReturnVal
Result:=PChar(ReturnVal); // pass DelphiNumber and DelphiString to Ams
end;

exports Myfunction;
end.

To Call From Ams:


AmsString ="Hello";
AmsNumber = 12;
Vars = "\""..AmsString.."\",\""..AmsNumber.."\"";
result = DLL.CallFunction("DllPath", "Myfunction",Vars,DLL_RETURN_TYPE_STRING, DLL_CALL_STDCALL);

Unbelievable :wow ! Thousand of thanks, it works fine!!!
Now I'm able to send/receive information from and to AMS/SF and Delphi!