Hi, as relative newbe into C#integration with PB (2919 R2) I thought I'd give it a try. So I started with a .net dll function as simple as it could be created with snapdevelop in powerscript.
- Snapdevelop ClassLibrary 1 c# Code:
using System;
namespace tester
{
public class Utility
{
public string ReadEnv()
{
string user = Environment.UserName;
return user;
}
}
}
- Compiled, Built and Published fine with all depedenys to directory D:\Temp\pp\
- Imported into Powerbuilder with .NET DLL Importer as nvo_utility, PB Source code follows
forward
global type nvo_utility from dotnetobject
end type
end forward
global type nvo_utility from dotnetobject
end type
global nvo_utility nvo_utility
type variables
PUBLIC:
String is_assemblypath = "D:\Temp\pp\ClassLibrary1.dll"
String is_classname = "tester.Utility"
end variables
forward prototypes
public function string of_readenv ()
end prototypes
public function string of_readenv ();
//*-----------------------------------------------------------------*/
//* .NET function : ReadEnv
//* Return : String
//*-----------------------------------------------------------------*/
Return This.readenv()
end function
on nvo_utility.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nvo_utility.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
- Trying to use it in PB results in Error "Object instance does not exist " - cb_1.clicked() event
string ls_username
nvo_utility lnvo_utility
lnvo_utility = create nvo_utility
ls_username = lnvo_utility.of_readenv( ) // Exits with error
messagebox("Gotcha",ls_username)
destroy lnvo_utility
I tried chaging the "Return This.readenv()" to "Return This:ReadEnv()" since c# is case sensitive but run into same runtime error. Then i tried Bruce's .Net Importer Demo from CodeExchange resulting in the same Error as soon as I call the windows function of_sendmail from w.main.
Any Idea's what I'm missing?
regards
Peter
P.S. I Sure look forward to the elevate conference!
True, Yesterday i actually missed the Method 1 of your suggestion. Today, before I got your answer i came up with just about the same as your Method 2 after i follwed the powerbuilder help "Importing .NET assembly" by using scripted Loadwithdotnetcore() and Createinstance() :-)
I must say method 1 is alot easier and I just missed it in the Application techniques part of Help. So I'd like to emphasisze appeon to maybe note this more clearly in the PB Help or even make 'Encapsulate a DonenetAssembly object in each DotNetObject object' a default setting for Import.
I think your advice is very reasonable.
I will record it as a new enhancement/requirement request and will transfer it to our product team for consideration.