2008-11-17 25 views
2

調用DLL德爾福鑑於以下Delphil DLL聲明如何從VB6

function csd_HandleData(aBuf: PChar; aLen: integer): integer; stdcall; 

會是什麼VB6的聲明用呢?

我試過了各種各樣的聲明,例如

Declare Function csd_HandleData Lib "chsdet.dll" (ByVal aBuf As String, ByVal aLen As Integer) 
Declare Function csd_HandleData Lib "chsdet.dll" (aBuf As Long, ByVal aLen As Integer) 
Declare Function csd_HandleData Lib "chsdet.dll" (aBuf As Byte, ByVal aLen As Integer) 

與相關的代碼,以適應參數,但似乎沒有任何工作,即德爾福的調試器說我必須在阿倫和過於相當大的價值在aBuf中一個空字符串。

我正在努力使用TypeLib來驅動連接,但使用Declares進行原型設計。

+0

這裏是等價的C原型爲Delphi函數: INT csd_HandleData(字符* aBuf中,INT阿倫); 沒有什麼驚天動地的,但也許會因爲不熟悉德爾福而害怕貢獻的人得到答案。 – 2008-11-17 23:39:37

回答

3

嘗試

Declare Function csd_HandleData Lib "chsdet.dll" (ByVal aBuf As String, 
ByVal aLen As Integer) As Integer 

看來你忘了返回值。

+0

是的,我有。哦,尷尬(臉紅)。 – bugmagnet 2008-11-17 14:18:27

+0

這似乎工作。這意味着我輸入字符串的任何Unicode都會在輸入到DLL時被ANSI化,但只有Typelib會阻止這種情況,但無論如何Typelib是目標。 謝謝Steve和mj2008。 – bugmagnet 2008-11-18 01:02:54

-3

我不確切知道Vb是如何工作的,但PChar是一個指針,所以嘗試獲取引用而不是值。

Declare Function csd_HandleData Lib "chsdet.dll" (**ByReference <--guessing here :D** aBuf As String, ByVal aLen As Integer) 
-1

我不知道什麼是德爾福的PChar,它只是一個字符? ASCII? Unicode的?

VB6中的Integer是16位,你必須聲明aLen爲Long,它可以保存32位。

您還必須聲明函數的返回類型,在這種情況下,您還需要返回Long值。

這可能會工作: 聲明函數csd_HandleData庫「chsdet.dll」(aBuf中爲字節,BYVAL阿倫只要)只要

1

VB整數數據類型,是16bit,所以你應該把它聲明,只要是相當於Delphi和其他語言中的整數。

Declare Function csd_HandleData Lib "chsdet.dll" (ByVal aBuf As String, ByVal aLen As long) as long 
0

對於那些感興趣的,這裏是CHSDET typelib的最終IDL。給我留下了深刻的印象(在重新發現Matt Curland的EditTLB工具之後)是我可以將結構放入一個typelib中,VB處理它們就好像我在源代碼中聲明它們一樣。

我已經寫信給ChsDet的作者,也許這將最終成爲標準發行版的一部分。

// Generated .IDL file (by the OLE/COM Object Viewer) 
// 
// typelib filename: chsdet.tlb 

[ 
    uuid(316A83D7-8BF4-490E-BDDE-75EBC332C355), 
    version(1.0), 
    helpstring("Charset Detector - as the name says - is a stand alone executable module for automatic charset detection of a given text.\r\n\t\r\nIt can be useful for internationalisation support in multilingual applications such as web-script editors or Unicode editors.\r\n\t\r\nGiven input buffer will be analysed to guess used encoding. The result can be used as control parameter for charset conversation procedure.\r\n\t\r\nCharset Detector can be compiled (and hopefully used) for MS Windows (as dll - dynamic link library) or Linux.\r\n\t\r\nBased on Mozilla's i18n component - http://www.mozilla.org/projects/intl/. \r\n\r\nCharset Detector is open source project and distributed under Lesser GPL.\r\nSee the GNU Lesser General Public License for more details - http://www.opensource.org/licenses/lgpl-license.php\r\n\r\nNikolaj Yakowlew \xFFFFFFA9 2006-2008 \r\nTypeLib by Bruce M. Axtens, 2008.") 
] 
library CHSDET 
{ 
    // TLib :  // Forward declare all types defined in this typelib 

    [ 
     dllname("CHSDET.dll"), 
     version(1.0), 
     helpstring("Functions in CHSDET.DLL") 
    ] 
    module CHSDETFunctions { 
    [entry(0x60000000), helpstring("Returns rAbout record (qv)")] 
    void _stdcall GetAbout([in, out] rAbout* AboutRec); 
    [entry(0x60000001), helpstring("Reset detector. Prepares for new analysis.")] 
    void _stdcall Reset(); 
    [entry(0x60000002), helpstring("Analyse given buffer of specified length. 

Return value is of eHandleDataErrors, either 
NS_ERROR_OUT_OF_MEMORY (Unable to create internal objects) or NS_OK. 

Function can be called more that one time to continue guessing. Charset Detector remembers last state until Reset called.")] 
    void _stdcall HandleData(
      [in] BSTR aBuf, 
      [in] short aLen, 
      [out, retval] short* retVal); 
    [entry(0x60000003), helpstring("Returns either TRUE (Charset Detector is sure about text encoding.) or FALSE. 

NB: If input buffer is smaller then 1K, Charset Detector returns FALSE.")] 
    void _stdcall IsDone([out, retval] short* retVal); 
    [entry(0x60000004), helpstring("Signal data end. If Charset Detector hasn't sure result (IsDone = FALSE) the best guessed encoding will be set as result.")] 
    void _stdcall DataEnd(); 
    [entry(0x60000005), helpstring("Returns guessed charset as rCharsetInfo record")] 
    void _stdcall GetDetectedCharset([out, retval] rCharsetInfo* retVal); 
    [entry(0x60000006), helpstring("Returns all supported charsets in form "0x0A Name - CodePage"")] 
    void _stdcall GetKnownCharsets(
      [in, out] long* sList, 
      [out, retval] long* retVal); 
    [entry(0x60000007), helpstring("Return eBOMKind value matching byte order mark (if any) of input data.")] 
    void _stdcall GetDetectedBOM([out, retval] eBOMKind* retVal); 
    [entry(0x60000008), helpstring("Remove CodePage from consideration as a possible match")] 
    void _stdcall DisableCharsetCP([in] long CodePage); 
    }; 

    typedef [uuid(91694067-30AB-44A9-A210-F5602935475F)] 
    struct tagrAbout { 

long lMajor; 

long lMinor; 

long lRelease; 

long sAbout; 
    } rAbout; 

    typedef [uuid(3C8B7420-D40B-458B-8DE8-9B3D28607396)] 
    enum { 
    BOM_Not_Found = 0, 
    BOM_UCS4_BE = 1, 
    BOM_UCS4_LE = 2, 
    BOM_UCS4_2143 = 3, 
    BOM_UCS4_3412 = 4, 
    BOM_UTF16_BE = 5, 
    BOM_UTF16_LE = 6, 
    BOM_UTF8 = 7 
    } eBOMKind; 

    typedef [uuid(9B231DEF-93FB-440D-B06B-D760AECE09D0)] 
    struct tagrCharsetInfo { 

long Name; 

short CodePage; 

long Language; 
    } rCharsetInfo; 

    typedef enum { 
    NS_OK = 0, 
    NS_ERROR_OUT_OF_MEMORY = -2147024882 
    } eHandleDataErrors; 
};