【发布时间】:2016-05-18 19:56:18
【问题描述】:
我找不到与此相关的问题,或者我太笨了,无法理解可以应用其他解决方案。就这样吧。
我正在尝试创建一个 DLL,它应该只包含一个函数,其他程序员可以在他们的项目中引用该函数以使用该函数。该函数只是获取一个已经在运行的对象并将其返回给调用者。这是一个获取正在运行的 SAP 对象并返回它的函数。
下面的DLL代码
using System;
using SAPFEWSELib;
using SapROTWr;
namespace SAPCon
{
public class SAPObj
{
public static GuiSession CreateNewSession()
{
SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr.CSapROTWrapper();
object SapGuilRot = sapROTWrapper.GetROTEntry("SAPGUI");
object engine = SapGuilRot.GetType().InvokeMember("GetSCriptingEngine", System.Reflection.BindingFlags.InvokeMethod, null, SapGuilRot, null);
GuiApplication sapGuiApp = engine as GuiApplication;
GuiConnection connection = sapGuiApp.Connections.ElementAt(0) as GuiConnection;
GuiSession session = connection.Children.ElementAt(0) as GuiSession;
int c = (connection.Children as GuiComponentCollection).Count;
session.CreateSession();
int err = new int();
int ses = new int();
do
{
try
{
session = connection.Children.ElementAt(c) as GuiSession;
ses = session.Info.SessionNumber;
err = 0;
}
catch (Exception e)
{
err = e.HResult;
}
} while (err == 614);
return session;
}
}
}
这是试图测试 dll 的程序的代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SAPFEWSELib;
using SapROTWr;
using SAPCon;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
GuiSession g;
g = SAPCon.SAPObj.CreateNewSession();
int s;
s = g.Info.SessionNumber;
Console.WriteLine(s);
Console.ReadKey();
}
}
}
如果我将整个 DLL 代码放在常规控制台应用程序中,它可以完美运行,但是当我引用 dll 并尝试使用该函数时,我在第一行出现异常 SapROTWr.CSapROTWrapper sapROTWrapper = new SapROTWr. CSapROTWrapper(); 表示该类没有注册。
我认为这是我的 DLL 有问题,而不是 SAP Dll,因为它们在从应用程序运行时工作正常。我在我的 dll 上做了一个 regasm 32bit 并且一切正常,我尝试了一个 regsvr 但它找不到入口点。
我在这里缺少什么?
【问题讨论】:
-
您的 EXE 项目的项目 > 属性 > 构建选项卡 > 目标平台设置很重要。