1. Pallavi Karnati
  2. PowerBuilder
  3. Tuesday, 11 June 2019 16:37 PM UTC

Trying to use a inhouse built .Net dll in PB 2017 , that was successfully working in PB12.5

It gives an error "Cannot create object"

We are trying to connect to it with OleObject. Used REGASM to register that dll.

Anyone has a solution for this?

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Wednesday, 29 July 2020 06:59 AM UTC
  2. PowerBuilder
  3. # 1

Maybe there's an old version somewhere in the GAC.

Clean up any presence of your DLL in any global assembly folder.

Make sure you run regasm with the "/codebase" option.

 

Comment
There are no comments made yet.
Andrew Barnes Accepted Answer Pending Moderation
  1. Tuesday, 28 July 2020 16:29 PM UTC
  2. PowerBuilder
  3. # 2

Alternatively, if you have anyone handy with C/C++, you can create a C++ wrapper class using .NET interop to bridge between the PowerBuilder WinAPI and your .NET DLL.  There is more backend programming, but you do not need to futz about with COM, registering DLLs on the client machines, etc.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 28 July 2020 14:38 PM UTC
  2. PowerBuilder
  3. # 3

Hi Everyone;

   FWIW: If you migrate to PB2019R2, you can interface with a .Net DLL directly. No muss, no fuss, no com, etc.

Food for thought.

Regards ... Chris

 

Comment
There are no comments made yet.
Eric Freudenberg Accepted Answer Pending Moderation
  1. Wednesday, 12 June 2019 05:48 AM UTC
  2. PowerBuilder
  3. # 4

Hi,

using .Net DLL in PB17 is a little bit tricky, you have to take care of some things.

First your .Net DLL:
- the DLL must be COM visible (see .Net project settings)
- the created class / object must be COM visible. Place this code over every class/object you want to call / create via OleObject

        [ComVisible(true)]
        [ClassInterface(ClassInterfaceType.AutoDual)]
        [ProgId("MYCLASS")]

- you must register the DLL. You are right, use REGASM, but check if the class / object you define with [ProgId("MYCLASS")] is correct placed in registry

EDIT:
- the class / object you call / create via OleObject must be PUBLIC, all parents must be PUBLIC too
- the class / object can not be static or abstract, best practices is to hold your class / object and all called functions simple as possible (means argument types, return value and any types of access modifier)

As Second, your PB-Object. I think a sample is the best help, so here is a snippet from an old project (work fine in PB17):

LONG ll_erg = 0
STRING ls_msg = ""
OleObject myOLe

myOLe = CREATE OleObject

TRY
    CHOOSE CASE myOLe.ConnecTtoNewObject("MYCLASS")
        CASE -1
            ll_erg = in_e.icl_err_obj_invalid_call
            ls_msg = in_e.sof_get_enum_txt(ll_erg) + " MSG: Invalid Call: the argument is the Object property of a control"
            
        CASE -2
            ll_erg = in_e.icl_err_obj_invalid
            ls_msg = in_e.sof_get_enum_txt(ll_erg) + " MSG: Class name not found"
            
        CASE -3
            ll_erg = in_e.icl_err_obj_can_not_create
            ls_msg = in_e.sof_get_enum_txt(ll_erg) + " MSG: Object could not be created"
            
        CASE -4
            ll_erg = in_e.icl_err_obj_can_not_con
            ls_msg = in_e.sof_get_enum_txt(ll_erg) + " MSG: Could not connect to object"
            
        CASE -9
            ll_erg = in_e.icl_err_ext
            ls_msg = in_e.sof_get_enum_txt(ll_erg) + " MSG: Other error"
            
        CASE -15
            ll_erg = in_e.icl_err_obj_not_load
            ls_msg = in_e.sof_get_enum_txt(ll_erg) + " MSG: COM+ is not loaded on this computer"
            
        CASE -16
            ll_erg = in_e.icl_err_obj_invalid_call
            ls_msg = in_e.sof_get_enum_txt(ll_erg) + " MSG: Invalid Call: this function not applicable"
            
        CASE ELSE
            ll_erg = in_e.icl_err_default
    END CHOOSE

CATCH (Exception ex)
    // handle Exception
CATCH (RUNTIMEERROR err)
    // handle RunTimeError
END TRY

 

I hope it helps.

Greetings Eric

 

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 29 July 2020 12:09 PM UTC
Hi Nilanjan... FYI: the PB IDE is 32 bit only.
  1. Helpful
  1. Nilanjan Chatterjee
  2. Tuesday, 4 August 2020 03:34 AM UTC
Solution for those who might face similar issue:

We had installed PB2017 64bit version. So when we run PB it runs in 64-bit.

The dll that we are trying to use was built in 32-bit as that of the other dll the application use.

Browsed to the PB2017 installed path and changed to compatibility mode. Now PB is able to identify the dll and our issue is resolved.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 4 August 2020 03:42 AM UTC
The current PB IDE is 32 bit only. Appeon is looking into a 64 bit edition for PB 2021.
  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.