1. Praveen Rajarao
  2. PowerBuilder
  3. Monday, 13 August 2018 19:06 PM UTC

We have couple of existing PB applications in version PB12.5.2 which are of .NET win forms target.

 

We noticed that this target is no longer available in PowerBuilder 2017 R3.

 

What is the workaround to migrate these applications to the new version. We need this application as a .NET target since we are referencing a COM Visible .NET DLL to call the methods inside the DLL.

 

We also tried to use the appeon_workaround.pbl but it is not returning back the result from the DLL method. The code looks like below. We also deployed the application and tried to run from the EXE. It didn’t work either. The return argument – iResult is NULL. There is no error however when we call the function.

 

Appreciate if you could address this and let us know how we can migrate this application to the new version.

 

long lRet

string iResult

string strError

string ls_cipher_string = ‘TEST’

appeondotnetcomponent comcaller

any paramlist[]

 

 

comcaller = create appeondotnetcomponent

comcaller.componenttype = '1'

comcaller.typelib = 'HelloWorld.dll'

comcaller.classdescript = 'Program'

 

// invoke component method

 

paramlist[1] = ls_cipher_string

lRet = comcaller.of_execinterface( "SayHello", paramlist)

 

if lRet = 0 then

iResult = string(comcaller.ReturnValue)

messagebox('Hi', iResult)

else

strError = comcaller.ErrorText

end if

 

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 14 August 2018 03:27 AM UTC
  2. PowerBuilder
  3. # 1

Hi Praveen;

  Another approach would be to convert the code that consumes the .NET resources into a PB Web Service. The WS in PB 2017 is based on the Winform .Net model and can consume .Net assemblies "as is" - just like your current Winform App.

Food for thought.

regards ... Chris

Comment
  1. Armeen Mazda @Appeon
  2. Tuesday, 14 August 2018 04:12 AM UTC
This approach should work but keep in mind this is a deprecated feature.
  1. Helpful
  1. Praveen Rajarao
  2. Tuesday, 14 August 2018 17:43 PM UTC
Why cant I just declare the .NET DLL as a Local External Function and call it within my app?

I tried doing this by making the DLL COM Visible / COM Invisible. Both failed. I am able to recompile the app, but when i run it, it gives me an error saying 'Error accessing external function'.

Why is it so damn hard just because I am trying to upgrade to a newer version of PB? If something is removed, then shouldnt there be an easy way to migrate existing apps?

  1. Helpful
  1. Bruce Armstrong
  2. Wednesday, 15 August 2018 15:15 PM UTC
Local External Functions are for calling C++ that use __STDCALL exports. You can't call C# code that way.
  1. Helpful
There are no comments made yet.
Armeen Mazda @Appeon Accepted Answer Pending Moderation
  1. Monday, 13 August 2018 20:11 PM UTC
  2. PowerBuilder
  3. # 2

I would recommend reverting back to a native PB app and then to interop with .NET DLLs (assuming it is non-visual) our recommended approach is through REST Web APIs, which was one of the core focus of the R3 release. You will however need to use Visual Studio or some other tool to create a REST Web API interface for your DLL or wait for PB 2018, which provides C# server development capabilities. The Workaround PBL is for the PowerServer deployment option - so it is not applicable to your client/server app (please ignore that).

Bruce Armstrong has done number of articles how to interop with .NET DLLs (both visual and non-visual) in a native PB app on the client side (without having to involve a web server/web API architecture), so those can be alternatives to consider: https://community.appeon.com/index.php/articles-blogs/tips-tricks-techniques-articles/17-powerbuilder/167-calling-net-components-from-powerbuilder-via-com-wrappers-redux and https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/165-using-visual-net-components-in-powerbuilder 

Comment
  1. Bruce Armstrong
  2. Wednesday, 15 August 2018 15:29 PM UTC
Take a look at this article: https://www.brucearmstrong.org/2006/08/calling-dot-net-components-from.html. That's a copy of the article I was referring to in the first article that Armeen gave you. It shows the source code for both VS and PB.



Unfortunately, the article was migrated from my wordpress blog to blogger, and I didn't realize that it was still referencing the images in wordpress until I took the wordpress site down, so all the images were lost.



There should be similar content on the old PBDJ site, but I can't find it readily.



  1. Helpful
  1. Praveen Rajarao
  2. Thursday, 16 August 2018 18:43 PM UTC
Thank you Bruce. I will go through this. Also waiting to attend the upcoming conference in Nov and see what PB2018 has to offer with the C# integration.
  1. Helpful
  1. Praveen Rajarao
  2. Friday, 17 August 2018 12:26 PM UTC
Bruce - I created a simple DLL and am trying to call a method. See below code:



C# DLL Code:

namespace HelloWorld

{

[ComVisible(true)]

public class Program

{

[ComVisible(true)]

public static string SayHello(string name)

{

return $"Hello - {name}";

}

}

}



I have given it a strong name. Then I added it to GAC using GACUTIL. After that I have created a .reg file using REGASM and also ran the REG file to add to registry.



PB Code:

integer li_rc

string ls_result

oleobject loo_test

loo_test = CREATE oleobject

li_rc = loo_test.ConnectToNewObject ( "HelloWorld.Program" )

ls_result = loo_test.SayHello('Praveen')



Destroy loo_test



==================================

When I ran this I am getting an error saying - "Name not found calling external object function sayhello"

The OLE object is getting created fine, but the method call is the problem.



What is it that I am missing here?



Thanks

Praveen

  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.