PhilipG Posted January 3, 2010 Share Posted January 3, 2010 i have a dll file witch i want to use. I never done this before and keep getting some strange error msg. In the documentation for the dll file they say the following:#include "apdf.h" HPDF_Doc pdf; pdf = HPDF_New (error_handler, NULL); if (!pdf) { printf ("ERROR: cannot create pdf object.\n"); return 1; } if (setjmp(env)) { HPDF_Free (pdf); return 1; } When i try to use the HPDF_New (error_handler, NULL) function I use the following code snippet:$vPath = drivers\libhpdf.dll $hDll = DllOpen($vPath) $nDll = DllCall($hDll, "hwnd", "HPDF_New", "str", "Error_Handler", "none", "null");And the result is @error = 1, unable to use the DLL file.Is there any format problem in the syntax or is it something else or could it be both? I've tried to solve this for almost 4hours and now i'm out of ideas. Link to comment Share on other sites More sharing options...
trancexx Posted January 3, 2010 Share Posted January 3, 2010 First time can be painful. Four hours of poking for sure. Try something like this: $sDLL = "libhpdf.dll" ; full path maybe $hDll = DllOpen($sDLL) $aCall = DllCall($hDll, "ptr:cdecl", "HPDF_New", "ptr", 0, "ptr", 0) ; you need to check what pointers should point to ConsoleWrite($aCall[0] & @CRLF) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
martin Posted January 3, 2010 Share Posted January 3, 2010 First time can be painful. Four hours of poking for sure. Try something like this: $sDLL = "libhpdf.dll" ; full path maybe $hDll = DllOpen($sDLL) $aCall = DllCall($hDll, "ptr:cdecl", "HPDF_New", "ptr", 0, "ptr", 0) ; you need to check what pointers should point to ConsoleWrite($aCall[0] & @CRLF) There comes a time when the pain ends?? pdf is defined as 'long' so the return type should be long, but maybe it makes no difference if you're using a 32 bit OS. To pass a function for a callback, which is what the error handler is, you need to use DllCallBackRegister, and then pass the pointer obtained from DllCallBackGetPtr. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
trancexx Posted January 3, 2010 Share Posted January 3, 2010 (edited) There comes a time when the pain ends??It's nothing but pleasure then.pdf is defined as 'long' so the return type should be long, but maybe it makes no difference if you're using a 32 bit OS.Where do you see that?edit: 's Edited January 3, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
PhilipG Posted January 3, 2010 Author Share Posted January 3, 2010 (edited) Well you lost me there... I tried your script by the way! executed following code: $sDLL = '@ScriptDir & "\drivers\libhpdf.dll'; full path maybe $hDll = DllOpen($sDLL) $aCall = DllCall($hDll, "ptr:cdecl", "HPDF_New", "ptr", 0, "ptr", 0) ; you need to check what pointers should point to ConsoleWrite($aCall[0] & @CRLF) The dll path is c:\scriptdir\drivers\dll.dll so that schould be right i guess The function returned: Subscript used with non-Array variable.: ConsoleWrite($aCall[0] & @CRLF) ConsoleWrite($aCall^ ERROR >Exit code: 1 Time: 0.210 I guess that that means that it doesnt find the dll? or am i wrong? Edited January 3, 2010 by PhilipG Link to comment Share on other sites More sharing options...
PhilipG Posted January 3, 2010 Author Share Posted January 3, 2010 Just noticed that dllcall still returns @error=1 Link to comment Share on other sites More sharing options...
trancexx Posted January 3, 2010 Share Posted January 3, 2010 Just noticed that dllcall still returns @error=1 Your last posted code, expanded: $sDLL = '@ScriptDir & "\drivers\libhpdf.dll'; full path maybe If FileExists($sDLL) Then ConsoleWrite("I'm cool" & @CRLF) Else MsgBox(32 + 262144, "ZZzzzz!", "WTF did I wrote there?!?") Exit EndIf $hDll = DllOpen($sDLL) ;... ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
PhilipG Posted January 3, 2010 Author Share Posted January 3, 2010 Your last posted code, expanded: $sDLL = '@ScriptDir & "\drivers\libhpdf.dll'; full path maybe If FileExists($sDLL) Then ConsoleWrite("I'm cool" & @CRLF) Else MsgBox(32 + 262144, "ZZzzzz!", "WTF did I wrote there?!?") Exit EndIf $hDll = DllOpen($sDLL) ;... I just found the problem '@ScriptDir & "\drivers\libhpdf.dll'; should be @ScriptDir & "\drivers\libhpdf.dll"; No it works and returns following: 0x01D32158 What to do with that? (I feel like a total newbie) Link to comment Share on other sites More sharing options...
martin Posted January 3, 2010 Share Posted January 3, 2010 Where do you see that? In Form1.frm Dim pdf As Long That was the only definition of pdf I found in the source code for Haru pdf. @PhilipG Test the error to see what is going wrong. $aCall = [url="../autoit3/docs/functions/DllCall.htm"]DllCall[/url]($hDll, "ptr:cdecl", "HPDF_New", "ptr", 0, "ptr", 0) ; you need to check what pointers should point to [url="../autoit3/docs/functions/ConsoleWrite.htm"]ConsoleWrite[/url]("@error after DllCall = " & @error & [url="../autoit3/docs/macros.htm"]@CRLF[/url]) and see the help for the meaning of the value. Also try with something like this Func error_handler($erno,$status,$userData) consolewrite("Error from dll: Error = " & $erno & ", detail number = " & $status & @CRLF) return 0 endfunc $hCB = DllCallBackRegister("error_handler","int","int:int:ptr") $aCall = DllCall($hDll, "int:cdecl", "HPDF_New", "ptr", DllCallbackGetPtr($hCB), "ptr", 0) [url="../autoit3/docs/functions/ConsoleWrite.htm"]ConsoleWrite[/url]("@error after DllCall = " & @error & [url="../autoit3/docs/macros.htm"]@CRLF[/url]) It looks to me like the dll version of Harupdf uses the stdcall method so the "int:cdecl" might need to be just "int". We'll probably find that Prog@ndy already has a udf in his back pocket for all this and we're wasting our time. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
martin Posted January 3, 2010 Share Posted January 3, 2010 I just found the problem '@ScriptDir & "\drivers\libhpdf.dll'; should be @ScriptDir & "\drivers\libhpdf.dll";No it works and returns following:0x01D32158What to do with that?(I feel like a total newbie)That's good. I think that is the value for the pdf that you need to use as a parameter in other calls to the dll. You must remember to free the value (handle?) with a call to HPDF_Free when you've finished. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
ProgAndy Posted January 3, 2010 Share Posted January 3, 2010 We'll probably find that Prog@ndy already has a udf in his back pocket for all this and we're wasting our time.Not this time. This is all i found in my archives (only the start of an UDF)HPDF_convert.au3 ... i tried to create an automatic convertertest.txt ... the result of the converterAU3\hpdf.h.au3 ... the very first manual start*.h ... the c-header files you have to convert libharu.zip *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 More sharing options...
PhilipG Posted January 3, 2010 Author Share Posted January 3, 2010 Not this time. This is all i found in my archives (only the start of an UDF)HPDF_convert.au3 ... i tried to create an automatic convertertest.txt ... the result of the converterAU3\hpdf.h.au3 ... the very first manual start*.h ... the c-header files you have to convert Thanks for that, really helpful to see some other script. Do i really need to convert the c-headers? isn't the .dll files working on there own? Link to comment Share on other sites More sharing options...
ProgAndy Posted January 3, 2010 Share Posted January 3, 2010 (edited) The c-headers contain the function definitions, in especially their parameters and the type to use (ptr/str/long/...) You do not have to convert all, but the functions and constants you need to use the dll in you script Edited January 3, 2010 by ProgAndy *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 More sharing options...
PhilipG Posted January 3, 2010 Author Share Posted January 3, 2010 The c-headers contain the function definitions, in especially their parameters and the type to use (ptr/str/long/...) You do not have to convert all, but the functions and constants you need to use the dll in you scriptAnd i would take it that the headers is the files in the include folder (*.h)?I never worked with C so please excuse my inertia Link to comment Share on other sites More sharing options...
PhilipG Posted January 3, 2010 Author Share Posted January 3, 2010 (edited) I've started to translate the funtions. But now a new problem has come up. When i run the functions rewritten the first two works but then when it's supposed to run set HPDF_SetCompressionMode it fail, big time. Auto it stops responding, and that window: "Autoit has encountered a problem.... etc. " Pops up! This can't be good. Is this a common problem or is it easily solved? The code so far: expandcollapse popupGlobal Const $HPDF_HANDLE = "ptr" Global Const $HPDF_Doc = $HPDF_HANDLE ; Global Const $HPDF_Page = $HPDF_HANDLE ; Global Const $HPDF_Pages = $HPDF_HANDLE ; Global Const $HPDF_Stream = $HPDF_HANDLE ; Global Const $HPDF_Image = $HPDF_HANDLE ; Global Const $HPDF_Font = $HPDF_HANDLE ; Global Const $HPDF_Outline = $HPDF_HANDLE ; Global Const $HPDF_Encoder = $HPDF_HANDLE ; Global Const $HPDF_Destination = $HPDF_HANDLE ; Global Const $HPDF_XObject = $HPDF_HANDLE ; Global Const $HPDF_Annotation = $HPDF_HANDLE ; Global Const $HPDF_ExtGState = $HPDF_HANDLE ; Func _PdfDLLstart(ByRef $sErr) $vPath = @ScriptDir & "\libhpdf.dll" $hDll = DllOpen($vPath) If $hDll = 0 Then SetError(1) $sErr = 'Failed to open ' & $vPath Return -1;failed EndIf Return $hDll;ok EndFunc Func _PdfNew(ByRef $nErr, $hDll) ;DllCall($hDll, "str", "#include", "str", "apdf.h");#include "apdf.h" ;DllCall($hDll, "str", "HPDF_Doc");#include "apdf.h" $nDll = DllCall($hDll, "ptr:cdecl", "HPDF_New", "ptr", 0, "ptr", 0) ;DLLCall($hDll, $HPDF_Doc , "HPDF_New", _ ;"str", "error_handler", _ ;"none", "NULL");) ;DllCall($hDll, "hwnd", "HPDF_New", "str", "Error_Handler", "none", "null"); If @error Then $nErr = "Failed to execute HPDF_new() command! Error code: "&@error&" Error from Dll: "&$nDll Return -1;failed EndIf Return $nDll[0];ok EndFunc Func _PdfNew(); _PdfDocAtr(ByRef $daErr, $nDll, $hDll) ;set compression mode $temp = DllCall($hDll, 'float', "HPDF_SetCompressionMode", "ptr:cdecl", $nDll, 'uint', "HPDF_COMP_ALL"); if @error >= 1 Then $daErr = "Set compression mode failed! Error code: "&@error & "Return value: ";& $temp[0] return -1;failed EndIf endfunc EDIT: This functions are called from an other document the calling code: #include 'PdfMaker.au3' Global $HD, $nDll, $page Local $mmssgg $HD = _PdfDLLstart($mmssgg) if $HD = 0 then consolewrite("Error from dllstart = " & $mmssgg & @CRLF) Exit endif $nDll = _PdfNew($mmssgg, $HD) if $nDLL = -1 then consolewrite("Error from DllCall = " & $mmssgg & @CRLF) Exit endif $a = _PdfDocAtr($mmssgg, $nDll, $HD) if $a = -1 then consolewrite("Error from aDllCall = " & $mmssgg & @CRLF) Exit endif Edited January 3, 2010 by PhilipG Link to comment Share on other sites More sharing options...
trancexx Posted January 3, 2010 Share Posted January 3, 2010 You are writing bunch of nonsenses.Leave libhpdf.dll aside for some time and learn about DllCall() and related functions.Then try calling these functions by yourself GetCurrentProcess, Sleep, Beep, MessageBox.All of them all well documented (follow the links). When you are done with them and have the full understanding of your actions then try functions from libhpdf.dll.Otherwise it's kind of sad reading, really. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
martin Posted January 4, 2010 Share Posted January 4, 2010 (edited) Not much time to help on this now but the function HPDF_SetCompressionMode defined here requires 2 parameters; a PDF value which was returned from a previous call to HPDF_NEW, but remember to use $nDll[0] not $nDll, and thesecond parameter required is an integer. You have passed a string!$temp = DllCall($hDll, 'float', "HPDF_SetCompressionMode", "ptr:cdecl", $nDll, 'uint', "HPDF_COMP_ALL");should possibly beConst $HPDF_COMP_ALL = 0x0F ;?? not sure $temp = DllCall($hDll, 'int:cdecl', "HPDF_SetCompressionMode", "ptr", $nDll[0], 'uint', $HPDF_COMP_ALL); Edited January 4, 2010 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
PhilipG Posted January 4, 2010 Author Share Posted January 4, 2010 (edited) Ah... Thanks for that! I've totally missed the string thing. I'm done with rewriting the script now. It works to the point where it outputs a .pdf file but for some reason that i still don't now the file is damaged. I've tracked the script for errors. and I only found one, according to the dlls document files, a very weird one: "Unexpected EOF marker was detected." I assume that they mean EOF = End of File Could this be caused by a corrupt .dll? I am almost 100% that i followed the calling sequence described in the documentation! Edited January 4, 2010 by PhilipG Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now