Accessing automation server from asp

I am trying to create a system that allows an asp page to make a call to a remote automation server which interfaces with a Walldata Rumba 3270 session using IBM's Ehllapi32 api (Rumba is running locally on the same machine as the server).  It scrapes a piece of data from the screen and returns a string that should be displayed in the browser. I am relatively new to com programming, but I have gotten everything to work locally on one computer (ie. eliminating the dcom part) from a test client application written in Delphi.  I can't get it to work from the asp page.  Here is what I've got...

**** asp page  ****
<HTML><BODY>
<% Set DelphiASPObj = Server.CreateObject("aspAccess.objAspAccess")
   Response.Write(DelphiAspObj.MyValue)%>
</BODY></HTML>

**** asp object ****
unit objAspAccess;
interface
uses
  ComObj, ActiveX, AspTlb, aspAccess_TLB, StdVcl, TestComExe_TLB;

type
  TobjAspAccess = class(TASPObject, IobjAspAccess)
  protected
    procedure OnEndPage; safecall;
    procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
    function Get_MyValue: WideString; safecall;
  end;

implementation
uses ComServ;

procedure TobjAspAccess.OnEndPage;
begin
  inherited OnEndPage;
end;

procedure TobjAspAccess.OnStartPage(const AScriptingContext: IUnknown);
begin
  inherited OnStartPage(AScriptingContext);
end;

function TobjAspAccess.Get_MyValue: WideString;
var
  TestServer: IAutoComExe;
  DisplayValue: WideString;
begin
  TestServer := CoAutoComExe.Create;
  TestServer.GetValue(9, DisplayValue);
  Result := DisplayValue;
end;

initialization
  TAutoObjectFactory.Create(ComServer, TobjAspAccess, Class_objAspAccess,
    ciMultiInstance, tmFree);
end.

**** automation object ****
unit AutoComExe;
interface
uses  ComObj, ActiveX, TestComExe_TLB, StdVcl, Windows;

type
  TAutoComExe = class(TAutoObject, IAutoComExe)
  protected
    procedure GetValue(Code: Integer; out ResultData: WideString); safecall;
  end;

implementation
uses ComServ, FComExeMain;

procedure TAutoComExe.GetValue(Code: Integer; out ResultData: WideString);
begin
  ResultData := Form1.RetrieveValue(Code);
end;

initialization
  TAutoObjectFactory.Create(ComServer, TAutoComExe, Class_AutoComExe,
    ciMultiInstance, tmFree);
end.

**** Main Server (.exe) ****
unit FComExeMain;
interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, walldata;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
  public
    Function RetrieveValue(AValue: Integer): WideString;
  end;

var  Form1: TForm1;
implementation
function TForm1.RetrieveValue(AValue: Integer): WideString;
var
  RetValue: Integer;
  strBuffer: String;
begin
  WD_ConnectPS(GetCurrentProcessId, 'X');
  Memo1.Lines.Add('ConnectionResult = ' + IntToStr(RetValue));
  WD_SendKey(GetCurrentProcessId,'123');
  WD_Wait(GetCurrentProcessId);
  strBuffer := '';
  SetLength(strBuffer,8);
  WD_CopyPSToString(GetCurrentProcessId,1785,strBuffer,8);
  WD_DisconnectPS(GetCurrentProcessId);
  Memo1.Lines.Add('Retrieved value: ' + strBuffer);
  Result := strBuffer;
end;
end.

**** Walldata unit ****
unit Walldata;
interface
  function WD_ConnectPS(hInstance: LongInt; ShortName: String): Integer; stdcall; external ehlapi32 name 'WD_ConnectPS';
  function WD_SendKey(hInstance: LongInt; KeyData: String): Integer; stdcall; external ehlapi32 name 'WD_SendKey';
  function WD_Wait(hInstance: LongInt): Integer; stdcall; external ehlapi32 name 'WD_Wait';
  function WD_CopyPSToString(hinstance: LongInt; Position: Integer; Buffer: String; Length: Integer): Integer; stdcall; external ehlapi32 name 'WD_CopyPSToString';
  function WD_DisconnectPS(hInstance: LongInt): Integer; stdcall; external ehlapi32 name 'WD_DisconnectPS';
implementation
end.

I can't figure out why everything works great if I use a client app with the exact same code in the asp object.  Could it have something to do with marshalling? or maybe stdcall vs safecall in the walldata unit?

Sorry this is so long but I have been working at this for 6 days now and wanted to make sure I'm not leaving anything out.

Scott
ssunkoAsked:
Who is Participating?
 
SpideyModConnect With a Mentor Commented:
PAQ'd and points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
ssunkoAuthor Commented:
I answered my own question.  Since ehlapi32 interacts with the desktop to connect to a session, the automation object must be set to "Launch as Interactive User".  This way the automation server can see the desktop and thus the ehlapi32 session.  This setting can be done in OLE View on the Activation page of the object.  I'm not sure if anyone tried to help me figure this out (there are no comments) but thanks if you did!
Scott
0
All Courses

From novice to tech pro — start learning today.