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?
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?
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.
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.
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
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