imdumb Posted December 17, 2022 Share Posted December 17, 2022 here is my code FileChangeDir(@ScriptDir) $sDLL_Path = 'E:\Chung\OCRandRE\IRL64' $AIRL_Name = 'AIRL.dll' $IRL_Name = 'ImageRecognition.dll' $__gh_DLL_AIRL = DllOpen('E:\Chung\OCRandRE\IRL64\AIRL.dll') $__g_h_Tess = DllOpen('E:\Chung\OCRandRE\libtesseract-5.dll') MsgBox(0,'',@WorkingDir&' Open $__g_h_Tess ' & $__g_h_Tess &' Open $__gh_DLL_AIRL ' & $__gh_DLL_AIRL) DllClose($__g_h_Tess) _ScriptRestart() it work normal eveytime script restart but when i add DllCall FileChangeDir(@ScriptDir) $sDLL_Path = 'E:\Chung\OCRandRE\IRL64' $AIRL_Name = 'AIRL.dll' $IRL_Name = 'ImageRecognition.dll' $__gh_DLL_AIRL = DllOpen('E:\Chung\OCRandRE\IRL64\AIRL.dll') $__g_h_Tess = DllOpen('E:\Chung\OCRandRE\libtesseract-5.dll') DllCall($__gh_DLL_AIRL, 'handle', 'AIRL_InitLibrary', 'wstr', $sDLL_Path, 'wstr', $IRL_Name) ;;;;; -- here MsgBox(0,'',@WorkingDir&' Open $__g_h_Tess ' & $__g_h_Tess &' Open $__gh_DLL_AIRL ' & $__gh_DLL_AIRL) DllClose($__g_h_Tess) _ScriptRestart() The Second restart show that the $__g_h_Tess DLL file cannot be opened anyone can point me how to deal with this RestartUDF : Link to comment Share on other sites More sharing options...
ioa747 Posted December 17, 2022 Share Posted December 17, 2022 i don't know But i have see in help file If a dll filename is given then the DLL is automatically loaded and then closed at the end of the call. If you want to manually control the loading and unloading of the DLL then you should use DllOpen() and DllClose() and use a handle instead of a filename in this function. try when add in your code DllClose($__gh_DLL_AIRL) maybe... I know that I know nothing Link to comment Share on other sites More sharing options...
imdumb Posted December 17, 2022 Author Share Posted December 17, 2022 53 minutes ago, ioa747 said: i don't know But i have see in help file If a dll filename is given then the DLL is automatically loaded and then closed at the end of the call. If you want to manually control the loading and unloading of the DLL then you should use DllOpen() and DllClose() and use a handle instead of a filename in this function. try when add in your code DllClose($__gh_DLL_AIRL) maybe... Tks for help but no matter if i add DLLClose or not, not thing change , still error Link to comment Share on other sites More sharing options...
Musashi Posted December 17, 2022 Share Posted December 17, 2022 (edited) 29 minutes ago, imdumb said: ... but no matter if i add DLLClose or not, not thing change , still error If you use only a few DllCalls, then an explicit DllOpen and DllClose is not mandatory. Just use DllCall with the specification of the filename. DllCall opens the DLL and closes it immediately after the call. Check the @error macro right after the DllCall to see if the operation was successful.Excerpt from the help : Failure: sets the @error flag to non-zero.@error: 1 = unable to use the DLL file, 2 = unknown "return type", 3 = "function" not found in the DLL file, 4 = bad number of parameters, 5 = bad parameter. Edited December 17, 2022 by Musashi typo "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
imdumb Posted December 17, 2022 Author Share Posted December 17, 2022 5 hours ago, Musashi said: If you use only a few DllCalls, then an explicit DllOpen and DllClose is not mandatory. Just use DllCall with the specification of the filename. DllCall opens the DLL and closes it immediately after the call. Check the @error macro right after the DllCall to see if the operation was successful.Excerpt from the help : Failure: sets the @error flag to non-zero.@error: 1 = unable to use the DLL file, 2 = unknown "return type", 3 = "function" not found in the DLL file, 4 = bad number of parameters, 5 = bad parameter. if i call only 1 of them , they will work as normal , but if i use both of them , the second DLLCall give error Do you have any idea Link to comment Share on other sites More sharing options...
Musashi Posted December 17, 2022 Share Posted December 17, 2022 (edited) 55 minutes ago, imdumb said: Do you have any idea First of all : Please do not post your code as graphics but as described here : how-to-post-code-on-the-forum Regarding the error handling : The MsgBox in your script only shows the @error of the second _ArrayDisplay command. Try something like this : ;[...] Local $aAIRL, $aTess5 ; Arrays to store the return from DllCall's $aAIRL = DllCall(...) MsgBox(0, 'Result : AIRL', @error & @CRLF) $aTess5 = DllCall(...) MsgBox(0, 'Result : $aTess5', @error & @CRLF) _ArrayDisplay($aAIRL) MsgBox (0, 'Array $aAIRL :', @error & @CRLF) _ArrayDisplay($aTess5) MsgBox (0, 'Array $aTess5 :', @error & @CRLF) ;[...] Edited December 17, 2022 by Musashi "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
imdumb Posted December 17, 2022 Author Share Posted December 17, 2022 Sorry for that , im new , FileChangeDir(@ScriptDir) $sDLL_Path = 'E:\Chung\OCRandRE\IRL64' $AIRL_Name = 'AIRL.dll' $IRL_Name = 'ImageRecognition.dll' _ArrayDisplay(DllCall('E:\Chung\OCRandRE\IRL64\AIRL.dll', 'handle:cdecl', 'AIRL_InitLibrary', 'wstr', $sDLL_Path, 'wstr', $IRL_Name),'AIRL.dll') MsgBox(0,'errocode',@error) _ArrayDisplay(DllCall('E:\Chung\OCRandRE\libtesseract-5.dll', 'handle:cdecl', 'TessBaseAPICreate'),'libtesseract') MsgBox(0,'errocode',@error) _ScriptRestart() No matter what , when i use DLLCALL both of this in one script , _ArrayDisplay(DllCall('E:\Chung\OCRandRE\libtesseract-5.dll', 'handle:cdecl', 'TessBaseAPICreate'),'libtesseract') alway return - 1 Link to comment Share on other sites More sharing options...
imdumb Posted December 17, 2022 Author Share Posted December 17, 2022 10 minutes ago, Musashi said: First of all : Please do not post your code as graphics but as described here : how-to-post-code-on-the-forum Regarding the error handling : The MsgBox in your script only shows the @error of the second _ArrayDisplay command. Try something like this : ;[...] Local $aAIRL, $aTess5 ; Arrays to store the return from DllCall's $aAIRL = DllCall(...) MsgBox(0, 'Result : AIRL', @error & @CRLF) $aTess5 = DllCall(...) MsgBox(0, 'Result : $aTess5', @error & @CRLF) _ArrayDisplay($aAIRL) MsgBox (0, 'Array $aAIRL :', @error & @CRLF) _ArrayDisplay($aTess5) MsgBox (0, 'Array $aTess5 :', @error & @CRLF) ;[...] when i change the position of DLLCALL to this FileChangeDir(@ScriptDir) $sDLL_Path = 'E:\Chung\OCRandRE\IRL64' $AIRL_Name = 'AIRL.dll' $IRL_Name = 'ImageRecognition.dll' _ArrayDisplay(DllCall('E:\Chung\OCRandRE\libtesseract-5.dll', 'handle:cdecl', 'TessBaseAPICreate'),'libtesseract') MsgBox(0,'errocode',@error) _ArrayDisplay(DllCall('E:\Chung\OCRandRE\IRL64\AIRL.dll', 'handle:cdecl', 'AIRL_InitLibrary', 'wstr', $sDLL_Path, 'wstr', $IRL_Name),'AIRL.dll') MsgBox(0,'errocode',@error) _ScriptRestart() Both DLLCALL work , but then script restart via _ScriptRestart() func , _ArrayDisplay(DllCall('E:\Chung\OCRandRE\libtesseract-5.dll', 'handle:cdecl', 'TessBaseAPICreate'),'libtesseract') error again Link to comment Share on other sites More sharing options...
Musashi Posted December 17, 2022 Share Posted December 17, 2022 Just now, imdumb said: Sorry for that , im new No problem, we were all beginners at some point. By the way : "Welcome to the forum" The error macro only returns the result of the last called function and it will be reset or overwritten by the next function call. Try this to find the problem : FileChangeDir(@ScriptDir) $sDLL_Path = 'E:\Chung\OCRandRE\IRL64' $AIRL_Name = 'AIRL.dll' $IRL_Name = 'ImageRecognition.dll' Local $aAIRL, $aTess5 ; Arrays to store the return from DllCall's $aAIRL = DllCall('E:\Chung\OCRandRE\IRL64\AIRL.dll', 'handle:cdecl', 'AIRL_InitLibrary', 'wstr', $sDLL_Path, 'wstr', $IRL_Name) MsgBox(0, 'Result : AIRL', @error & @CRLF) $aTess5 = DllCall('E:\Chung\OCRandRE\libtesseract-5.dll', 'handle:cdecl', 'TessBaseAPICreate') MsgBox(0, 'Result : $aTess5', @error & @CRLF) _ArrayDisplay($aAIRL) MsgBox (0, 'Array $aAIRL :', @error & @CRLF) _ArrayDisplay($aTess5) MsgBox (0, 'Array $aTess5 :', @error & @CRLF) _ScriptRestart() Hint : Instead of the MsgBox outputs you could also have a look at the ConsoleWrite function. "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." 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