Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.20/5 (2 votes)
See more:
Hi everyone,

I am trying to call SAP Gui from a VS2010 C# Windows Forms Application. Below follows my C# source code describing the way i am trying to do it :

...
using SAPFEWSELib;
...

static class Program
{

///
/// The main entry point for the application.
///


[STAThread]

static void Main()
{
//
// Create the GuiApplication object
//

try
{
SAPActive.SapGuiApp =
new GuiApplication(); // <--- But at this point, i get the error message!

}
catch (Exception ex) // Here i trap the error and display the message.
{

}
}
}

Visual Studio Error Message : Retrieving the COM class factory for component with CLSID {B90F32AD-859E-4EDD-BFAE-C9216849520C} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

The setup of my programming environment is as follows :

> Windows 7, 64 bit Operating System
> Visual Studio 2010
> .NET 4.0
> SAP Gui Client 7.2

As i have searched extensively in many blogs and red a banch of opinions, none of these solved the problem.

Here is a list of checks which i have already tried, but still with no success to solve the problem.

1. I have checked the Windows Registry. All SAP keys seem to be in place. Especially the key (Class) B90F32AD-859E-4EDD-BFAE-C9216849520C is registered.

2. I have checked the Project Settings in VS 2010 for this project. They are all properly set for an x86 bit machine. (as mentioned in many blogs that they so must be!)

3. The only one .ocx file which I am currently using in my (VS Project) References is sapfewse.ocx. I have found and added this file as a Reference in my project from the directory C:\program files(x86)\sap\frontend\sapgui\sapfewse.ocx.

Does anyone have an idea what might be the cause of the problem or give me a clue what to search? Is this a problem with the version of the Active X Control which i am using (i.e x86/x64)? Am i missing a file as a reference in the using section of the project or is it a matter of access rights?

Many thanks in advance.
Posted

1 solution

You'll have to declare it like this:

public static GuiApplication Application = new GuiApplication();
public static GuiConnection Connection;
public static GuiSession Session;

My objects are declared as public because the're Global Objects, also you'll need to use a Session Object and a Connection Object, the way scripting in C# is very very very different from VBS, you'll have to access every GUI resource in a explicit way, here are a few examples on how to do this:

((GuiTextField)Session.ActiveWindow.FindByName("RSYST-BNAME", "GuiTextField")).Text = txtUserName.Text; // Set The UserName in the Logon Screen

Session.SendCommand(""); // Send Enter

((GuiButton)Session.ActiveWindow.FindByName("btn[0]", "GuiButton")).Press();

Happy Coding!
 
Share this answer
 
Comments
Hari prakash R 28-Mar-17 1:17am    
you are using FindByName...if i use FindById i got this error while run time...

The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).

Please help to solve the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900