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

請問如何將c的struct轉成pascal的record

尚未結案
mhcjk
一般會員


發表:4
回覆:3
積分:1
註冊:2003-11-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-11-19 18:01:36 IP:61.219.xxx.xxx 未訂閱
struct hostent { char FAR * h_name; char FAR * FAR * h_aliases; short h_addrtype; short h_length; char FAR * FAR * h_addr_list; } 可否請各位大大告之此段要如何宣告成pascal的record
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-11-20 10:58:18 IP:147.8.xxx.xxx 未訂閱
16 bit? far is useless in 32 bit Delphi... Please refer to your C compiler manul for this kind of defination.    
type
    THostent = packed record
        h_name: PChar;
        h_aliases: PChar;
        h_addrtype: smallint;
        h_length: smallint;
        h_addr_list: PChar;
    end;
Depends on your defination of short, you may need to adjust smallint type to other (like shortint). h_alias and h_addr are probably pointing to an array of string.
mhcjk
一般會員


發表:4
回覆:3
積分:1
註冊:2003-11-12

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-11-20 11:42:43 IP:61.219.xxx.xxx 未訂閱
struct hostent { char FAR * h_name; char FAR * FAR * h_aliases; short h_addrtype; short h_length; char FAR * FAR * h_addr_list; } struct hostent FAR * gethostbyname ( const char FAR * name ); //sorry,一開始沒仔細寫清楚,我所call的是api,其原本的宣告如上。 type PHostent =^THostent; THostent = packed record h_name: PChar; h_aliases: PChar; h_addrtype: Shortint; h_length: Shortint; h_addr_list: PChar; end; function gethostbyname(const name:pchar):PHostent;stdcall;external 'ws2_32.dll'; 此為我以delphi所宣告的。執行後h_name確時可傳回正確的值,但其它的均伝回不正確的資料(可能無法正確對應到正確的位置)。 請大大們幫幫忙。
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-11-20 12:28:44 IP:147.8.xxx.xxx 未訂閱
mhcjk
一般會員


發表:4
回覆:3
積分:1
註冊:2003-11-12

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-11-20 12:52:06 IP:61.219.xxx.xxx 未訂閱
^^~ 哈哈~~我真的是想太多了~~ 原本就有宣告了~~ 謝謝大大囉~~~浪費大大的時間
系統時間:2024-04-29 11:31:51
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!