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

DELPHI如何調用C寫的DLL文件!

答題得分者是:shunchia63
stars_chen
一般會員


發表:14
回覆:35
積分:9
註冊:2006-10-29

發送簡訊給我
#1 引用回覆 回覆 發表時間:2007-06-21 15:26:55 IP:218.104.xxx.xxx 訂閱
請問各位大大們我應該如何調用這個C寫的DLL文件中的FUNCTION呢?
需要調用:
SMODEM_DLL_API int fnSModem_GetFinderID(char *rfMAC, char *finderID);
SMODEM_DLL_API int fnSModem_Init(char *fname);
SMODEM_DLL_API int fnSModem_Exit();
下面是DLL文件的說明


// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the SMODEM_DLL_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// SMODEM_DLL_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
//#ifdef SMODEM_DLL_EXPORTS
#define SMODEM_DLL_API __declspec(dllexport)
//#else
//#define SMODEM_DLL_API __declspec(dllimport)
//#endif
// This class is exported from the SModem_DLL.dll
class SMODEM_DLL_API CSModem_DLL {
public:
CSModem_DLL(void);
// TODO: add your methods here.
};
extern SMODEM_DLL_API int nSModem_DLL;
/*
fname: Filename for logging - like "f:\\logs.txt"
Please note this file is always appended so that there is no data
loss when application restarts. Each new session starts with
system data and time.
This file has to be kept safe by ASUS and sent to Sling Media on
regular basis.
return value:
0: success
-100: file (fname) could not be opened in append mode.
-200: another instance of this DLL might have been
instantiated.
*/
SMODEM_DLL_API int fnSModem_Init(char *fname);
/*
return value:
0: success
-100: not closed properly because of multiple active sessions.
*/
SMODEM_DLL_API int fnSModem_Exit();
/*
rfMAC: NULL terminated string with FinderID - like "0013B6000001".
This should of exactly 12 bytes for "strlen()".
6 byte MAC address needs 12 bytes in string format. 13th byte,
rfMAC[12], should be NULL.

finderID:
16 byte FinderID needs 32 bytes in string format. 33rd byte,
finderID[32], will be NULL.
return value:
0: success
-100: rfMAC is not a 12 byte string.
-200: another instance of this DLL might have been
instantiated.
-300: fnSModem_Init() was unable to open text log file.
*/
SMODEM_DLL_API int fnSModem_GetFinderID(char *rfMAC, char *finderID);


shunchia63
高階會員


發表:26
回覆:141
積分:198
註冊:2007-05-22

發送簡訊給我
#2 引用回覆 回覆 發表時間:2007-06-22 09:33:01 IP:61.62.xxx.xxx 訂閱
     <textarea class="delphi" rows="10" cols="60" name="code"> 宣告 function fnSModem_GetFinderID(rfMAC:Pchar; finderID:Pchar): integer; cdecl;external 'DLLName.dll' name 'fnSModem_GetFinderID'; </textarea>

參考Delphi HELP 主題:Calling conventions
stars_chen
一般會員


發表:14
回覆:35
積分:9
註冊:2006-10-29

發送簡訊給我
#3 引用回覆 回覆 發表時間:2007-06-22 09:57:57 IP:218.104.xxx.xxx 訂閱
這種方法好像不行,調試運行時會報錯.

shunchia63
高階會員


發表:26
回覆:141
積分:198
註冊:2007-05-22

發送簡訊給我
#4 引用回覆 回覆 發表時間:2007-06-23 10:59:48 IP:61.62.xxx.xxx 訂閱
DLL Type 為C++ 我測過用上述方式會無法載入進入點 請改用index方式即可    How to Know Index?  A:Please using Tool"depends.exe" Dump 即可    Sample: <textarea class="delphi" rows="10" cols="60" name="code"> function fnSModem_Init(fname: PCHAR ): integer;stdcall; external 'C:\SModem_DLL.dll' index 5; </textarea> ShunChia.
stars_chen
一般會員


發表:14
回覆:35
積分:9
註冊:2006-10-29

發送簡訊給我
#5 引用回覆 回覆 發表時間:2007-06-25 10:57:37 IP:218.104.xxx.xxx 訂閱
OK.
thank you for your help!
系統時間:2024-05-02 10:34:07
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!