?
Solved

Accessing automation server from asp

Posted on 2003-03-13
2
Medium Priority
?
482 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:ssunko
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:ssunko
ID: 8147394
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
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8147558
PAQ'd and points refunded.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question