cancel
Showing results for 
Search instead for 
Did you mean: 

I have a structure in PB. How do I pass it to C function thru DLL call & return values within structure?

Former Member
0 Kudos

I have a structure in PB. How do I pass it to C function thru DLL call & return values within structure?

Any sample code would be appreciated.

Here are sample IDL structures we currently us in PB12.

$PBExportHeader$str_app_error_t.srs

global type str_app_error_t from structure

Char s_component[4]

Char s_type[16]

UnsignedLong ul_num

UnsignedLong ul_level

Char s_text[256]

end type

$PBExportHeader$str_app_user_t.srs

global type str_app_user_t from structure

Integer level

Long plength

Long flength

Long elength

Char principal[258]

Char full_name[258]

Char exp_date[31]

end type

Clint

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi.

Normally the structure can be passed as you pass any other variable (except if it use datatypes or objects that aren't compatible with c datatypes, which doesn't seem to be your case). The function you want to call from a dll returns a structure? Or it expects a reference of the structure?

Andreas.

Former Member
0 Kudos

Thank you for the comment but we haven't resolved our issue.

How to we extract/assign values from/to the structure from the c/c## function? We are calling with these two complex structures from PB (see my original post).

global type str_app_error_t from structure

global type str_app_user_t from structure

Any help is appreciated. Thanks again.

Former Member
0 Kudos

You have to declare a variable with the type of your structure to pass it to the function.

Example:

str_app_error_t lstr_app_error

str_app_user_t lstr_app_user

lstr_app_user.level = 1

...

your_dll_call (lstr_app_user, lstr_app_error)

...

MessageBox ("Error", lstr_app_error.s_text)

Is it that what you want to know?

Former Member
0 Kudos

Hi Clinton;

  Just make sure that you pass the PB Structure in by reference when you declare the external function call to your C method.

For example (where "s_netresource" is a structure):

FUNCTION ulong WNetUseConnection (ulong hwndOwner, REF s_netresource lpNetResource, string lpPassword, string lpUsername, ulong dwFlags, REF string lpAccessName, REF ulong lpBufferSize, REF ulong lpResult) Library "MPR.DLL" ALIAS FOR "WNetUseConnectionA;Ansi"

Note: You may also need to declare the extremal method as expecting ANSI arguments - hence the ";ANSI" qualifier used at the end of the FUNCTION declaration. Omitting this piece will default to PB sending everything in Unicode format.

HTH

Regards ... Chris

Former Member
0 Kudos

Thank you for the comment but we haven't resolved our issue.

How to we extract/assign values from/to the structure from the c/c## function? We are calling with these two structures from PB (see my original post).

global type str_app_error_t from structure

global type str_app_user_t from structure

Any help is appreciated. Thanks again.