Jump to content

jtredez

Members
  • Posts

    8
  • Joined

  • Last visited

Everything posted by jtredez

  1. I have found a usefull documentation on how to write DLL with MinGW (in case someone interested): http://www.transmissionzero.co.uk/computing/building-dlls-with-mingw/ http://www.transmissionzero.co.uk/computing/advanced-mingw-dll-topics/ MinGW doesn't have the same "name-decoration" as VisualC++ and need Definition file (thank wraithdu to point me on this) to solve this issue (see link #2 for explanation).
  2. Thank you, your answers helped me a lot. Just one more clarification for the question #2: Now I understand why I have this "name-decoration". If I compile my DLL by declaring the function with __stdcall, when I call the function in autoit I need to do it like this: $result = DllCall($hDll, "int","addition@8", "int",3, "int",7) The default call convention on autoit is __stdcall, so I assumes I doesn't need to put the "name-decoration" to find this function, but it's not the case.I would like to write it like this (without the :cdecl and without the @8): $result = DllCall($hDll, "int","addition", "int",3, "int",7)
  3. Hello, I would like to develop a DLL for autoit but I have some questions. I use Autoit 3.3.9.0beta and codeblock with mingw for the DLL part. I have the DLL, a external program developped in C to test this DLL and an autoit program to test this DLL. The DLL have only one function: addition to add two integer and return the result. This is part of my source code (I put the full project in attachment): int DLL_EXPORT addition(int integer1, int integer2) { return integer1 + integer2; } #define DLL_EXPORT __declspec(dllexport) #ifdef __cplusplus extern "C" { #endif int DLL_EXPORT addition(int integer1, int integer2); #ifdef __cplusplus } #endif local $hDll = DllOpen("LibTest.dll") $result = DllCall($hDll, "int:cdecl","addition", "int",3, "int",7) MsgBox(4096, "In AutoIt", "3 + 7 = " & $result & @CRLF & "error = " & @error) DllClose($hDll) ExitThe returned value on my DLL function is correct (=10) with my C test program but not in autoit (=0). The parameters is correctly passed to the DLL in both case (I display it in the DLL with a msgbox). I have tested with __stdcall and without. What is wrong with my code?When I use the __stdcall version, my DLL function name change to addition@8, why this? and how to avoid this? (sorry I not realy familiar with DLL development).I would like to call an autoit function in my DLL. I suppose I need to use the DllCallbackRegister to get a pointer on my autoit function and to pass it to a function in my DLL, like what it’s done in the Example of DllCallbackRegister with EnumWindows. But in my DLL how I call this pointer? Does I need a specific mechanism or I can call it like another C function pointer? And how to pass parameters to the autoit callback function and eventualy get a return value?Thank you for your help.dll.zip
  4. Hi Martin, Sometime I have a popup window with title=Autoit3.exe and message=Timeout. I doesn't have this message in my program, is it in the library? Thank you
  5. Hi Martin, Finaly I got some error with the last version (2.84). I send a string to the serial port with _CommSendString("message", 1) and wait the answer with $received = _CommGetLine(@LF, 100, 5000). On the last version I doesn't receive anything, so I check what's wrong and found it works if I put in comment the end of _CommReadByte function like this : #cs if StringLen($vDllAns[0]) > 1 then Return seterror(1,0,$vDllAns[0]) EndIf #ce I don't see why you return an error if the len of the received string >1 (not present in the previous version) but without this it works. Also I add "#include-once" at the first line of the file to avoid problem when used in my project (two different drivers that use the commg driver). Just to informe you, I use the new _ComGetPortNames function (not present in the list of start of file) and it works fine. Jerome
  6. Thank you martin, now it works perfectly, I receive the timeout notification and it doesn't crash anymore.
  7. To temporarily solve my crash, I have change the code for the function _CommReadByte to this: Func _CommReadByte($wait = 0) Local $iCount, $vDllAns If Not $fPortOpen Then SetError(1) Return 0 EndIf If Not $wait Then $iCount = _CommGetInputCount() If $iCount = 0 Then SetError(1) Return '' EndIf ;Patch for crash timeout ;EndIf else local $time = TimerInit() do $iCount = _CommGetInputCount() until (TimerDiff($time) >= $timeOut) OR ($iCount > 0) if ($iCount = 0) then SetError(1) Return '' EndIf EndIf ;End patch $vDllAns = DllCall($hDll, 'str', 'GetByte') If @error <> 0 Then SetError(2) Return '' EndIf ;mgdebugCW('byte read was ' & $vDllAns[0] & @CRLF) Return $vDllAns[0] EndFunc ;==>_CommReadByte And add a global variable (Global $timeOut = 0) to store the timeout set in function _CommSetTimeouts
  8. Hi, I use the commg to communicate with a device, but when I want to use the timeout functionality, it crash when the timeout come. The windows (Windows XP pro SP3) report crash is: AppName: autoit3.exe AppVer: 3.3.7.14 ModName: kernel32.dll MpdVer: 5.1.2600.5781 Offset: 00012afb And the crash is in function _CommReadByte inside the call of the DLL. A simple program to test: #include <CommMG.au3> const $iTimeOut = 10000 Local $sportSetError = "" local $char local $log = FileOpen("Log.txt", 1) FileWrite($log, "App Start" & @CRLF) _CommSetPort(1, $sportSetError, 9600, 8, 0, 1, 2) if $sportSetError = "" then FileWrite($log, "COM1 open" & @CRLF) _CommSetTimeouts($iTimeOut, $iTimeOut, 0, $iTimeOut, 0) else FileWrite($log, "Error opening COM1" & @CRLF) endif do $char = _CommReadByte(1) ; Crash if set to 1 but doesn't if set to 0 if $char = "" then if @error > 1 then FileWrite($log, "E" & @error & "E") endif else FileWrite($log, $char) endif until $char = 13 ; @CR to end _CommClosePort() FileWrite($log, "App Stop" & @CRLF) How can I solve this? Thank you.
×
×
  • Create New...