bittware Posted July 11, 2010 Share Posted July 11, 2010 Hello experts, I am trying to use DllCall to call one function in my Dll file. But every time the script runs to DllCall it crashes. I used both windows 7 and xp, but same thing happens. The AutoIt syntax is: DllCall("D:\scripts\sub20.dll", "prt", "usb_find_devices", "prt", 0) And the original C function prototype is typedef void* sub_device; sub_device sub_find_devices( sub_device first ); I can't figure out what is wrong. It may be something stupid in there... Thanks for your attention.BRs,bittware Link to comment Share on other sites More sharing options...
Authenticity Posted July 11, 2010 Share Posted July 11, 2010 Read the help file about the default calling method that is used by DllCall. If your compiler's default calling convention is __cdecl then you should tell notify DllCall about it as well. By the way, it's ptr not prt but it wasn't the reason for the crash, just posting typo. Link to comment Share on other sites More sharing options...
MvGulik Posted July 11, 2010 Share Posted July 11, 2010 Could be for the same reason when I had a dll call that kept crashing on me. This was because I was using a "type" while I should have been using "type*" "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 Hello,Yes, that should be "prt". "ptr" is typo.I just tried both calling conventionDllCall("D:\scripts\sub20.dll", "prt:stdcall", "usb_find_devices", "prt:stdcall", 0)DllCall("D:\scripts\sub20.dll", "prt:cdecl", "usb_find_devices", "prt:cdecl", 0)But crashing as always...Might it be the problem of AutoIt compiler setting? When I complie my script in SciTE it promptsStarting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0804 Keyboard:00000804 OS:WIN_7/ CPU:X64 OS:X86)I was wondering if CPU:X64 OS:X86 has something to do complier setting.BRs,bittware Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 Hello,Yes, that should be "prt". "ptr" is typo.I just tried both calling conventionDllCall("D:\scripts\sub20.dll", "prt:stdcall", "usb_find_devices", "prt:stdcall", 0)DllCall("D:\scripts\sub20.dll", "prt:cdecl", "usb_find_devices", "prt:cdecl", 0)But crashing as always...Might it be the problem of AutoIt compiler setting? When I complie my script in SciTE it promptsStarting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0804 Keyboard:00000804 OS:WIN_7/ CPU:X64 OS:X86)I was wondering if CPU:X64 OS:X86 has something to do with complier setting.BRs,bittware Link to comment Share on other sites More sharing options...
Authenticity Posted July 11, 2010 Share Posted July 11, 2010 lol prt is the typo. It should be ptr. You need to specify the calling convention in the function return value -only-.Local $aResult = DllCall("MyLib.dll", "int:cdecl", "Add", "int", 4, "int", 5) If @error Then Return SetError(@error, @extended, 0) Return $aResult[0] ;...Also, you should provide a bit more information about the function description. Does the function require the data to be already allocated by user? If it's a generic object pointer allocated and maintained internally by the function, it should be like:Func _MyFunc(ByRef $OutPtr) ; On success, $aResult[1] points to an opaque pointer. Local $aResult = DllCall("MyLib.dll", "int:cdecl", "MyFunc", "ptr*", 0) If @error Then Return SetError(@error, @extended, 0) $OutPtr = $aResult[1] Return $aResult[0] EndFunc ;...In general, "type" in DllCall means pass without reference, "type*" means pass by reference. Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 Sorry for the mistake...But even DllCall("D:\scripts\sub20.dll", "prt:cdecl", "usb_find_devices", "prt:cdecl", 0) can still be successfully compiled. It's weird.I am meant to pass the pointer itself to the called function, not the pointer of pointer, so it should look like thisDllCall("D:\scripts\sub20.dll", "ptr:cdecl", "usb_find_devices", "ptr", 0)But this also crashes.Is there any possibility I can trace the root cause of such crash. Can any useful debug tool do some help? Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 (edited) DllCall("D:\scripts\sub20.dll", "ptr:cdecl", "usb_find_devices", "ptr*", 0)DllCall("D:\scripts\sub20.dll", "ptr*:cdecl", "usb_find_devices", "ptr*", 0)DllCall("D:\scripts\sub20.dll", "ptr:cdecl", "usb_find_devices", "ptr", 0)DllCall("D:\scripts\sub20.dll", "ptr*:cdecl", "usb_find_devices", "ptr", 0)DllCall("D:\scripts\sub20.dll", "ptr", "usb_find_devices", "ptr*", 0)DllCall("D:\scripts\sub20.dll", "ptr*", "usb_find_devices", "ptr*", 0)DllCall("D:\scripts\sub20.dll", "ptr", "usb_find_devices", "ptr", 0)DllCall("D:\scripts\sub20.dll", "ptr*", "usb_find_devices", "ptr", 0)I tried all possible combinations. They all crash.In this DLL user manual, it says2.1.1 sub_find_devicesSynopsissub_device sub_find_devices( sub_device first )Function scans USB devices currently connected to the host looking for SUB-20 device(s). If parameter first isNULL function will initiate new search, otherwise it will continue to search from the place it finished during lastcall.Return valueFunction returns next found SUB-20 device descriptor or NULL if no more devices were found. Returned valuecan be used as parameter for sub_open. Device descriptor is not a device handle required by API calls. Handleis returned by sub_open.Examplesub_device dev=0;while( dev = sub_find_devices(dev) ){/* Check device serial number */} Edited July 11, 2010 by bittware Link to comment Share on other sites More sharing options...
Authenticity Posted July 11, 2010 Share Posted July 11, 2010 Strange. Care to run the following script and post the console output? #include <Constants.au3> #include <WinAPI.au3> Local $hDll = DllOpen("D:\scripts\sub20.dll") ConsoleWrite("Dll: " & $hDll & ", error: " & @error & @CRLF) If $hDll Then DllClose($hDll) Local $hLib = _WinAPI_LoadLibraryEx("D:\scripts\sub20.dll", $DONT_RESOLVE_DLL_REFERENCES) ConsoleWrite("Dll: " & $hLib & ", error: " & @error & ", winerror: " & _WinAPI_GetLastErrorMessage()) Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 The console output is>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "D:\scripts\dllcall.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>17:14:42 Starting AutoIt3Wrapper v.2.0.1.24 Environment(Language:0804 Keyboard:00000804 OS:WIN_7/ CPU:X64 OS:X86)>Running AU3Check (1.54.19.0) from:C:\Program Files\AutoIt3+>17:14:43 AU3Check ended.rc:0>Running:(3.3.6.1):C:\Program Files\AutoIt3\autoit3.exe "D:\scripts\dllcall.au3" Dll: 1, error: 0Dll: 0x10000000, error: 0, winerror: 操作成功完成。汬??潃獮汯坥+>17:14:43 AutoIT3.exe ended.rc:0>Exit code: 0 Time: 2.447Sorry for the embedded chinese charaters. In fact, it just says the operation is well done.I also attached the definition head file and sub20.dll. Please take a look. Very appreciate your help.libsub.hsub20.dll Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 (edited) I also dumpped out all the functions inside sub20.dll by using DLL Export Viewer. It looks like this expandcollapse popup================================================== Function Name : DllMain Address : 0x10002b90 Relative Address : 0x00002b90 Ordinal : 1 (0x1) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_adc_config Address : 0x100020d0 Relative Address : 0x000020d0 Ordinal : 2 (0x2) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_adc_read Address : 0x10002140 Relative Address : 0x00002140 Ordinal : 3 (0x3) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_adc_single Address : 0x10002120 Relative Address : 0x00002120 Ordinal : 4 (0x4) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_close Address : 0x100010f0 Relative Address : 0x000010f0 Ordinal : 5 (0x5) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_control_request Address : 0x10002980 Relative Address : 0x00002980 Ordinal : 6 (0x6) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_errno Address : 0x1001d4d8 Relative Address : 0x0001d4d8 Ordinal : 7 (0x7) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_fifo_config Address : 0x10002670 Relative Address : 0x00002670 Ordinal : 8 (0x8) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_fifo_read Address : 0x10002520 Relative Address : 0x00002520 Ordinal : 9 (0x9) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_fifo_write Address : 0x10002470 Relative Address : 0x00002470 Ordinal : 10 (0xa) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_find_devices Address : 0x10001000 Relative Address : 0x00001000 Ordinal : 11 (0xb) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_fpwm_config Address : 0x10001db0 Relative Address : 0x00001db0 Ordinal : 12 (0xc) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_fpwm_set Address : 0x10001f00 Relative Address : 0x00001f00 Ordinal : 13 (0xd) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_get_cfg_vpd Address : 0x10001250 Relative Address : 0x00001250 Ordinal : 14 (0xe) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_get_mode Address : 0x10001120 Relative Address : 0x00001120 Ordinal : 15 (0xf) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_get_product_id Address : 0x100029e0 Relative Address : 0x000029e0 Ordinal : 16 (0x10) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_get_serial_number Address : 0x100029c0 Relative Address : 0x000029c0 Ordinal : 17 (0x11) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_get_version Address : 0x10001170 Relative Address : 0x00001170 Ordinal : 18 (0x12) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_gpio_config Address : 0x10001c10 Relative Address : 0x00001c10 Ordinal : 19 (0x13) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_gpio_read Address : 0x10001cb0 Relative Address : 0x00001cb0 Ordinal : 20 (0x14) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_gpio_write Address : 0x10001d10 Relative Address : 0x00001d10 Ordinal : 21 (0x15) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_config Address : 0x100013f0 Relative Address : 0x000013f0 Ordinal : 22 (0x16) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_freq Address : 0x100012d0 Relative Address : 0x000012d0 Ordinal : 23 (0x17) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_read Address : 0x10001540 Relative Address : 0x00001540 Ordinal : 24 (0x18) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_scan Address : 0x100014e0 Relative Address : 0x000014e0 Ordinal : 25 (0x19) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_start Address : 0x10001440 Relative Address : 0x00001440 Ordinal : 26 (0x1a) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_status Address : 0x1001d4d4 Relative Address : 0x0001d4d4 Ordinal : 27 (0x1b) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_stop Address : 0x10001490 Relative Address : 0x00001490 Ordinal : 28 (0x1c) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_i2c_write Address : 0x10001660 Relative Address : 0x00001660 Ordinal : 29 (0x1d) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_lcd_write Address : 0x10002210 Relative Address : 0x00002210 Ordinal : 30 (0x1e) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_mdio22 Address : 0x10001a80 Relative Address : 0x00001a80 Ordinal : 31 (0x1f) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_mdio45 Address : 0x10001ae0 Relative Address : 0x00001ae0 Ordinal : 32 (0x20) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_mdio_xfer Address : 0x10001b30 Relative Address : 0x00001b30 Ordinal : 33 (0x21) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_open Address : 0x100010c0 Relative Address : 0x000010c0 Ordinal : 34 (0x22) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_pwm_config Address : 0x10001f90 Relative Address : 0x00001f90 Ordinal : 35 (0x23) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_pwm_set Address : 0x10002070 Relative Address : 0x00002070 Ordinal : 36 (0x24) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_rs_get_config Address : 0x100022f0 Relative Address : 0x000022f0 Ordinal : 37 (0x25) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_rs_set_config Address : 0x10002280 Relative Address : 0x00002280 Ordinal : 38 (0x26) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_rs_timing Address : 0x10002370 Relative Address : 0x00002370 Ordinal : 39 (0x27) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_rs_xfer Address : 0x100023f0 Relative Address : 0x000023f0 Ordinal : 40 (0x28) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_sdio_transfer Address : 0x100019e0 Relative Address : 0x000019e0 Ordinal : 41 (0x29) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_set_debug_level Address : 0x10002ae0 Relative Address : 0x00002ae0 Ordinal : 42 (0x2a) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_spi_config Address : 0x10001780 Relative Address : 0x00001780 Ordinal : 43 (0x2b) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_spi_transfer Address : 0x100017e0 Relative Address : 0x000017e0 Ordinal : 44 (0x2c) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : sub_strerror Address : 0x10002950 Relative Address : 0x00002950 Ordinal : 45 (0x2d) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== ================================================== Function Name : usb_transaction Address : 0x10002750 Relative Address : 0x00002750 Ordinal : 46 (0x2e) Filename : sub20.dll Full Path : D:\scripts\sub20.dll Type : Exported Function ================================================== Edited July 11, 2010 by SmOke_N Link to comment Share on other sites More sharing options...
trancexx Posted July 11, 2010 Share Posted July 11, 2010 (edited) You have dyslexia? #AutoIt3Wrapper_UseX64=n Local $hDll = DllOpen("D:\scripts\sub20.dll") DllCall($hDll, "ptr:cdecl", "sub_find_devices", "ptr", 0) ConsoleWrite("! " & @error & @CRLF) ; ...close handle edit: added DllOpen - seems crucial Edited July 11, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 You have dyslexia? #AutoIt3Wrapper_UseX64=n Local $hDll = DllOpen("D:\scripts\sub20.dll") DllCall($hDll, "ptr:cdecl", "sub_find_devices", "ptr", 0) ConsoleWrite("! " & @error & @CRLF) ; ...close handle edit: added DllOpen - seems crucial I didn't get your point. Does DllOpen have something to do with this problem? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 11, 2010 Moderators Share Posted July 11, 2010 bittware,What trancexx is pointing out in her normal inimitable fashion is that you have been using:usb_find_devicesthroughout, whereas the function in that huge list you posted issub_find_devicesAdd that to the ptr/prt confusion earlier and I feel she has a point! M23P.S. The next time you post a list as long as that, please put it in [code ] [/code ] tags so that it appears in a scrollable box. Just leave out the trailing spaces - there are only there so the tags appear here. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bittware Posted July 11, 2010 Author Share Posted July 11, 2010 OMG, I made such a stupid mistake. Thank you, all you warm hearted guys. This is my very first post, but I learned a lot. Thank you. 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