把DLL改为delphi调用方法(100)

  • 主题发起人 主题发起人 woodyou
  • 开始时间 开始时间
W

woodyou

Unregistered / Unconfirmed
GUEST, unregistred user!
年历动态链接库提供万年历(从1900年到2050年长达150年的农历、生肖、天干地支、二十四节气、节假日)和星座(太阳星座、月亮星座)的计算功能。函数说明======== ●输入参数 int nyear; // 公历年份 int nmonth; // 公历月份 int nday; // 公历日 int nhour; // 小时 int nminute; // 分钟 ●输出参数 char week[4]; // 星期 int lyear; // 农历年份 int lmonth; // 农历月份 int lday; // 农历日 char cYear[6]; // 天支年 char cMonth[6]; // 干支月 char cDay[6]; // 干支日 char animals[4]; // 十二生肖 char lunarFestival[128]; // 农历节日 char solarFestival[128]; // 公历节日 char solarTerms[128]; // 二十四节气 bool isLeapYear; // 是否为闰年 bool isLeapMonth; // 是否包含闰月 int leapMonth; // 闰月的月份 int leapMonthDays; // 闰月的天数 char SunSignChn[8]; // 太阳星座的中文名称 char SunSignEn[12]; // 太阳星座的英文名称 char MoonSignChn[8]; // 月亮星座的中文名称 char MoonSignEn[12]; // 月亮星座的英文名称 ●万年历函数 把公历日期进行转换,得到了农历日期的属性和各种节日,提供农历日期、大小月、闰月、二十四节气、农历节日、天干地支计时、十二生肖、公历节日、星期等的查询。 VoliCalendar( int nyear, int nmonth, int nday, char *week, int *lyear, int *lmonth, int *lday, char *cYear, char *cMonth, char *cDay, char *animals, char *lunarFestival, char *solarFestival, char *solarTerms, bool *isLeapYear, bool *isLeapMonth, int *leapMonth, int *leapMonthDays ) ●星座函数 根据出生的年、月、日、时、分,得到对应的太阳星座和月亮星座。 VoliHoroscope( int nyear, int nmonth, int nday, int nhour, int nminute, char *SunSignChn, char *SunSignEn, char *MoonSignChn, char *MoonSignEn )使用举例======== 以下是一个用C++写的实例,在 Borland C++ Builder 5/6 中编译调试通过。 int nyear = Now().FormatString("yyyy").ToInt(); int nmonth = Now().FormatString("m").ToInt(); int nday = Now().FormatString("d").ToInt(); int nhour = Now().FormatString("h").ToInt(); int nminute = Now().FormatString("n").ToInt(); char week[4]; int lyear; int lmonth; int lday; char cYear[6]; char cMonth[6]; char cDay[6]; char animals[4]; char lunarFestival[128]; char solarFestival[128]; char solarTerms[128]; bool isLeapYear; bool isLeapMonth; int leapMonth; int leapMonthDays; char SunSignChn[8]; char SunSignEn[12]; char MoonSignChn[8]; char MoonSignEn[12]; // 加载 DLL HINSTANCE ins; ins = LoadLibrary("Calendar.dll"); // DLL 文件的路径 if( ins == NULL ) { ShowMessage("Can't Load Library!"); return; } // 加载函数 FARPROC proc, proc2; proc = GetProcAddress(ins, "_VoliCalendar"); proc2 = GetProcAddress(ins, "_VoliHoroscope"); if( proc == NULL || proc2 == NULL) { FreeLibrary(ins); ShowMessage("Can't Get Proc Address!"); return; } typedef void (* FUNC)( int nyear, int nmonth, int nday, char *week, int *lyear, int *lmonth, int *lday, char *cYear, char *cMonth, char *cDay, char *animals, char *lunarFestival, char *solarFestival, char *solarTerms, bool *isLeapYear, bool *isLeapMonth, int *leapMonth, int *leapMonthDays ); typedef void (* FUNC2)( int nyear, int nmonth, int nday, int nhour, int nminute, char *SunSignChn, char *SunSignEn, char *MoonSignChn, char *MoonSignEn ); FUNC VoliCalendarFunc=(FUNC)proc; FUNC2 VoliHoroscopeFunc=(FUNC2)proc2; // 调用函数 VoliCalendarFunc( nyear, nmonth, nday, week, &lyear, &lmonth, &lday, cYear, cMonth, cDay, animals, lunarFestival, solarFestival, solarTerms, &isLeapYear, &isLeapMonth, &leapMonth, &leapMonthDays ); VoliHoroscopeFunc( nyear, nmonth, nday, nhour, nminute, SunSignChn, SunSignEn, MoonSignChn, MoonSignEn ); // 释放 DLL if( !FreeLibrary(ins) ) { ShowMessage("Can't Free Library!"); return; }把以上DLL改为delphi调用方法
 
uses Windows;type TVoliCalendar = procedure (nyear,nmonth, nday: integer; szWeek: PChar; plyear,plmonth, plday: Pinteger; cYear, cMonth, cDay, animals, lunarFestival, solarFestival, solarTerms: PChar; pisLeapYear, pisLeapMonth: PBool; pleapMonth, pleapMonthDays: PInteger ); cdecl; TVoliHoroscope = procedure(nyear, nmonth, nday, nhour, nminute: integer; SunSignChn, SunSignEn, MoonSignChn, MoonSignEn: PChar ); cdecl;var LibHandle : Cardinal; VoliCalendar :TVoliCalendar; VoliHoroscope : TVoliHoroscope; SysTime : TSystemTime; Week: array [0..4-1] of Char; lyear,lmonth, lday: integer; cYear: array [0..6-1] of Char; cMonth: array [0..6-1] of Char; cDay: array [0..6-1] of Char; animals: array [0..4-1] of Char; lunarFestival: array [0..128-1] of Char; solarFestival: array [0..128-1] of Char; solarTerms: array [0..128-1] of Char; isLeapYear, isLeapMonth: BOOL; leapMonth, leapMonthDays: integer; SunSignChn: array [0..8-1] of Char; SunSignEn: array [0..12-1] of Char; MoonSignChn: array [0..8-1] of Char; MoonSignEn: array [0..12-1] of Char;begin LibHandle := LoadLibrary('Calendar.dll'); if LibHandle = 0 then begin Writeln('Can''t Load Library!'); Halt; end; try @VoliCalendar := GetProcAddress(LibHandle, '_VoliCalendar'); @VoliHoroscope := GetProcAddress(LibHandle, '_VoliHoroscope'); if not Assigned(VoliCalendar) or not Assigned(VoliHoroscope) then begin Writeln('Can''t Get Proc Address!'); Exit; end; GetLocalTime(SysTime); with SysTime do begin VoliCalendar(wYear, wMonth, wDay, Week, @lyear,@lmonth, @lday, cYear, cMonth, cDay, animals,lunarFestival, solarFestival, solarTerms, @isLeapYear, @isLeapMonth, @leapMonth, @leapMonthDays ); VoliHoroscope(wYear, wMonth, wDay, wHour, wMinute, SunSignChn, SunSignEn, MoonSignChn, MoonSignEn); end; finally if not FreeLibrary(LibHandle) then Writeln('Can''t Free Library!'); end;end.
 
结帐了,如果用暗的方法则如何调用VoliCalendar和 VoliHoroscope
 
后退
顶部