cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Error Calling External Function - PB 12.5.2

Former Member
0 Likes
826

Hello,

I have a .NET dll with a public function which I need to call from PB.

I have declared it in my Global External Function like below:

Function string GetRatingArea (string zipCode) Library "C:\PBDEV\Apiclient\ApiClient.dll" ALIAS for "GetRatingArea"

PB Code:

String ls_ratingarea

ls_ratingarea = GetRatingArea("21030")

Messagebox("Rating Area", ls_ratingarea)

This is giving me an error saying cannot call the external function. What am I missing here?

PB12.5.2. Classic application

.NET 4 framework DLL

COM Visible.

Thanks.

View Entire Topic
Former Member
0 Likes

I think, that you can't use .net dlls like "classic" dlls.

You may use it as a com object, e.g. you have to connect with ConnectToNewObject.

Former Member
0 Likes

Rene - Thanks for the response.

I did try this as well

Integer result

OleObject myole

myole = create oleobject

result  = myole.connecttoobject("C:\PBDEV\Apiclient\ApiClient.dll", "ApiClient.Operation")

But it gives back -2 which is Class not found.

Any ideas?

Former Member
0 Likes

You have to use the function ConnectToNewObject and to specify the class name. Your COM object must be registered.

There are some examples in the web. Here is one: http://blogs.artinsoft.net/Mrojas/archive/2009/03/03/Calling-NET-from-PowerBuilder.aspx

Former Member
0 Likes

>>result  = myole.connecttoobject("C:\PBDEV\Apiclient\ApiClient.dll", "ApiClient.Operation")


Because that's not the way to call it.  You have to determine if the assembly even support a COM Callable Wrapper.  Then you need to see if it's been registered with RESASM and, if not, register it.  Then you have to call it using the ClassID that REGASM created.



Former Member
0 Likes

Thanks guys. I understand that registering the DLL will make it work. But I am looking at a lot of upcoming enhancements in this DLL logic and functionality. So, I do not want to register the DLL every time we have a new version.

Also, all my PB applications are in PB Classic flavor, so I cannot use it as a reference. I did migrate one of the smaller apps to PB .NET target and was able to easily consume a .NET dll as a reference.

So how should I go about with an architectural change to the classic applications which can be a good standard practice to do.

I was also thinking of a new PB .NET application which will implement the DLL functionalities, and maybe use it as a wrapper to all other classic apps. But this will involve a lot of back-and-forth of data between the apps.

Is there any major issues of converting a PB classic app to a .NET target? Is there any known issues or any features not supported?

Any help in this matter is highly appreciated.

Former Member
0 Likes

We have a .NET dll that we've called PBUtils that does many things for us such as emailing, working with MS Office, and lots of other things .NET can do. We used Bruce's example of creating a COM Wrappable DLL, and every time there a new version we just ask all the developers to re-register it with a batch file. For the final release however we use a manifest file to make it availble to the PowerBuilder application with it being registered, I couldn't get this to work when running from the PB IDE.

It seems to work very well for us, I've even split it up into multiple namespaces so I can call ConnectToNewObject just for the bit I need, for example Common, or Excel. We've also decided to create new versions in the one DLL when an interface changes, e.g. a new argument is added to an existing function call. That way the calling program can specify in ConnectToNewObject that it wants to connect to <company>.PBUtils.Excel_1_20, i.e. a specific version.

Let me know if you need any help if you want to do something similar.

The other thing you can do is create web services in .NET which can be called from PB Classic. I've been looking at this recently and it works pretty well once you work out that you need to use the lowest common denominator of WCF, SOAP 1.1. You can get your datawindows to retrieve and update using web services, and you can call web service methods independently of the datawindow, all in PB Classic.

Former Member
0 Likes
 For the final release however we use a manifest file to make it availble to the PowerBuilder application with it being registered, I couldn't get this to work when running from the PB IDE.

What you have to do to get it to work for the PowerBuilder IDE is create a manifest file for the PowerBuilder IDE exe.  You also have to make the assembly available in the same directory as the PowerBuilder IDE exe.