Background

I have a file of VB a UDT's called Patient, which has the following definition...
VB Code:
  1. LName As String * 16       
  2.     FName As String * 12       
  3.     MName As String * 1            
  4.     BDate As String * 10       
  5.     NDate As String * 10       
  6.     Upi As Integer  'unique identifier

Each UDT is 100 bytes long...and is not in any discerning order in the file.

My application sorts these UDT's (500 records takes almost 1 second on a AMD 850mhz) when a new record is added.

My application does not sort the records in the file, but writes another file that just contains the UPI of each UDT in the order it should appear based on alphabetic order of LastName, FirstName, etc....

Problem
This works fine, but if I have 5000 records, I imagine it will take ten times longer. My idea was to implement a C++ dll to do the actual alphabetizing.

My half-ass ideas

Two solutions came to mind:
1) write C++ code to take an array of the UDT's and sort them (in memory). The problem is, I'm not quite certain how I should pass these UDT's to my C++ dll.


2) Read the file made by my VB app, take the values from that, and sort them, all within the C++ dll. The problem here is, even records of fixed-length UDT's seem to vary in size from record to record. I'm not sure how I can read these strings values into C++ since I actually have to examine each byte.

I would like to hear if anyone has encountered the same idea, or problem, and any suggestions as how I should approach this.