線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1641
推到 Plurk!
推到 Facebook!

請問 DLL 這樣要怎樣傳?

尚未結案
SamSam1230
中階會員


發表:128
回覆:178
積分:65
註冊:2004-12-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-03-11 10:50:35 IP:218.103.xxx.xxx 未訂閱
我有一個DLL ABC.DLL 裡面有個function getinfo() : ^string return 是一個string pointer 我要怎麼樣才可以在delpi 裡把 return 的string 拿來用呢 我是以動態去Load DLL @DephiGetTimeFormat := GetProcAddress(DLLHandle, 'Getinfo'); 謝謝
mustapha.wang
資深會員


發表:89
回覆:409
積分:274
註冊:2002-03-13

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-03-11 12:11:19 IP:218.80.xxx.xxx 未訂閱
定义成一样的就可以 type   GetInfoProc=function: ^string;stdcall;    因为是传出的pointer,如果dll里是动态分配的内存用完自己要释放内存。 一般dll应该用PChar,在dll里的函数通常都是要求外部分配好内存传入,如 procedure GetInfo(PResult:Pchar);     久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听
------
江上何人初见月,江月何年初照人
SamSam1230
中階會員


發表:128
回覆:178
積分:65
註冊:2004-12-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-03-11 12:17:00 IP:218.103.xxx.xxx 未訂閱
我已經定義了一個type 跟你的一樣 Type Pstring :^string; TDephiGetTimeFormat = function :Pstring; . . . var DephiGetTimeFormat : TDephiGetTimeFormat ; . . . var x : string; x := DephiGetTimeFormat^; 這樣得不到正確的result 是那裡錯呢 可以告訴我嗎? 謝謝
SamSam1230
中階會員


發表:128
回覆:178
積分:65
註冊:2004-12-23

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-03-11 15:22:56 IP:218.103.xxx.xxx 未訂閱
其實我的問題是 我要get system date time format 我是用delphi 4.0 然後發現 SysUtils unit 沒有 procedure GetLocaleFormatSettings ( LCID : Integer; var FormatSettings : TFormatSettings 所以用MFC 去寫一個DLL 給delphi 用 要pass 一條 string , 但C pass string 會 pass string pointer 所以請問delphi 4.0 有GetLocaleFormatSettings 可以call 嗎? 或者是DLL 要pass by ref .string pointer 要怎麼用 謝謝大大
mustapha.wang
資深會員


發表:89
回覆:409
積分:274
註冊:2002-03-13

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-03-11 22:54:38 IP:218.1.xxx.xxx 未訂閱
当然你不能在dll里写 function getinfo() : ^string;sdtcall; var   S:string; begin   ....   Result:=@S; end; 把局部变量返回,因为局部变量离开函数就自动释放了。 1.记得用stdcall 2.让外部传Pchar来比较好 3.SysUtils.LongDateFormat,SysUtils.LongTimeFormat     久病成良医--多试 千人之诺诺,不如一士之谔谔--兼听 發表人 - mustapha.wang 於 2005/03/11 22:57:52
------
江上何人初见月,江月何年初照人
SamSam1230
中階會員


發表:128
回覆:178
積分:65
註冊:2004-12-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-03-15 14:16:11 IP:218.103.xxx.xxx 未訂閱
謝謝mustapha.wang 我試試看
SamSam1230
中階會員


發表:128
回覆:178
積分:65
註冊:2004-12-23

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-03-16 10:02:06 IP:218.103.xxx.xxx 未訂閱
引言: 当然你不能在dll里写 function getinfo() : ^string;sdtcall; var S:string; begin .... Result:=@S; end;
想請問一下, 你這個dll 裡的function call 的寫法嗎? 已經是這樣的方法寫 另外在主程式裡是這樣call 的
type
PString = ^string
TDephiGetTimeFormat = function :Pstring;    var
DephiGetTimeFormat   :TDephiGetTimeFormat;    begin
    @DephiGetTimeFormat := GetProcAddress(DLLHandle, 'GetMyTimeFormat');    S := DephiGetTimeFormat^;    end;
就會有以下的error 請問我是那裡錯呢? 謝謝
rexchiu
中階會員


發表:14
回覆:88
積分:70
註冊:2002-03-17

發送簡訊給我
#8 引用回覆 回覆 發表時間:2005-03-16 14:30:08 IP:220.130.xxx.xxx 未訂閱
插個花... 其實你要的東西..SysUtils.pas中就有了.. 以下貼出 help 中的說明
Influence the way numeric or date/time values are formatted.    Unit    Sysutils    The following are a set of variables used to define the format for numeric or date/time strings:    var CurrencyString: string;
var CurrencyFormat: Byte;
var NegCurrFormat: Byte;
var ThousandSeparator: Char;
var DecimalSeparator: Char;
var CurrencyDecimals: Byte;
var DateSeparator: Char;
var ShortDateFormat: string;
var LongDateFormat: string;
var TimeSeparator: Char;
var TimeAMString: string;
var TimePMString: string;
var ShortTimeFormat: string;    var LongTimeFormat: string;
var ShortMonthNames: array[1..12] of string;
var LongMonthNames: array[1..12] of string;
var ShortDayNames: array[1..7] of string;
var LongDayNames: array[1..7] of string;    var SysLocale: TSysLocale;
var EraNames: array[1..7] of string;
var EraYearOffsets: array[1..7] of Integer;
var TwoDigitYearCenturyWindow: Word = 50;    var TListSeparator: Char;    Description    The Sysutils unit includes a number of variables that are used by various formatting routines. Values are assigned to these variables to define the formats of numeric and date/time strings. The initial values of these variables are fetched from the system registry using the GetLocaleInfo function in the Win32 API. VCL (non-console) applications automatically update these formatting variables in response to WM_WININICHANGE messages. The Application variable? UpdateFormatSettings method either allows or disallows changes in system settings. The default is True. Set this property to False to prevent the system settings from changing.    The description of each variable specifies the LOCALE_XXXX constant used to fetch the initial value using the GetLocaleInfo Win32 API.    Typed constant        Defines    CurrencyString        CurrencyString defines the currency symbol (or characters) used in floating-point to decimal conversions. The initial value is fetched from LOCALE_SCURRENCY.
CurrencyFormat        CurrencyFormat defines the currency symbol placement and separation used in floating-point?o?ecimal conversions. Possible values are:
0 = $1
1 = 1$
2 = $ 1
3 = 1 $
The initial value is fetched from LOCALE_ICURRENCY.
NegCurrFormat        NegCurrFormat defines the currency format used in floating-point to decimal conversions of negative numbers. Possible values are:
0 = ($1)    4 = (1$)    8 = -1 $     12 = $ -1
1 = -$1     5 = -1$     9 = -$ 1     13 = 1- $
2 = $-1     6 = 1-$    10 = 1 $-    14 = ($ 1)
3 = $1-     7 = 1$-    11 = $ 1-    15 = (1 $)
The initial value is fetched from LOCALE_INEGCURR.    ThousandSeparator        ThousandSeparator is the character used to separate thousands in numbers with more than three digits to the left of the decimal separator. The initial value is fetched from LOCALE_STHOUSAND.
DecimalSeparator        DecimalSeparator is the character used to separate the integer part from the fractional part of a number. The initial value is fetched from LOCALE_SDECIMAL.
CurrencyDecimals        CurrencyDecimals is the number of digits to the right of the decimal point in a currency amount. The initial value is fetched from LOCALE_ICURRDIGITS.    DateSeparator        DateSeparator is the character used to separate the year, month, and day parts of a date value. The initial value is fetched from LOCATE_SDATE.
ShortDateFormat        ShortDateFormat is the format string used to convert a date value to a short string suitable for editing. For a complete description of date and time format strings, see the documentation for the FormatDateTime function. The short date format should only use the date separator character and the  m, mm, d, dd, yy, and yyyy format specifiers. The initial value is fetched from LOCALE_SSHORTDATE..    LongDateFormat        LongDateFormat is the format string used to convert a date value to a long string suitable for display but not for editing. For a complete description of date and time format strings, see the documentation for the FormatDateTime function. The initial value is fetched from LOCALE_SLONGDATE.
TimeSeparator        TimeSeparator is the character used to separate the hour, minute, and second parts of a time value. The initial value is fetched from LOCALE_STIME.    TimeAMString        TimeAMString is the suffix string used for time values between 00:00 and 11:59 in 12-hour clock format. The initial value is fetched from LOCALE_S1159.
TimePMString        TimePMString is the suffix string used for time values between 12:00 and 23:59 in 12-hour clock format. The initial value is fetched from LOCALE_S2359.
ShortTimeFormat        ShortTimeFormat is the format string used to convert a time value to a short string with only hours and minutes. The default value is computed from LOCALE_ITIME and LOCALE_ITLZERO.    LongTimeFormat        LongTimeFormat is the format string used to convert a time value to a long string with hours, minutes, and seconds. The default value is computed from LOCALE_ITIME and LOCALE_ITLZERO.
ShortMonthNames        ShortMonthNames is the array of strings containing short month names. The mmm format specifier in a format string passed to FormatDateTime causes a short month name to be substituted. The default values are fetched from the LOCALE_SABBREVMONTHNAME system locale entries.     LongMonthNames        LongMonthNames is the array of strings containing long month names. The mmmm format specifier in a format string passed to FormatDateTime causes a long month name to be substituted. The default values are fetched from the LOCALE_SMONTHNAME system locale entries.
ShortDayNames        ShortDayNames is the array of strings containing short day names. The ddd format specifier in a format string passed to FormatDateTime causes a short day name to be substituted. The default values are fetched from the LOCALE_SABBREVDAYNAME system locale entries.    LongDayNames        LongDayNames is the array of strings containing long day names. The dddd format specifier in a format string passed to FormatDateTime causes a long day name to be substituted. The default values are fetched from the LOCALE_SDAYNAME system locale entries.
SysLocale        Indicates the locale used by FormatDateTime to interpret dates.
EraName        Controls the DateTimeToStr function (for East Asian locales).    EraYearOffsets        Controls the DateTimeToStr function (for East Asian locales).
TwoDigitYearCenturyWindow        Determines what century is added to two-digit years when string dates are converted to numeric dates with StrToDate or StrToDateTime. The value of TwoDigitYearCenturyWindow, if it is nonzero, is subtracted from the current year to calculate the floating ?ivot?prior to which two-digit years are interpreted as falling in the next century. The default value is 50. You can use TwoDigitYearCenturyWindow to extend the life of legacy applications that are tied to two-digit-year data entry; but the best solution is to require four-digit input for years.    ListSeparator        The character used to separate items in a list. The default value is fetched from LOCALE_SLIST.
這樣好像不好看,去查delphi的help 中有關Currency and date/time formatting variables就是了. 以你要的東西你只要直接去取得 ShortDateFormat,LongDateFormat,ShortTimeFormat,LongTimeFormat 這幾個字串就是了
------
Best Regards,
Rex Chiu
SamSam1230
中階會員


發表:128
回覆:178
積分:65
註冊:2004-12-23

發送簡訊給我
#9 引用回覆 回覆 發表時間:2005-03-17 09:27:46 IP:218.103.xxx.xxx 未訂閱
謝謝各位大大的熱心幫助 問題解決了
系統時間:2024-05-21 21:44:46
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!