Link to home
Start Free TrialLog in
Avatar of aztec
aztec

asked on

Routine returning multiples of 65536

here's a strange one: I'm using this sort routine from a 3rd party vendor. It's in the form of a DLL...one of its parameters is a LONGINT which returns back to the calling program the final number of sorted records output. I was instructed to put a VAR in front of the parameter when I call this DLL.
  When I call the DLL when sorting a file...it sorts the file correctly, but always returns a crazy number in this recnum count field. And it always seems to be in multiples of 65536! If my input file has less than 65536 records, it'll return 0...if it has between 65536 and 131072, it'll return 65536...weird!
  I tried asking the people who make this sort routine, but they're idiots and they couldn't give me an answer. All they said is that it looks like the low order byte is being taken as the high order byte and so on. But didn't provide a solution. If this is in fact the case, is there a way to flip the bytes around in this longint field to yield the correct answer?

Thanks!
   Shawn Halfpenny
   drumme59@sprint.ca
Avatar of erajoj
erajoj
Flag of Sweden image

Is your declaration using stdcall as calling convention?

I.e: procedure ExtSort( var cRec: LongInt ); stdcall; // <<<<<<
external 'sort.dll' name 'Sort';

Could be it.

/// John
Avatar of pjdb
pjdb

do you use 32bit integer and do they use 32bits integer?

JDB
Avatar of aztec

ASKER

Hi John...
   Nah...tried every type of calling convention...none worked.
And in reply to JDB, I called the sort routine people and they say their sort routine in 32 bit also...I'm stumped!

Shawn
ASKER CERTIFIED SOLUTION
Avatar of EmmDieh
EmmDieh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can  you give me some return values and what the real value should be???
Avatar of aztec

ASKER

Hello EmmDieh...
   Success! Simply declaring that field as a DWORD (instead of Longint) seems to solve the problem! How large a number can a DWORD variable hold? It's a 32-bit field, yes? I would imagine it's a very large value.

Cheers
   Shawn
Yes, a DWORD is a 32bit unsigned integer. Strange enough that
this solves your problem. I would have thought that high
and low word had to be swapped. Guess I'll have to look it
up in the SDK,
Avatar of aztec

ASKER

Right on! DWORD works great!

Cheers
   Shawn Halfpenny