cancel
Showing results for 
Search instead for 
Did you mean: 

Calling SAP GUI from Visual Studio 2010 C#

0 Kudos

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
{

  /// <summary>

  /// The main entry point for the application.

  /// </summary>

  [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 checkings 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.

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.

Accepted Solutions (0)

Answers (2)

Answers (2)

Sriram2009
Active Contributor
0 Kudos

Hi Andreas

If you can call normal command prompt from VS2010 then you can call the SAPGUI by using the command line or batch or CMD  file

"start sapshcut  -system=(SID) -client=(Client No) -desc=("SYSTEM Desc") -user=(USER ID) -pw=(Password) -maxgui -command=(T code) "

Thanks & Regards

Sriram

Former Member
0 Kudos

I hope that even though my reply is late, you'll benefit from it's content.

If you change your build target from 64bit to 32bit, it should function properly.

Microsoft decided to create a separate location to maintain 32 bit registry keys on 64 bit systems. Likely, your COM object lives in this section of your registry. Programs built using a 64 bit target will not have access to the 32 bit part of your registry and therefore cannot see the relevant entry. Changing your build target to 32 bit should make that section of the registry available to your application. (http://support.microsoft.com/kb/305097)

The answer to the question "How do I get my 64 bit application to interact with my 32 bit COM components?" is not an easy question to answer but here's some guidance:

http://blog.mattmags.com/2007/06/30/accessing-32-bit-dlls-from-64-bit-code/

Former Member
0 Kudos

Hello,

Your response really help me.

Thanks!