简体   繁体   English

从PowerBuilder调用C#(.NET)方法

[英]Calling a C# (.NET) Method from PowerBuilder

I am looking for direction in regards to calling a C# module (written in the .NET (2.1) framework) from PowerBuilder. 我正在寻找有关从PowerBuilder调用C#模块(在.NET(2.1)框架中编写)的方向。 Here is the C#.NET information: The function is used to connect to COM PORT device and get the device status. 这是C#.NET信息:该函数用于连接到COM PORT设备并获取设备状态。

NameSpace:  NETS
Class:    NETS
Method:    REQUESTCARDSTATUS()
DLL:    NETS.dll

Using my dll as OLE Object in Powerbuilder. 在Powerbuilder中使用我的dll作为OLE对象。 I am using PowerBuilder version 11.5. 我正在使用PowerBuilder 11.5版。 I have a simple window with a command button on it. 我有一个简单的窗口,上面带有命令按钮。 Within this window, my code looks like this: 在此窗口中,我的代码如下所示:

OLEObject ole_3 ole_3 = CREATE OLEObject OLEObject ole_3 ole_3 = CREATE OLEObject

// connect to C# class //连接到C#类
MessageBox("Value = ", +String(li_rc)) IF li_rc <> 0 THEN DESTROY ole_3 END IF MessageBox("Value = ", +String(li_rc)) IF li_rc <> 0 THEN DESTROY ole_3 END IF

 li_sum = ole_3.RequestCardStatus(); 

Getting error while calling this function Error R0035: Error Calling External Function. 调用此函数时出现错误错误R0035:调用外部函数时出错。

The function is working fine when try to call the function using c# application. 尝试使用c#应用程序调用该函数时,该函数运行正常。 I don't know what is causing the issue in powerbuilder. 我不知道是什么导致了powerbuilder中的问题。 Trying from past three day, but no luck. 从过去三天开始尝试,但没有运气。

Your code shows that you have not called the ConnectToNewObject function for starting the Ole server application. 您的代码显示您尚未调用ConnectToNewObject函数来启动Ole服务器应用程序。 After creating ole_3 and before calling the RequestCardStatus function, you should call this function as follows: 创建ole_3之后,在调用RequestCardStatus函数之前,应按以下方式调用此函数:

ole_3.ConnectToNewObject ( classname ) ole_3.ConnectToNewObject(classname)

where classname is a Progid or a Classid of the server 其中classname是服务器的Progid或Classid

The C# dll must be made COM visible. 必须使C#dll对COM可见。

The syntax to connect (using your example) would be: ole_3.ConnectToNewObject('NETS.NETS') 连接的语法(使用您的示例)将是:ole_3.ConnectToNewObject('NETS.NETS')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM