Jump to content

DllCall Problem: returns @error=1


c.haslam
 Share

Recommended Posts

The following code writes @error=1 to the console:

Local $DoxlibDll = DllOpen("doxlib.dll")
Local $ar, $bufIn, $lenIn, $bufOut, $lenOut, $opts
Local Enum $doc_rtf, $doc_html
Local $DOX_IN_RTF = ($doc_rtf + 1)
Local $DOX_OUT_HTML = BitShift($doc_html + 1, -4)
$opts = BitOR($DOX_IN_RTF, $DOX_OUT_HTML) ; RTF to HTML
Local $infilspc = @ScriptDir & "\sample.rtf"
If Not FileExists($infilspc) Then
    MsgBox(0, "", $infilspc & " not found")
    Exit
EndIf
Local $oufilspc = @ScriptDir & "\sample.htm"
$ar = DllCall($DoxlibDll, "long:cdecl", "DoxConvert", $infilspc, "str", $oufilspc, "str", $opts, "long")
ConsoleWrite("@error=" & @error & @CRLF)

The function converts RTF to HTML. sample.rtf converts OK in the author's test program.

Is my error in the parameters to DllCall, or elsewhere?

zip file containing .h file and DLL attached.

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

@c.haslam

Try this:

Global Const $DOX_IN_RTF  = 1
Global Const $DOX_IN_HTML = 2
Global Const $DOX_IN_TEXT = 3

Global Const $DOX_OUT_RTF  = 16
Global Const $DOX_OUT_HTML = 32
Global Const $DOX_OUT_TEXT = 48

Global $hDoxlibDll = DllOpen(@ScriptDir & "\doxlib.dll")

$sHTM = @ScriptDir & "\test.htm"
$sRTF = @ScriptDir & "\test.rtf"

If _DoxConvert($sRTF, $sHTM, BitOR($DOX_IN_RTF, $DOX_OUT_HTML)) Then
    MsgBox(64, "_DoxConvert", "Success")
Else
    MsgBox(16, "_DoxConvert", "Error")
EndIf

DllClose($hDoxlibDll)

Func _DoxConvert($sFileIn, $sFileOut, $iOpt)
    Local $aRet = DllCall($hDoxlibDll, "int:cdecl", "_DoxConvert", _
                                                    "str", $sFileIn, _
                                                    "str", $sFileOut, _
                                                    "int", $iOpt)
    Return $aRet[0]
EndFunc   ;==>_DoxConvert

:)

Link to comment
Share on other sites

And for _DoxStringConvert:

Global Const $DOX_IN_RTF  = 1
Global Const $DOX_IN_HTML = 2
Global Const $DOX_IN_TEXT = 3

Global Const $DOX_OUT_RTF  = 16
Global Const $DOX_OUT_HTML = 32
Global Const $DOX_OUT_TEXT = 48

Global $hDoxlibDll = DllOpen(@ScriptDir & "\doxlib.dll")

$sHTM = @ScriptDir & "\test.htm"
$sRTF = @ScriptDir & "\sample.rtf"

If _DoxConvert($sRTF, $sHTM, BitOR($DOX_IN_RTF, $DOX_OUT_HTML),$hDoxlibDll) Then
    MsgBox(64, "_DoxConvert", "Success")
Else
    MsgBox(16, "_DoxConvert", "Error")
EndIf

Local $OutBuff =""
Local $InBuff = "<html><body>cc<b>Test</b><i>test</i></body></html>"
$len = _DoxStringConvert($InBuff, $OutBuff, BitOr($DOX_IN_HTML,$DOX_OUT_RTF),$hDoxlibDll)
MsgBox(0,$len,"->"&$OutBuff&"<-")
If $len < 0 Then
   For $i = 0 To Abs($len)
      $OutBuff &= " "
   Next
$len = _DoxStringConvert($InBuff, $OutBuff, BitOr($DOX_IN_HTML,$DOX_OUT_RTF),$hDoxlibDll)
EndIf
MsgBox(0,$len,"->"&$OutBuff&"<-")

DllClose($hDoxlibDll)

Func _DoxConvert($sFileIn, $sFileOut, $iOpt,$hDoxlibDll="doxlib.dll")
    Local $aRet = DllCall($hDoxlibDll, "long:cdecl", "_DoxConvert", _
                                                    "str", $sFileIn, _
                                                    "str", $sFileOut, _
                                                    "long", $iOpt)
    Return $aRet[0]
EndFunc   ;==>_DoxConvert

Func _DoxStringConvert($sInBuffer, ByRef $sOutBuffer, $iOpt,$hDoxlibDll="doxlib.dll")
    Local $iInLength = StringLen($sInBuffer)
    Local $iOutLength = StringLen($sOutBuffer)
    Local $aRet = DllCall($hDoxlibDll, "long:cdecl", "_DoxStringConvert", _
                                                    "str", $sInBuffer, _
                                                    "long", $iInLength, _
                                                    "str", $sOutBuffer, _
                                                    "long", $iOutLength, _
                                                    "long", $iOpt)
    $sOutBuffer = StringLeft($aRet[3],$aRet[0])
    Return $aRet[0]
EndFunc   ;==>_DoxStringConvert

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Many thanks to both of you. Both functions are working for me. I find it mildly annoying that _DoxStringConvert() creates a log file and writes debug stuff to stdout.

Now to get the RichText Edit control working ...

...chris

Spoiler

CDebug Dumps values of variables including arrays and DLL structs, to a GUI, to the Console, and to the Clipboard

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...