Solved

Routine returning multiples of 65536

Posted on 1998-08-13
8
193 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:aztec
8 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1362014
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
0
 
LVL 1

Expert Comment

by:pjdb
ID: 1362015
do you use 32bit integer and do they use 32bits integer?

JDB
0
 

Author Comment

by:aztec
ID: 1362016
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
0
 
LVL 1

Accepted Solution

by:
EmmDieh earned 50 total points
ID: 1362017
first try a DWORD as a Parameter, then a pointer to a DWORD.
Otherwise swap hi and lo word with something like
swapped := {Highword->Lo}(Res div 65536) +
           {Loword->Hi}(Res mod 65536) * 65536.
this does not work for negative values of course.
method 2:
var
  l: longint;
  r: record r1, r2: word; end absolute l;
  h: Word;
begin
  h := r.r1; r.r1 := r.r2; r.r2 := h;
end;

or method 3:
var
  l: record
     case boolean of
     true : (l: Longint);
     false: (r1, r2: word);
     end;
  h: Word;
begin
  h := l.r1; l.r1 := l.r2; l.r2 := h;
end;

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:rickpet
ID: 1362018
Can  you give me some return values and what the real value should be???
0
 

Author Comment

by:aztec
ID: 1362019
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
0
 
LVL 1

Expert Comment

by:EmmDieh
ID: 1362020
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,
0
 

Author Comment

by:aztec
ID: 1362021
Right on! DWORD works great!

Cheers
   Shawn Halfpenny
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Working this component WebCopy with proxy, help 3 76
Delphi Firemonkey Need Sample for Online Shopping Example. 2 120
How to debug For loops? 3 45
Base1 Encode/Decode 3 68
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now