cancel
Showing results for 
Search instead for 
Did you mean: 

PB 12.5 Classic how to return a C# dll array

Former Member
0 Kudos

I created a dll in visual studio and using it in PB.  I am able to connect to the dll with no problems from PB.

If I call a function on the dll with a return of int or string it works fine but when I need to return an array/structure I get

"error calling external function"  How can/do you pass data (rows) back from a dll and into PB?

Thanks

Dave V.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

How are you defining the structure in C#?  Are there any non-standard datatypes?

And how are you declaring the method call in PB?  You should define a similar structure class in PB, and use that as the class of the return value or the byRef argument.

-Paul-

Former Member
0 Kudos

Hi Paul

Here is how I am declaring the structure (FIY.. c# created in Visual Studio Express 2013)

its coded in the class....(by the way I am new to C# so hopefully I defined it correctly)

(sorry had to uses pictures for some reason copy/paste into this window does not work causes to not be editable)

then in the method

In powerbuilder classic 12.5

I created a structure object to have the same fields and datatypes as the structure in c#.

I create an ole and do a connecttonewobject and call the method in this case GetFolder..

If I changed the return of the method to be int and return an number it works find but when I try to return the structure that's when I get an error of method not found... I also tried to create a simple function that just returns a simple array of int[] with only 3 items in it and that also did not work.  Seems like PB classic just chokes on arrays/structs...  or am I defining it wrong...

Any ideas...

Former Member
0 Kudos

OK - well, that's the C# side and it all looks fine.  That was the first half of my question...

What does your method declaration AND invocation code look like in PB?

You have to use a variable of the ANY datatype as the return variable, then you cast that into the defined structure.  Something like this:

ANY myAnyVar

myStructure l_myStructure[]  // local array of your structure class

myAnyVar = ReturnItems( "INBOX" )

l_myStructure = myAnyVar

Former Member
0 Kudos

Well one step closer I tried your suggestion on just simple array and got it to work but unfortunately not the one for the structured array it looks like it is trying to do something though because the function is taking a longer time before it gets the error.

It never makes it to where it takes the any and assigns it to the structure it bombs out on the method call "GetFolder"

here is my pb code ...

here is the error

Thanks for getting me at lease one step closer...

Former Member
0 Kudos

Are you seeing your method in the C# class get invoked?  Put some kind of tracing statements in there (write to a log file, put up a messagebox, etc...)

You'll get that error message for literally ANY error that happens inside the DLL.

And have you tried putting this in a TRY/CATCH block?  The error class may catch more details on the error being thrown by the DLL.

-Paul-

Former Member
0 Kudos

Not to familiar with the try/catch.. I do know that the method is working if I ran a c# program calling that method it works fine but in PB it does not like it.  For now I changed the return to be just a simple array and that is working fine.   I marked the answer with the array return as any since that was a big help.

Thanks for your help...

Dave V.

Answers (1)

Answers (1)

Former Member
0 Kudos

Just a guess...

Try passing the array as a "by ref" argument and have the return value be an integer or boolean that indicates success or failure.

Former Member
0 Kudos

Hi Roland... I thought the same thing and had tried it but did not work...