realshyfox Posted June 2, 2011 Share Posted June 2, 2011 (edited) I have a free dll that offers three functions to create PDF file from Tiff. But the problem is that when I call it´s functions throws an error:!>08:48:55 AutoIT3.exe ended.rc:-1073741819 >Exit code: -1073741819 Time: 6.630+This is the code:$Tif2PDF_DLL = DllOpen(@ScriptDir & "\tif2pdf.dll") $PDFN = @ScriptDir & "\Img.pdf" $PDFTmpN = @ScriptDir & "\Temp" $TiffFile = @ScriptDir & "\2069.tif" DllCall($Tif2PDF_DLL, "int", "open_PDF", "str", $PDFTmpN) DllCall($Tif2PDF_DLL, "int", "add_TIFF", "str", $TiffFile) DllCall($Tif2PDF_DLL, "int", "close_PDF", "str", $PDFTmpN, "str", $TiffFile) DllClose($Tif2PDF_DLL)Here sample code for C++, Delphi and C#:C++ code sample:expandcollapse popuptypedef int ( *PFN_open_PDF)(const char *); PFN_open_PDF open_PDF; typedef int ( *PFN_close_PDF)(const char *,const char *); PFN_close_PDF close_PDF; typedef int ( *PFN_add_TIFF)(const char *); PFN_add_TIFF add_TIFF; HINSTANCE hDll; void LoadDll() { hDll=LoadLibrary(_T("tif2pdf.dll")) if(hDll) { open_PDF=(PFN_open_PDF)GetProcAddress(hDll,"open_PDF"); add_TIFF=(PFN_add_TIFF)GetProcAddress(hDll,"add_TIFF"); close_PDF=(PFN_close_PDF)GetProcAddress(hDll,"close_PDF"); } } int OpenPDF(const char *n) { if (open_PDF) return (*open_PDF)(n); else return -1; } int AddTIFF(const char *n) { if (add_TIFF) return (*add_TIFF)(n); else return -1; } int ClosePDF(const char *n,const char *n1) { if (close_PDF) return (*close_PDF)(n,n1); else return -1; } int _tmain(int argc, _TCHAR* argv[]) { LoadDll(); if (OpenPDF("tmp_image")== 0){ AddTIFF("image1.tif"); AddTIFF("image2.tif"); ClosePDF("tmp_image","image.pdf"); } if (hDll!=NULL) FreeLibrary(hDll); return 0; }C# code sample:public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("tif2pdf.dll")] static extern int open_PDF(String n); [DllImport("tif2pdf.dll")] static extern int add_TIFF(String n); [DllImport("tif2pdf.dll")] static extern int close_PDF(String n, String n1); private void button1_Click(object sender, EventArgs e) { if (open_PDF("temp_name") == 0) { add_TIFF("image1.tif"); add_TIFF("image2.tif"); close_PDF("temp_name", "image.pdf"); } }Delphi code sample:function open_PDF(tmp_namefile:PChar):integer;cdecl; external 'tif2pdf.dll' name 'open_PDF'; function close_PDF(tmp_namefile,pdf_namefile:PChar):integer;cdecl ; external 'tif2pdf.dll' name 'close_PDF'; function add_TIFF(tiff_namefile:PChar):integer;cdecl ; external 'tif2pdf.dll' name 'add_TIFF'; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin if open_PDF('temp_pdf')=0 then begin add_TIFF('image1.tif'); add_TIFF('image2.tif'); close_PDF('temp_pdf','image.pdf'); end; end;This is the Dll:Original site:Code-Industry.NET Edited June 2, 2011 by realshyfox Learn, learn and ... learn Link to comment Share on other sites More sharing options...
smartee Posted June 2, 2011 Share Posted June 2, 2011 hi, Try return type as int:cdecl -smartee Link to comment Share on other sites More sharing options...
realshyfox Posted June 2, 2011 Author Share Posted June 2, 2011 (edited) hi, Try return type as int:cdecl -smartee I did this, but it doesn´t work ... $Tif2PDF_DLL = DllOpen(@ScriptDir & "\tif2pdf.dll") $PDFN = @ScriptDir & "\2069.pdf" $PDFTmpN = @ScriptDir & "\Temp" $TiffFile = @ScriptDir & "\2069.tif" DllCall($Tif2PDF_DLL, "int:cdecl", "open_PDF", "str", $PDFTmpN) DllCall($Tif2PDF_DLL, "int:cdecl", "add_TIFF", "str", $TiffFile) DllCall($Tif2PDF_DLL, "int:cdecl", "close_PDF", "str", $PDFTmpN, "str", $TiffFile) DllClose($Tif2PDF_DLL) Edited June 2, 2011 by realshyfox Learn, learn and ... learn Link to comment Share on other sites More sharing options...
rover Posted June 2, 2011 Share Posted June 2, 2011 It is advisable to post the link to the original site instead of posting a dll that is part of a package, without its installer and EULA http://code-industry.net/tiff2pdf.php The return is cdecl, and $PDFTmpN should be a temp filename, not a temp folder Check for the expected return code and error from the dll call 0 = success, less than 0 (-1, -3 etc.) = fail (for this dll) Use ConsoleWrite(), _WinAPI_GetLastErrorMessage() and _WinAPI_GetLastError() when testing a dll call. ConsoleWrites slow down a script, so comment them out or remove them for a compiled script #include <WinAPI.au3> Local $aRet Local $Tif2PDF_DLL = DllOpen(@ScriptDir & "\tif2pdf.dll") Local $PDFN = @ScriptDir & "\Img.pdf" Local $PDFTmpN = @TempDir & "\temp.bin" Local $TiffFile = @ScriptDir & "\PIA08329.tif" $aRet = DllCall($Tif2PDF_DLL, "int:cdecl", "open_PDF", "str", $PDFTmpN) ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage()) ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf) If @error Then Exit ConsoleWrite('-open_PDF return = ' & $aRet[0] & @crlf & '>Error code: ' & @error & @crlf) $aRet = DllCall($Tif2PDF_DLL, "int:cdecl", "add_TIFF", "str", $TiffFile) ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage()) ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf) If @error Then Exit ConsoleWrite('-add_TIFF return = ' & $aRet[0] & @crlf & '>Error code: ' & @error & @crlf) $aRet = DllCall($Tif2PDF_DLL, "int:cdecl", "close_PDF", "str", $PDFTmpN, "str", $PDFN) ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage()) ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf) ConsoleWrite('-close_PDF return = ' & $aRet[0] & @crlf & '>Error code: ' & @error & @crlf) DllClose($Tif2PDF_DLL) I see fascists... Link to comment Share on other sites More sharing options...
realshyfox Posted June 2, 2011 Author Share Posted June 2, 2011 It is advisable to post the link to the original site instead of posting a dll that is part of a package, without its installer and EULA http://code-industry.net/tiff2pdf.php The return is cdecl, and $PDFTmpN should be a temp filename, not a temp folder Check for the expected return code and error from the dll call 0 = success, less than 0 (-1, -3 etc.) = fail (for this dll) Use ConsoleWrite(), _WinAPI_GetLastErrorMessage() and _WinAPI_GetLastError() when testing a dll call. ConsoleWrites slow down a script, so comment them out or remove them for a compiled script #include <WinAPI.au3> Local $aRet Local $Tif2PDF_DLL = DllOpen(@ScriptDir & "\tif2pdf.dll") Local $PDFN = @ScriptDir & "\Img.pdf" Local $PDFTmpN = @TempDir & "\temp.bin" Local $TiffFile = @ScriptDir & "\PIA08329.tif" $aRet = DllCall($Tif2PDF_DLL, "int:cdecl", "open_PDF", "str", $PDFTmpN) ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage()) ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf) If @error Then Exit ConsoleWrite('-open_PDF return = ' & $aRet[0] & @crlf & '>Error code: ' & @error & @crlf) $aRet = DllCall($Tif2PDF_DLL, "int:cdecl", "add_TIFF", "str", $TiffFile) ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage()) ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf) If @error Then Exit ConsoleWrite('-add_TIFF return = ' & $aRet[0] & @crlf & '>Error code: ' & @error & @crlf) $aRet = DllCall($Tif2PDF_DLL, "int:cdecl", "close_PDF", "str", $PDFTmpN, "str", $PDFN) ConsoleWrite('+_WinAPI_GetLastErrorMessage() = ' & _WinAPI_GetLastErrorMessage()) ConsoleWrite('+_WinAPI_GetLastError() = ' & _WinAPI_GetLastError() & @crlf) ConsoleWrite('-close_PDF return = ' & $aRet[0] & @crlf & '>Error code: ' & @error & @crlf) DllClose($Tif2PDF_DLL) Thanyou rover. I updated my first post too(my fault, I should be more carefull, but no harm intended.) Learn, learn and ... learn 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