
tehhahn
Members-
Posts
11 -
Joined
-
Last visited
About tehhahn
- Birthday 09/28/1985
Profile Information
-
Location
Germany
tehhahn's Achievements

Seeker (1/7)
0
Reputation
-
Hi everybody, I'm dealing with C functions exported in a dynamic link library at the moment. For that, I've implemented a simple Stack in C. Im already able to call functions, so building the .dll file and accessing its functions is not a problem for me. The problem is the AutoIt function DllStructCreate. I do not know how to create nested structures in AutoIt. I have the following implemented in C: stack.h #ifndef STACK_H #define STACK_H typedef int stackDataType; typedef struct stack { stackDataType vValue; struct stack *pNext; } SStack; #ifdef __cplusplus extern "C" { #endif #ifndef DLL_TEST #define DLL_DECLARE __declspec(dllexport) #endif DLL_DECLARE void dll_check(); DLL_DECLARE stackDataType pop(SStack **head); DLL_DECLARE void push(SStack **head, stackDataType vValue); #ifdef __cplusplus } #endif #endif stack.c (not really relevant) #include <stdbool.h> #include <stdlib.h> #include <stdio.h> #include "stack.h" void dll_check() { printf("Works"); } stackDataType pop(SStack **head) { SStack *pTop = *head; stackDataType vValue = pTop->vValue; *head = pTop->pNext; free(pTop); return vValue; } void push(SStack **head, stackDataType vValue) { SStack *pNode = malloc( sizeof(SStack) ); pNode->vValue = vValue; pNode->pNext = *head; *head = pNode; } And last, but not least the CppStack.au3: #include-once Exit Main() Func Main() Local Const $hDLL = _StackCpp_Startup() MsgBox(64, "_StackCpp_Startup", @error) _StackCpp_Check($hDLL) MsgBox(64, "_StackCpp_Check", @error) _StackCpp_Push($hDLL, 1) MsgBox(64, "_StackCpp_Push", @error) _StackCpp_Shutdown($hDLL) EndFunc ;==>Main Func _StackCpp_Startup($sFile = Default) Local $h = 0 If $sFile = Default Then $sFile = @ScriptDir & "\libCppStack.dll" $h = DllOpen($sFile) If $h = -1 Then Return SetError(1, 0, False) Return $h EndFunc ;==>_StackCpp_Startup Func _StackCpp_Shutdown(ByRef Const $h) DllClose($h) EndFunc ;==>_StackCpp_Shutdown ;~ Works... Func _StackCpp_Check(ByRef Const $h) DllCall($h, "none", "dll_check") If @error Then Return SetError(@error, 0, False) Return True EndFunc ;==>_StackCpp_Check ;~ Does not work since the DllCall call fails with a runtime error... Func _StackCpp_Push(ByRef Const $h, Const $V) Local Const $SSTACK = DllStructCreate("int;int") DllCall($h, "none", "push", "ptr", DllStructGetPtr($SSTACK), "int", $V) If @error Then Return SetError(@error, 0, False) Return True EndFunc ;==>_StackCpp_Push My problem is to deal with the following two lines, since the second datatype in the structure is the structure itself. Local Const $SSTACK = DllStructCreate("int;int") DllCall($h, "none", "push", "ptr", DllStructGetPtr($SSTACK), "int", $V) Can somebody explain me, how to realize that nested structure in AutoIt? I've added the project (NetBeans IDE) to the appendix! Thanks! CppStack.zip
-
MySQL ODBC Connection under Vista x64
tehhahn replied to tehhahn's topic in AutoIt General Help and Support
*push* (Sorry for that, but I must solve this problem!) See above: EDIT 1 and EDIT 2! -
MySQL ODBC Connection under Vista x64
tehhahn replied to tehhahn's topic in AutoIt General Help and Support
I wrote this function... I cannot reach the URL with the recent version of the MySQL UDFs, but this should work, because it does under Windows XP x86... The root user I am connecting with also has access from the host localhost. EDIT 1: What I am wondering about is, I've installed both the old and new version of the MySQL ODBC driver for x64, but the drivers are only listed under C:\Windows\System32\odbcad32.exe and not under C:\Windows\SysWOW64\odbcad32.exe where they should be listed in my understanding! From the odbcad32.exe under System32 I can connect to the database without problems with both drivers! I certainly do not know what to do to solve this problem. Does anyone have Vista x64 and a running MySQL server who can test it? Also, does someone has the recent verson of the UDFs mentioned above and can post it here? EDIT 2: Below is a screenshot of the error message (with enabled ErrorHandling) and the ODBC Windows Dialog in German language (sorry for that). I just checked the link under Administrative tools that links to C:\Windows\System32\odbcad32.exe, so I think that should be ok... -
MySQL ODBC Connection under Vista x64
tehhahn replied to tehhahn's topic in AutoIt General Help and Support
Oh, i forgot to mention. I am using both the x64 ODBC drivers. Is seems that the connection string is not working or has to be changed, but I did not find anything about it on the Internet. -
Hello everybody, I wanted to run an old script of me under Vista 64Bit, that required MySQL ODBC support to run. I successfully installed the MySQL ODBC driver (I tried version 3.51.26 AND version 5.1!) and I am also able to create a connection with the MySQL Connector GUI. But when I try to create a connection from my script I always run into an error with the ADODB-Open method, saying the DSN does not exist or the driver is not installed. Here is my Connection function: Func _MySQLConnect(Const $S_USERNAME, Const $S_PASSWORD, Const $S_SERVER, Const $S_DATABASE, _ Const $I_PORT = 3306, Const $I_OPTION = 0, Const $S_DRIVER = "{MySQL ODBC 3.51 Driver}", Const $F_X64 = False) Local $s_key = "HKLM" If $F_X64 Then $s_key &= "64" $s_key &= "\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers" Local Const $S_VAL = RegRead($s_key, StringMid($S_DRIVER, 2, StringLen($S_DRIVER) - 2)) If @error Or Not $S_VAL Then Return SetError(2, 0, 0) Local $o_adodb = ObjCreate("ADODB.Connection") If @error Then SetError(3, 0, 0) Local Const $S_CONN = "DRIVER=" & $S_DRIVER & _ ";SERVER=" & $S_SERVER & _ ";PORT=" & $I_PORT & _ ";DATABASE=" & $S_DATABASE & _ ";UID=" & $S_USERNAME & _ ";PWD=" & $S_PASSWORD & _ ";OPTION=" & $I_OPTION & ";" $o_adodb.ConnectionString = $S_CONN ConsoleWrite($S_CONN & @CRLF) $o_adodb.Open If @error Then Return SetError(1, 0, 0) Return $o_adodb EndFunc ;==>_MySQLConnectoÝ÷ Ø ÝêÞɲ~éܶ*'q©ejëh×6$o_mysql = _MySQLConnect($s_mysqlusername, $s_mysqlpassword, $s_mysqlserver, $s_mysqldatabase, $i_mysqlport, 0, "{MySQL ODBC 3.51 Driver}", true) MsgBox(64, "_MySQLConnect", @error) This worked fine under Windows XP x86, but under Vista x64 it always crashes (enable ErrorHandling for detailed error description!). Does any one know how to solve this problem? Has the connection string to be changed or what is going on?
-
MD5,SHA1,CRC32,RC4,BASE64,XXTEA machine code version
tehhahn replied to Ward's topic in AutoIt Example Scripts
Great functions, Ward! Thank you very much! I have one question: The Base64 and the RC4 functions do return the same hashes. I am not an expert and do not have very much knowledge about cryptography, but is that correct? Do Base64 and RC4 base on the same algorithm, or what? Some more algorithms you (maybe) want to implement: "MD2", "MD4", "SHA256", "SHA384", "SHA512", "HAVAL128", "HAVAL160", "HAVAL192", "HAVAL224", "HAVAL256", "GHOST", "TIGER128", "TIGER160", "TIGER192", "RIPE-MD128", "RIPE-MD160", "CRC16", "ARC-CRC" -
Hi, why so complicated, three LOC are enough for this: 1. It makes no sense to check for a blank string ("") for $S_FILE, FileExists is enough! 2. To check if $S_RENAME is blank, is not enough! RegExp does the job. 3. One goal of UDFs should be to use no includes (One line does it all!). ToDo: Retrieving all possible error codes for "rename" and handle them in the UDF. ;=============================================================================== ; Function Name.....: _FileRename ; Description.......: Renames a file using the command "rename". ; Version...........: 1.0.4 ; Change Date.......: 2008-07-29 ; AutoIt Version....: 3.2.12.1 ; ; Parameter(s)......: $S_FILE - String containing the directory or file to rename. ; $S_RENAME - String containing the new name of the file, without the path. ; Requirements(s)...: None ; Return Value(s)...: Success: Returns the exit code of the "rename" command. ; Failure: Returns 0 and sets @error to: ; 1 = The file or folder $S_FILE does not exist. ; 2 = $S_RENAME is an invalid filename. ; ; Author(s).........: xVivoCity ; Modified by: JellyFish666 & litlmike ; Modified by: teh_hahn <sPiTsHiT@gmx.de> ; Company...........: None ; URL...............: None ; Note(s)...........: None ;=============================================================================== Func _FileRename(Const $S_FILE, Const $S_RENAME) If Not FileExists($S_FILE) Then Return SetError(1, 0, 0) If Not StringRegExp($S_RENAME, '(?i)^[^<>\?":\|\\/\*]+$') Then Return SetError(2, 0, 0) Return RunWait(@ComSpec & ' /c ren "' & $S_FILE & '" "' & $S_RENAME & '"', "", @SW_HIDE) EndFunc ;==>_FileRename
-
Hi, I think this UDF is very useful, but there were a few glitches within the code. I fixed them and this is the result:
-
Hi again, sorry I did not reply earlier but I was at the Cebit fair yesterday. I checked the syntax for WQL and of course you're right. The correct query is: SELECT Antecedent FROM Win32_LogicalDiskToPartition WHERE Dependent = '\\\\AS106789\\root\\cimv2:Win32_LogicalDisk.DeviceID="C:"' But the FDD is still checked! Is there any other possibility to retrieve the PNPDeviceID from the drive letter?
-
Thank you ptrex! Here is my code (but the problem exists in all scripts in this thread!). It does not differs from the two scripts posted here! #include <Array.au3> Global Const $wbemFlagReturnImmediately = 0x10 Global Const $wbemFlagForwardOnly = 0x20 Global Const $strComputer = "." Global Const $S_DRIVE = "C:" Global $as_smart = _GetSmartData($S_DRIVE) If $as_smart <> -1 Then _ArrayDisplay($as_smart, "S.M.A.R.T. Data for Drive " & $S_DRIVE) Else MsgBox(64, "Please note", $S_DRIVE & " may not be S.M.A.R.T. capable!") EndIf Func _GetSmartData($vDrive = "C:") If DriveStatus($vDrive) = "INVALID" Then Return SetError(1, 0, -1) Local $iCnt, $iCheck, $vPartition, $vDeviceID, $vPNPID, $objWMIService, $oDict Local $strReserved, $strVendorSpecific, $strVendorSpecific4, $Output If StringLeft($vDrive, 1) <> '"' Then $vDrive = '"' & $vDrive If StringRight($vDrive, 1) <> '"' Then $vDrive &= '"' MsgBox(64, "Debug", "Still OK.") $vPartition = _LogicalToPartition($vDrive) MsgBox(16, "Debug", "FDD was checked!") If $vPartition = -1 Then Return -1 $vDeviceID = _PartitionToPhysicalDriveID($vPartition) If $vDeviceID = -1 Then Return -1 $vPNPID = _PNPIDFromPhysicalDriveID($vDeviceID) If $vPNPID = -1 Then Return -1 $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\WMI") $colItems1 = $objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_ATAPISmartData", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colItems2 = $objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictThresholds", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $colItems3 = $objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictStatus", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) $iCnt = 1 For $objItem In $colItems1 If StringLeft($objItem.InstanceName, StringLen($vPNPID)) = String($vPNPID) Then $strReserved = $objItem.Reserved $strVendorSpecific = $objItem.VendorSpecific $strVendorSpecific4 = $objItem.VendorSpecific4 Else $iCnt += 1 EndIf Next $iCheck = 1 For $objItem In $colItems2 If $iCheck = $iCnt Then $strVendorSpecific2 = $objItem.VendorSpecific Else $iCheck += 1 EndIf Next $iCheck = 1 For $objItem In $colItems3 If $iCheck = $iCnt Then $strVendorSpecific3 = $objItem.PredictFailure $strVendorSpecific3 = $objItem.Reason Else $iCheck += 1 EndIf Next If Not IsArray($strVendorSpecific4) Then Return -1 If Not IsArray($strVendorSpecific2) Then Return -1 $oDict = ObjCreate("Scripting.Dictionary") _CreateDict($oDict) Local $Status[22] For $i = 1 To 21 $Status[$i] = "Not OK" Next If $strVendorSpecific[5] >= $strVendorSpecific2[3] Then $Status[1] = "OK" If $strVendorSpecific[17] >= $strVendorSpecific2[15] Then $Status[2] = "OK" If $strVendorSpecific[29] >= $strVendorSpecific2[27] Then $Status[3] = "OK" If $strVendorSpecific[41] >= $strVendorSpecific2[39] Then $Status[4] = "OK" If $strVendorSpecific[53] >= $strVendorSpecific2[51] Then $Status[5] = "OK" If $strVendorSpecific[65] >= $strVendorSpecific2[63] Then $Status[6] = "OK" If $strVendorSpecific[77] >= $strVendorSpecific2[75] Then $Status[7] = "OK" If $strVendorSpecific[89] >= $strVendorSpecific2[87] Then $Status[8] = "OK" If $strVendorSpecific[101] >= $strVendorSpecific2[99] Then $Status[9] = "OK" If $strVendorSpecific[113] >= $strVendorSpecific2[111] Then $Status[10] = "OK" If $strVendorSpecific[125] >= $strVendorSpecific2[123] Then $Status[11] = "OK" If $strVendorSpecific[137] >= $strVendorSpecific2[135] Then $Status[12] = "OK" If $strVendorSpecific[149] >= $strVendorSpecific2[147] Then $Status[13] = "OK" If $strVendorSpecific[161] >= $strVendorSpecific2[159] Then $Status[14] = "OK" If $strVendorSpecific[173] >= $strVendorSpecific2[171] Then $Status[15] = "OK" If $strVendorSpecific[185] >= $strVendorSpecific2[183] Then $Status[16] = "OK" If $strVendorSpecific[197] >= $strVendorSpecific2[195] Then $Status[17] = "OK" If $strVendorSpecific[206] >= $strVendorSpecific2[204] Then $Status[18] = "OK" If $strVendorSpecific[218] >= $strVendorSpecific2[216] Then $Status[19] = "OK" If $strVendorSpecific[230] >= $strVendorSpecific2[228] Then $Status[20] = "OK" If $strVendorSpecific[242] >= $strVendorSpecific2[240] Then $Status[21] = "OK" Local $aSmartData[1][8] = [["ID", "Attribute", "Type", "Flag", "Threshold", "Value", "Worst", "Status"]] $iCnt = 1 For $x = 2 To 242 Step 12 If $strVendorSpecific[$x] <> 0 Then ;0 id is not valid for this Smart Device $NextRow = UBound($aSmartData) ReDim $aSmartData[$NextRow + 1][8] $aSmartData[$NextRow][0] = $strVendorSpecific[$x];ID $aSmartData[$NextRow][1] = $oDict.Item($strVendorSpecific[$x]);Attribute If $aSmartData[$NextRow][1] = "" Then $aSmartData[$NextRow][1] = "Unknown SMART Attribute" If Mod($strVendorSpecific[$x + 1], 2) Then ;Type If odd number then it is a pre-failure value $aSmartData[$NextRow][2] = "Pre-Failure" Else $aSmartData[$NextRow][2] = "Advisory" EndIf $aSmartData[$NextRow][3] = $strVendorSpecific[$x + 1];Flag $aSmartData[$NextRow][4] = $strVendorSpecific2[$x + 1];Threshold $aSmartData[$NextRow][5] = $strVendorSpecific[$x + 3];Value $aSmartData[$NextRow][6] = $strVendorSpecific[$x + 4];Worst $aSmartData[$NextRow][7] = $Status[$iCnt];Status EndIf $iCnt += 1 Next Return $aSmartData EndFunc ;==>_GetSmartData Func _PartitionToPhysicalDriveID($vPart) Local $objWMIService, $colItems $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDriveToDiskPartition", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If $objItem.Dependent = $vPart Then $vPdisk = $objItem.Antecedent Return StringReplace(StringReplace(StringTrimLeft($vPdisk, StringInStr($vPdisk, "=")), '"', ""), "\\", "\") EndIf Next EndIf Return -1 EndFunc ;==>_PartitionToPhysicalDriveID Func _PNPIDFromPhysicalDriveID($vDriveID) Local $objWMIService, $colItems $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If $objItem.DeviceID = $vDriveID Then Return $objItem.PNPDeviceID Next EndIf Return -1 EndFunc ;==>_PNPIDFromPhysicalDriveID Func _LogicalToPartition($vDriveLet) Local $objWMIService, $colItems $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT Dependent,Antecedent FROM Win32_LogicalDiskToPartition", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems If StringRight($objItem.Dependent, 4) = $vDriveLet Then Return $objItem.Antecedent Next EndIf Return -1 EndFunc ;==>_LogicalToPartition Func _CreateDict(ByRef $oDict) $oDict.Add(1, "Read Error Rate") $oDict.Add(2, "Throughput Performance") $oDict.Add(3, "Spin-Up Time") $oDict.Add(4, "Start/Stop Count") $oDict.Add(5, "Reallocated Sectors Count") $oDict.Add(6, "Read Channel Margin") $oDict.Add(7, "Seek Error Rate Rate") $oDict.Add(8, "Seek Time Performance") $oDict.Add(9, "Power-On Hours (POH)") $oDict.Add(10, "Spin Retry Count") $oDict.Add(11, "Recalibration Retries") $oDict.Add(12, "Device Power Cycle Count") $oDict.Add(13, "Soft Read Error Rate") $oDict.Add(191, "G-Sense Error Rate Frequency") $oDict.Add(192, "Power-Off Park Count") $oDict.Add(193, "Load/Unload Cycle") $oDict.Add(194, "HDA Temperature") $oDict.Add(195, "ECC Corrected Count") $oDict.Add(196, "Reallocated Event Count") $oDict.Add(197, "Current Pending Sector Count") $oDict.Add(198, "Uncorrectable Sector Count") $oDict.Add(199, "UltraDMA CRC Error Count") $oDict.Add(200, "Write Error Rate") $oDict.Add(201, "Soft Read Error Rate") $oDict.Add(202, "Address Mark Errors Frequency") $oDict.Add(203, "ECC errors (Maxtor: ECC Errors)") $oDict.Add(204, "Soft ECC Correction") $oDict.Add(205, "Thermal Asperity Rate (TAR)") $oDict.Add(206, "Flying Height") $oDict.Add(207, "Spin High Current") $oDict.Add(208, "Spin Buzz") $oDict.Add(209, "Offline Seek") $oDict.Add(220, "Disk Shift") $oDict.Add(221, "G-Sense Error Rate") $oDict.Add(222, "Loaded Hours") $oDict.Add(223, "Load/Unload Retry Count") $oDict.Add(224, "Load Friction") $oDict.Add(225, "/Unload Cycle Count") $oDict.Add(226, "Load 'In'-time") $oDict.Add(227, "Torque Amplification Count") $oDict.Add(228, "Power-Off Retract Cycle") $oDict.Add(230, "GMR Head Amplitude") $oDict.Add(231, "Temperature") $oDict.Add(240, "Head Flying Hours") $oDict.Add(250, "Read Error Retry Rate") EndFunc ;==>_CreateDict PS: One further question: I did not really get how you can say the status is OK or not. What is the idea behind this?
-
Hi, I am currently working on a project that collects hardware information. I also have the problem, that the FDD is checked every time I want to retrieve SMART information. I already know the source of the problem: It's the function _DriveLetterToAntecedent (I renamed it). But when I try to implement a WHERE-clause, the WQL-Statement does not return any results. Here is my code: Func _DriveLetterToAntecedent(ByRef Const $objWMIService, Const $S_LETTER) ;~ Local $colItems = $objWMIService.ExecQuery("SELECT Dependent,Antecedent FROM Win32_LogicalDiskToPartition", _ ;~ "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDiskToPartition WHERE Dependent = '\\" & _ @ComputerName & '\root\cimv2:Win32_LogicalDisk.DeviceID="' & $S_LETTER & '"' & "'", _ "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) Then For $objItem In $colItems MsgBox(0, "", $objItem.Dependent & @CR & $objItem.Antecedent) ;~ If StringTrimRight(StringRight($objItem.Dependent, 3), 1) = $S_LETTER Then Return $objItem.Antecedent Next EndIf Return 0 EndFunc ;==>_DriveLetterToAntecedent Does anyone know how to fix the problem?