Jump to content

Dll that allows to insert a BMP image into an RTF file


phoenix73
 Share

Recommended Posts

Hi! I'm a newbie in AutoIt Forum :">. I have the following question: I needed a RTF dll that allows me to insert a BMP image into an RTF file and I found the free "KCRtfCreator.dll" (http://www.kalpatarucomputers.com/kcrtfcreator.htm), but I am not able to load its procedures in AutoIt, while in VB6 it runs successfully. Please, tell me where I'm wrong.

B) IMHO the problems are that this dll perhaps cannot run with AutoIt and I can't pass the boolean type of the parameters in the dllcall.

Example code in VB6:

Private Sub Form_Load()

Dim objKCRTFWriter As New KCRTFWriter

With objKCRTFWriter

.FontName = "Trebuchet MS"

.Bold = True

.FontSize = .FontSize * 1.1

.TextAlignment = CenterAlign

.StartParaSelection

.InsertText "This is a test.", True

.EndParaSelection

.InsertBMPFromFile "D:\MyWork\export.bmp", True

.SaveInFile "D:\MyWork\test.rtf"

End With

End

End Sub

Example code in AutoIt v3 (beta):

$dll = DllOpen("KCRtfCreator.dll")

If $dll = -1 Then

MsgBox(0, "Error", "Unable to open dll.")

Exit

EndI

$BTMfile = "D:\MyWork\export.bmp"

$result1 = DllCall($dll, "none", "KCRTFWriter.StartParaSelection", "none","")

check(@error, 1)

$result2 = DllCall($dll, "none", "KCRTFWriter.InsertText", "str", "This is a test.", "none", True)

check(@error, 2)

$result3 = DllCall($dll, "none", "KCRTFWriter.EndParaSelection", "none","")

check(@error, 3)

$result4 = DllCall($dll, "none", "KCRTFWriter.InsertBMPFromFile", "str", $BTMfile, "none", True)

check(@error, 4)

$result5 = DllCall($dll, "none", "KCRTFWriter.SaveInFile", "str", "D:\MyWork\test.rtf")

check(@error, 5)

DllClose($dll)

Func check($err, $n_proc)

Select

Case $err = 0

$msg = "Procedure " & $n_proc & " runs successfully."

MsgBox(0, "Success", $msg)

Case $err = 1

$msg = "Unable to call procedure " & $n_proc

MsgBox(0, "Error", $msg)

Exit

Case $err = 2

$msg = "Unknown return type from procedure " & $n_proc

MsgBox(0, "Error", $msg)

Exit

EndSelect

EndFunc

Best regards.

Pho

Link to comment
Share on other sites

@phoenix73

This is more or less how you should do it.

You don' t need to use DLL OPEN.

;
; RTF Example
; PTREX 09/11/05
;

#include <GUIConstants.au3>
#NoTrayIcon

;Vars
Dim $oMyError
Dim $File = "C:\Temp\test.rtf"

;Declare objects
$oRTF = ObjCreate("objKCRTFWriter"); Default to Office XP
    If IsObj($oRTF) Then
        with $oRTF
            .FontName = "Trebuchet MS"
            .Bold = True
            .FontSize = 10
            .TextAlignment = "CenterAlign"
            .StartParaSelection
            .InsertText = "This is a test."
            .EndParaSelection
        ;.InsertBMPFromFile "D:\MyWork\export.bmp", True
            .SaveInFile = $File
        EndWith
    Else
       MsgBox(0,"Reply","Not an Object",4)
   EndIf
   
;Main Gui
GuiCreate("RTF Object", 802, 590,(@DesktopWidth-802)/2, (@DesktopHeight-590)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$GUI_ActiveX = GUICtrlCreateObj ($oRTF, 10, 10 , 780 , 550)
GUICtrlSetStyle ( $GUI_ActiveX,  $WS_VISIBLE )
GUICtrlSetResizing ($GUI_ActiveX,$GUI_DOCKAUTO) ; Auto Resize Object
    
GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    EndSelect
WEnd
Exit

;This is Sven P's custom error handler
Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"     & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description  & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "       & @TAB & $HexNumber              & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "       & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile     & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
  SetError(1) ; to check for after this function returns
Endfunc

I have not tested ot yet. Because I have not downloaded the DLL.

Maybe if you can link the DLL to this Thread we can all start testing.

Enjoy !!

Link to comment
Share on other sites

@ptrex

Thanks for your reply! It was useful to discover that in AutoIt 3 beta exist new interesting functions. Although, I'm not be able to run the script yet.

$oRTF = ObjCreate("KCRTFWriter")

gives me only the result on msgbox "Not An Object". Why? I'm sure that KCRTFWriter is an object. The user manual of the DLL tells this...

Maybe if you can link the DLL to this Thread we can all start testing.

Look at my 1st post B)

Furtherware, being the DLL of third parts, I can't post it here, but only write its link etc.

Thanks a lot for your advices.

Regards

Pho

Link to comment
Share on other sites

@ptrex

I solved the problem B) (thanks to your advices) in this way:

$hPlug = PluginOpen("KCRtfCreator.dll")

;Declare objects
$oRTF = ObjCreate("KCRtfCreator.KCRTFWriter.1")
    If IsObj($oRTF) Then
        with $oRTF
            .FontName = "Trebuchet MS"
            .Bold = True
            .FontSize = .FontSize * 1.1
            .TextAlignment = 3
            .StartParaSelection
            .InsertText ("This is a test.", True)
            .EndParaSelection
            .InsertBMPFromFile ($BMPfile, True)
            .SaveInFile ($File)
        EndWith
    Else
       MsgBox(0,"Reply","Not an Object",4)
   EndIf

PluginClose($hPlug)

"KCRtfCreator" makes possible to make RTF report into our applications, inserting BMP images, tables, etc.

It is free to use and then it can bypass the well-done "RTF plugin" by Lazycat.

Have fun!!

Pho

Link to comment
Share on other sites

@phoenix73

Glad to be of assistance.

But you can do somothing in return.

Please upload the DLL in this Thread (Attache it in the post) So that other people don' t have to go to the site and register themselves and download and ....

When the DLL in atached in a ZIP format, you probably well get more respons.

Thanks

Edited by ptrex
Link to comment
Share on other sites

Link to comment
Share on other sites

@phoenix73

If it's free to use, it is free to distribute it, isn't it ? If not I am not interested.

If you want people to use you application, you will have to accomodate them.

If not there will be very few people interested, I guess. :o

@ptrex

Here's my example script... :"> Finally you have convinced me... B)

Have fun

Pho

Link to comment
Share on other sites

Thanks for the contribution.

I ran the script and it runs like a charm !!

A small cosmetic correction.

I changed the path to a more universal approach.

Dim $RTFFile = @ScriptDir&"\test.rtf"

Dim $BMPFile = @ScriptDir&"\autoit9.bmp"

Keep on bringing good tools for AutoIT !! B)

Link to comment
Share on other sites

  • 1 month later...

no need to register to download

juste fill form with some caracter and the donwload start :lmao:

ps : where is this file ?

#include "_ShellExecute.au3"

D:\Downloads\test DLL\KCRtfCreator Example.au3(38,23) : ERROR: _ShellExecute(): undefined function.

Edited by pinkfoyd
Link to comment
Share on other sites

Thanks for providing this nice DLL, Phoenix! It looks to be much better than the method I was using before, but unfortunately I keep getting the "Not an Object" error (the ObjCreate is failing). Any idea why this would happen?

Link to comment
Share on other sites

Thanks for providing this nice DLL, Phoenix! It looks to be much better than the method I was using before, but unfortunately I keep getting the "Not an Object" error (the ObjCreate is failing). Any idea why this would happen?

Don't mention it! It is a pleasure to give something of useful to all the AutoIt users.

My idea is that perhaps the dll is not registered on your pc. If not, you have to copy the dll in windows/system32 directory and then register it with regsv32.

Regards

Pho

Link to comment
Share on other sites

Okay, now that works a lot better than the method described here, which always fails to create the object no matter how many times I register the required files.

Now I've gotten it to successfully save the RTF file with text and images, but I can't figure out how to create or configure a GUI control. I am going on Ptrex's example in post #2 (code below), which doesn't throw any obvious errors but doesn't seem to create the control either. Has anyone gotten it working?

EDIT: On closer inspection, it appears that this DLL is meant to be solely focused on outputting RTF files, rather than creating RTF GUI controls. Looks like I'll have to puzzle out the above-mentioned method after all (and if anyone could reply to my post there with a possible explanation, that would be great).

Edited by Sokko
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...