从Visual Studio 2010 C#Windows应用程序调用SAP GUI [英] Calling SAP GUI from Visual Studio 2010 C# Windows Application

查看:359
本文介绍了从Visual Studio 2010 C#Windows应用程序调用SAP GUI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我试图从VS2010 C#Windows Forms应用程序调用SAP Gui。下面是我的C#源代码,描述了我尝试这样做的方式:



...

使用 SAPFEWSELib ;

...



静态课程

{



///< summary>

///应用程序的主要入口点。

///



[STAThread]



static void Main()

{

//

//创建GuiApplication对象

//



尝试

<

SAPActive.SapGuiApp =

新的GuiApplication(); //< ---但是在这一点上,我收到错误信息!


}

catch(Exception ex)//这里我捕获错误并显示消息。

{



}

}

}



Visual Studio错误消息:检索具有CLSID {B90F32AD-859E-4EDD-BFAE-C9216849520C}的组件的COM类工厂由于以下错误而失败:80040154未注册类(HRESULT异常:0x80040154(REGDB_E_CLASSNOTREG))。



我的编程环境设置如下:



> Windows 7,64位操作系统

> Visual Studio 2010

> .NET 4.0

> SAP Gui客户端7.2



由于我在许多博客中广泛搜索并发表了大量意见,所以这些都没有解决问题。



这是我已经尝试过的一系列支票,但仍未成功解决问题。



1.我有检查了Windows注册表。所有SAP密钥似乎都已到位。特别是钥匙(Class)B90F32AD-859E-4EDD-BFAE-C9216849520C已经注册。



2.我已经检查了VS 2010中的项目设置。它们都适用于x86位机器。 (正如许多博客中提到的那样,他们必须如此!)



3. 只有一个 .ocx我目前在我的(VS项目)参考文献中使用的文件是 sapfewse.ocx 。我已从目录 C:\program files(x86)\sap\frontend\sapgui \sapfewse.ocx 中找到并添加此文件作为我的项目中的参考。



有没有人知道问题可能是什么原因或者给我一些线索搜索的线索?这是我正在使用的Active X Control版本的问题(即x86 / x64)?我是否在项目的使用部分中缺少文件作为参考,还是访问权限问题?



非常感谢提前。

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.
///

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

推荐答案

你必须这样声明:< br $>


public static GuiApplication Application = new GuiApplication();

public static GuiConnection Connection;

public static GuiSession Session ;



我的对象被声明为公共因为'是全局对象,你还需要使用会话对象和连接对象,这是脚本的方式在C#中与VBS非常不同,你必须以明确的方式访问每个GUI资源,下面是一些如何做到这一点的例子:



((GuiTextField)Session.ActiveWindow.FindByName(RSYST-BNAME,GuiTextField))。Text = txtUserName.Text; //在登录屏幕中设置UserName



Session.SendCommand(); //发送回车



((GuiButton)Session.ActiveWindow.FindByName(btn [0],GuiButton))。按();



Happy Coding!
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!


这篇关于从Visual Studio 2010 C#Windows应用程序调用SAP GUI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆