1. Jörg Walter
  2. PowerBuilder
  3. Friday, 18 August 2017 12:11 PM UTC

Hi

I want to use a DLL, in which Functions require as parameter and yield pointers to a certain structure.

 

Let's say I have a library header:

 

struct StructType

{

int a;

void* p;

};

extern _declspec(dllimport) StructType* Func(StructType*,bool);

I want to PB-write something like this:

declare pointer here as p

p = Func(p, true)

I dont care about the contents of the struct. I want to treat a pointer to that structure type as ... a long value or something like that.

How do I declare an external function for this?

 

 

 

Accepted Answer
Bruce Armstrong Accepted Answer Pending Moderation
  1. Friday, 18 August 2017 14:46 PM UTC
  2. PowerBuilder
  3. # Permalink

>>struct StructType
​>>{
>>int a;
>>void* p;
>>};

>>extern _declspec(dllimport) StructType* Func(StructType*,bool);
>>How do I declare an external function for this?

You still have to declare the structure, but you define the second attribute as a long because it is a pointer

mystruct
int a
long p

Declare your local external function as:

FUNCTION myStruct Func ( myStruct struct, boolean flag ) LIBRARY "libname"

Call it as:

mystruct struct
struct = Func ( struct, true ) 

The p attribute of the structure will be your pointer.

See 

http://infocenter-archive.sybase.com/help/index.jsp?topic=/com.sybase.dc37781_1150/html/psref/CCJBAEEF.htm
Comment
  1. Jörg Walter
  2. Monday, 21 August 2017 08:52 AM UTC
Thanks for the answers!



A follow-up:



In the struct I actually have the following types:



struct StructType



{



size_t a; // 32 bit or maybe 64 bit



char name[MAX_CHARS];



SomeEnumType type;



};



How do I translate these types into PB types?



I see this:



http://infocenter-archive.sybase.com/help/index.jsp?topic=/com.sybase.dc37781_1150/html/psref/BCGEGBDD.htm



and would translate it into



UnsignedInteger a;



Blob name; // ??? or : char name [1000]; ?



integer type;



Is that correct?



I tried the listed and got a bad runtime function reference error.



A call to a function in the same DLL without parameters or return type succeeded.



A call to a function with extern _declspec(dllimport) StructType* Func();



succeeded  when I declared it as:



FUNCTION long Func() LIBRARY "mydll.dll"



At least I got a long value back that smelled like a valid pointer



 



 

  1. Helpful
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Saturday, 19 August 2017 22:09 PM UTC
  2. PowerBuilder
  3. # 1

In the external function declaration you can use "structure" as the datatype.

Comment
  1. Jörg Walter
  2. Monday, 28 August 2017 13:12 PM UTC
Thanks for the answers!



A follow-up:



In the struct I actually have the following types:



struct StructType



{



size_t a; // 32 bit or maybe 64 bit



char name[MAX_CHARS];



SomeEnumType type;



};



How do I translate these types into PB types?



I see this:



http://infocenter-archive.sybase.com/help/index.jsp?topic=/com.sybase.dc37781_1150/html/psref/BCGEGBDD.htm



and would translate it into



UnsignedInteger a;



Blob name; // ??? or : char name [1000]; ?



integer type;



Is that correct?



I tried the listed and got a bad runtime function reference error.



A call to a function in the same DLL without parameters or return type succeeded.



A call to a function with extern _declspec(dllimport) StructType* Func();



succeeded  when I declared it as:



FUNCTION long Func() LIBRARY "mydll.dll"



At least I got a long value back that smelled like a valid pointer

  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.