cancel
Showing results for 
Search instead for 
Did you mean: 

GUI Scripting in C#

Former Member
0 Kudos

I need to integrate GUI scripting into some existing c# code. I am making use of the SAPFEWSELib.dll as an Interop component within Visual Studio 2008.

I am having some success:

private void Form1_Load(object sender, EventArgs e)

{

GuiApplication Application;

GuiConnection Connection;

GuiSession Session;

Application = (GuiApplication)System.Activator.CreateInstance(Type.GetTypeFromProgID("SapGui.ScriptingCtrl.1"));

Connection = Application.OpenConnection("Bazinga", false, true);

Session = (GuiSession)Connection.Sessions.Item(0);

Session.TestToolMode = 1;

((GuiTextField)Session.ActiveWindow.FindByName("RSYST-MANDT", "GuiTextField")).Text = "050";

((GuiTextField)Session.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField")).Text = "dshelman";

((GuiTextField)Session.ActiveWindow.FindByName("RSYST-BCODE", "GuiPasswordField")).Text = "N0tAPwd";

((GuiTextField)Session.ActiveWindow.FindByName("RSYST-LANGU", "GuiTextField")).Text = "EN";

Session.SendCommand("");

Console.WriteLine("Logged in");

}

The problem occurs when I issue the SendCommand(""). I see the little barber pole/script indicator on the login screen and it appears to have logged in. Then the application quits. It never gets to the subsequent WriteLine statement of "Logged In".

I suspect I need to make use of events here, but am not familiar with how to code the GUI Scripting API events in C#.

Can someone provide me with some sample code to assist me in transitioning from the login to the actual use of a session with a transaction. I feel that once there, my VBA scripting knowlege will help me.

Thanks,

Don Shelman

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Don,

I can't C# but you can look in this forum at

Regards,

ScriptMan

Former Member
0 Kudos

Yes, I've seen that code as well. It helped me move forward quite a bit to get to the point about which I posted. Does anyone have some more extensive .Net examples that I could see?

Thanks,

Don

Former Member
0 Kudos

Dear Don,

I'm trying to get "Interop.SAPFEWSELib.dll" running in C# as well.

But I can not figure out how to import the DLL properly.


  [DllImport("Interop.SAPFEWSELib.dll")]

seems not to work. Even if i try to use a Kexword out of the SAPFEWSELib for example a constructor to create an instance of an object which might be included in the DLL i get an compiler Error.


    [DllImport("Interop.SAPFEWSELib.dll")]
    public static extern IntPtr GuiApplication();

    public GuiApplication Engine;

The error displayed:

GuiApplication is a 'method' but is used like a type.

How can I import a constructor from the DLL?!

Have you already solved your issue with this DLL?

Help would be highly appreciated Thanks a lot.

Andi

Edited by: aegidos on Jul 13, 2011 8:01 AM

Answers (0)