Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

At 29 JUN 1998 08:26:09PM Terry Evans wrote:

I'm trying to use a third party DLL that requires a C type structure be passed. I've used the Define_Struct function to define the structure to OI, not sure if I've got the call correct.

structure MY_STRUCT was defined as:

char48

char48

char200

DLL is declare with Declare_FCNS as:

short pascal MyFunc(plvoid)

I am trying to call it this way:

declare function MyFunc

myStruct=Build_Struct('MY_STRUCT', 'Fld1', 'Fld2', 'Fld3')

x=MyFunct(myStruct)

Is this correct?

Any help appreciated and TIA

Terry


At 30 JUN 1998 10:09AM Cameron Revelation wrote:

Terry,

structure MY_STRUCT was defined as: char48 char48 char200

Could you also post the C documentation (or header file) that defines the structure? I don't often see structures like the one above.

DLL is declare with Declare_FCNS as: short pascal MyFunc(plvoid)

So you are passing as pointer to the structure and receiving back a 16-bit signed int.

I am trying to call it this way: declare function MyFunc myStruct=Build_Struct('MY_STRUCT', 'Fld1', 'Fld2', 'Fld3') x=MyFunct(myStruct) Is this correct?

No. The result of Build_Struct is a binary structure in an OpenInsight variable. To pass a pointer to that binary structure you would either have to call it like:

x=MyFunc(GetPointer(myStruct)) ;* pass a pointer to the struct

or you would have to declare the DLL function so that OpenInsight knows to automatically pass a pointer to the variable data that you give it:

short pascal MyFunc(LPCHAR)

I suggest the latter. For more information, open BRFHELP.HLP in the OpenInsight directory and read Chapter 7.

Cameron Purdy

Revelation Software


At 30 JUN 1998 05:14PM Terry wrote:

Cameron

I read Ch7, but besides giving an overview of the process, I didn't see an example call. How to define, and several way to populate and parse a structure but no function calls using them.

the 'C' structure looks like this

typedef struct {

char sender48;
char comment48;
char message200;

} ParamDef;

two things though:

1) Should myStruct be locked in memory prior to this call?

"x=MyFunc(GetPointer(myStruct))"

Something like:

"LockVariable myStruct as ???
 x=MyFunc(GetPointer(myStruct))
 UnlockVariable(myStruct)"

and if so what do you lock a structure "as"

2) You used LPCHAR in your declaration of MyFunc:

"short pascal MyFunc(LPCHAR)"

Is that the correct variable type to use for all structures?

TIA

Terry


At 01 JUL 1998 07:32AM Cameron Revelation wrote:

Terry,

1) Should myStruct be locked in memory prior to this call?

"x=MyFunc(GetPointer(myStruct))"

No. You only have to lock variables when you are going to be doing other things after getting a pointer to the variable that could cause the engine to move the variable. For example:

* this code needs a lockvariable because the pointer value is stored

* in p but nothing guarantees that myStruct won't move in memory

* while the engine is processing the other instructions (i.e. the for loop)

p=GetPointer(myStruct)

for i=1 to 10

call MyFunc(p)

next i

2) You used LPCHAR in your declaration of MyFunc:

"short pascal MyFunc(LPCHAR)"

Is that the correct variable type to use for all structures?

Yes. BASIC+ variables when treated as "strings" are actually variable-length binary (basically just byte arrays). A structure in C is basically a fixed-length byte array that you can access parts of by name with some type safety. So if you need to pass a pointer to a C structure which is in a BASIC+ variable, it is the same as passing a string, so declare it as LPCHAR.

Cameron Purdy

Revelation Software


At 01 JUL 1998 01:33PM Terry Evans wrote:

Great! :) Thanks for the help

Two pointers I still need help with (pun intended).

1) If I wanted to lock a structure variable would the syntax be:

"LockVariable myStruct as CHAR"

2) One of the third party DLL's function is declared in C as:

"short pascal theFunc(long far* far* list);"

It returns a pointer to an array of longs that were allocated by the function (probably malloc or something). There is another function that will take this pointer and handle the deallocation for me, so I don't have to worry about that interface. But I'm not sure how to declare the variable in OI to access the values of the LONGs or what the function declaration should look like?

"short pascal theFunct(LPCHAR)" ???
  • LONG_STRUCT was defined with DEFINE_STRUCT with 6 longs
f1=0,0,0,0,0,0'
convert ',' to @fm in f1
indexList=Var_To_Struct(f1, LONG_STRUCT)
x=theFunct(GetPointer(indexList))

This looks like I've allocated space in OI instead of telling it that the function is doing that.

TIA

Terry


At 01 JUL 1998 03:35PM Cameron Revelation wrote:

Terry,

Check out this knowledge base article.

Cameron Purdy

Revelation Software


At 02 JUL 1998 11:33AM Terry Evans wrote:

Cameron

I'd read the article earlier but it didn't make as much sense as now. Thanks for the help!!!

Terry

View this thread on the forum...

  • third_party_content/community/commentary/forums_nonworks/a7a120d18e5d3c7585256633000264f6.txt
  • Last modified: 2023/12/28 07:40
  • by 127.0.0.1