Advertisement
TLama

Untitled

Dec 18th, 2014
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.75 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6.   Windows, SysUtils;
  7.  
  8. type
  9.   PZIP = ^TZIP;
  10.   TZIP = array[0..4] of AnsiChar;
  11.   PState = ^TState;
  12.   TState = array[0..1] of AnsiChar;
  13.   PCityName = ^TCityName;
  14.   TCityName = array[0..27] of AnsiChar;
  15.   PCountyNum = ^TCountyNum;
  16.   TCountyNum = array[0..2] of AnsiChar;
  17.   PCountyName = ^TCountyName;
  18.   TCountyName = array[0..24] of AnsiChar;
  19.  
  20.   // typedef int (CALLBACK* FindCityCounty)(
  21.   //   char ZIP[5],char cityname[28],char state[2],char countyname[25],char countynum[3]);
  22.   TFindCityCounty = function(ZIP: PZIP; CityName: PCityName; State: PState; CountyName: PCountyName;
  23.     CountyNum: PCountyNum): Integer; stdcall;
  24.  
  25. procedure runCA(pCA: TFindCityCounty);
  26. var
  27.   rc: Integer;
  28.   ZIP: TZIP;
  29.   State: TState;
  30.   CityName: TCityName;
  31.   CountyNum: TCountyNum;
  32.   CountyName: TCountyName;
  33. begin
  34.   // set input parameters - strncpy(ZIP,"10601",5);
  35.   Move(AnsiString('10601'), ZIP[0], 5 * SizeOf(AnsiChar));
  36.   // print the input
  37.   Writeln('Input ZIP code: ', ZIP);
  38.   // call the function - no result checking in the original example code ?   [DCC Hint] H2077
  39.   rc := pCA(@ZIP, @CityName, @State, @CountyName, @CountyNum);
  40.   // print the output
  41.   Writeln('Output city: ', CityName);
  42.   Writeln('Output state: ', State);
  43.   Writeln('Output county name: ', CountyName);
  44.   Writeln('Output county number: ', CountyNum);
  45. end;
  46.  
  47. var
  48.   hDLL: HMODULE;
  49.   pCA: TFindCityCounty;
  50. begin
  51.   // Load DLL and get function location
  52.   hDLL := LoadLibrary('CorrectA.dll');
  53.   if hDLL <> 0 then
  54.   try
  55.     pCA := GetProcAddress(hDLL, 'FindCityCounty');
  56.     if Assigned(pCA) then
  57.       runCA(pCA)
  58.     else
  59.       Writeln('FindCityCounty function could not be found.');
  60.   finally
  61.     FreeLibrary(hDLL);
  62.   end;
  63.   Readln;
  64. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement