Highlighted
Absent Member.
Absent Member.
1677 views

[archive] c dll unsigned-int

[Migrated content. Thread originally posted on 14 October 2008]

hello

i have a problem getting a unsigned int declerated return value off a c-dll function.

situation:
01 handle1 usage is handle.
01 port usage unsigned-int.
01 CardType usage unsigned-int.
01 structure1.
05 var1 pic x(30).
05 pic x.
05 var2 pic x(25).
05 pic x.
05 var3 usage unsigned-int.
05 pic x.
05 var4 pic x(15).
05 pic x.

call "dllfunction" using by value handle1,
by value port,
by reference CardType,
by reference structure1
end-call.

Problem:
handle and port are correct transmitted to the function but the return-value does not contain the desired values. the strings in this structure work as intended but neither CardType or var3 contain the values the c-function returns. how do i get unsigned int values of a c-function? am i missing something obvious?

*edit*: typo
0 Likes
9 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

A better choice than unsigned-int is PIC X(4) COMP-N, try this.

I am assuming you want a 32 bit unsigned integer.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

A better choice than unsigned-int is PIC X(4) COMP-N, try this.

I am assuming you want a 32 bit unsigned integer.


hello,

thank you for the answer but it does not work either.

and yes its a 32 bit unsigned int.

the return-value for CardType is 2 and for var3 its 1.
with unsigned-int i get CardType 0 and var3 49.
with pic x(4) COMP-N i get CardType 0 and var3 12544.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

What calling convention do you use? Do you have any documentation on the DLL, or example in C on how to call the DLL?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

im using __cdecl convention. with dll-convention 1 i get a memory access violation.

partly solved:

inside the structur i had to use 2 filling bytes (pic x(2)) to get the right value in unsigned-int.

this is no option/not working for CardType
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

Don't do that. Use PIC X(4) COMP-N for any instance of unsigned int. Sorry, I realized I did not make that clear in the first post.
I am assuming of course that unsigned int on this machine is 32 bit?

Can I get to see the C source (or declaration in header file) for this function (not the body, just the header), or documentation on its use from C?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

in fact i use pic x(4) comp-n delcaration for the dword32 value

the struct looks like that now

01 structure1.
05 var1 pic x(30).
05 filler1 pic x.
05 var2 pic x(25).
05 filler2 pic xxx.
05 var3 pic x(4) comp-n.
05 var4 pic x(15).
05 filler4 pic x.

i had to buff filler2 from just NULL-Char Container to NULL-Char Container + 2 fillbytes to get it working.


*edit:*sent you the header infos as a private message

*edit2:* the original structure is a bit longer and contains 2 dword32 variables. in order to get it working i have to use 2 additional fillbytes berfore the first and one additional fillbyte before the second one.
still not getting the single dword32 CardType to work 😕
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

I hate to hijack a thread but we just started interfacing with a dll and there were several unsigned int and longs which I setup to use PIC X(2) COMP-N and PIC X(4) COMP-N this all works perfectly except when the longs come back with a negative number then on my side it's some rediculously huge number like 4296967295... is there something special I need to do to handle this or should I just switch the longs to PIC S9(9) COMP-5's (which show the correct negative number)?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

If you need to have the negative, you have to use PIC S9(9) COMP-5.
PIC X(4) COMP-N is an unsigned storage.

However, if you expect large numbers into a PIC S9(9) COMP-5 item, do remember to use the --TruncANSI option.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] c dll unsigned-int

Thanks for the help, and no we don't expect huge numbers, prob nothing more than 9999.99 and nothing less than -9999.99.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.