Leaderboard
Popular Content
Showing content with the highest reputation on 11/11/2014 in all areas
-
Microsoft Access database Second version
123disconnect and one other reacted to wolf9228 for a topic
Microsoft Access database Second version MS_AccessDB.zip New in this version - ODBC UNICODE Functions - Improvements to the SetBinary function - General improvements to the project functions ODBC is an API that uses Structured Query Language (SQL) as the database access language. You can access a wide variety of database management systems (DBMSs) with the same ODBC source code that is directly incorporated into an application's source code. With the Microsoft ODBC Desktop Database Drivers, a user of an ODBC-enabled application can open, query, and update a desktop database through the ODBC interface. The Microsoft ODBC Desktop Database Drivers are a Microsoft Jet-based set of ODBC drivers. Whereas Microsoft ODBC Desktop Database Drivers 2.0 include both 16-bit and 32-bit drivers, versions 3.0 and later include only 32-bit drivers that work on Windows 95 or later, Windows NT Workstation or Server version 4.0, Windows 2000 Professional, or Windows 2000 Server. These drivers provide access to the following types of data sources: Microsoft Access Microsoft Excel Paradox dBASE Text Microsoft Access Driver Programming Consideration http://msdn.microsoft.com/en-us/library/windows/desktop/ms710302%28v=vs.85%29.aspx Microsoft Access Data Types http://msdn.microsoft.com/en-us/library/windows/desktop/ms714540%28v=vs.85%29.aspx Microsoft Access Data Types http://www.w3schools.com/sql/sql_datatypes.asp MS_AccessDB.au3 #Include <WinAPI.au3> #include <Math.au3> Global $odbc32 = DllOpen("odbc32.dll") , $StructToString = False , $AUTOCOMMIT = True Func MS_AccessDatabaseCreate($DbFileName = "MSDataBase.mdb",$DshWnd = 0,$OverExFile = False) ; $OverExFile ==> overwrite existing file Local $ODBC_ADD_SYS_DSN = 4 Local $lpszDriver = "Microsoft Access Driver (*.MDB)" & Chr(0) Local $lpszAttributes = "CREATE_DB=" & $DbFileName & " General" & Chr(0) if Not($DshWnd) Then $DshWnd = _WinAPI_GetDesktopWindow() if ($OverExFile) And (FileExists($DbFileName)) Then if Not(FileDelete($DbFileName)) Then Return SetError(1,0,False) EndIf Local $Return = DllCall("odbccp32.dll","BOOL","SQLConfigDataSourceW","HWND",$DshWnd , _ "WORD",$ODBC_ADD_SYS_DSN,"wstr",$lpszDriver,"wstr",$lpszAttributes) if @error Or Not($Return[0]) Then Return SetError(2,0,False) Return SetError(0,0,True) EndFunc Func MS_AccessDatabaseConnect($DbFileName = "MSDataBase.mdb",$DshWnd = 0) Local $SQL_HANDLE_ENV = 1 , $SQL_NULL_HANDLE = 0 , $SQL_ATTR_ODBC_VERSION = 200 Local $SQL_OV_ODBC3 = 3,$Return = 0,$SQL_HANDLE_DBC = 2,$SQL_LOGIN_TIMEOUT = 103 Local $SQL_SUCCESS = 0 , $SQL_SUCCESS_WITH_INFO = 1 , $SQL_DRIVER_NOPROMPT = 0 Local $TIMEOUT = 5 , $hDatabase[2], $SQL_AUTOCOMMIT = 102,$SQL_AUTOCOMMIT_ON = 1 Local $SQL_IS_INTEGER = -6 Local $InConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & $DbFileName if Not($DshWnd) Then $DshWnd = _WinAPI_GetDesktopWindow() Local $Return = DllCall($odbc32,"short","SQLAllocHandle", _ "short",$SQL_HANDLE_ENV,"ptr",$SQL_NULL_HANDLE,"ptr*",0) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then Return SetError(1,0,0) EndIf Local $henv = $Return[3] $Return = DllCall("odbc32.dll","short","SQLSetEnvAttr","ptr",$henv, _ "long",$SQL_ATTR_ODBC_VERSION,"long",$SQL_OV_ODBC3,"long",0) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(2,0,0) EndIf $Return = DllCall($odbc32,"short","SQLAllocHandle","short",$SQL_HANDLE_DBC,"ptr",$henv,"ptr*",0) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(3,0,0) EndIf Local $hdbc = $Return[3] $Return = DllCall($odbc32,"short","SQLSetConnectAttr","ptr", _ $hdbc,"long",$SQL_LOGIN_TIMEOUT,"long",$TIMEOUT,"long",$SQL_IS_INTEGER) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLDisconnect","ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_DBC,"ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(4,0,0) EndIf if ($AUTOCOMMIT) Then $Return = DllCall($odbc32,"short","SQLSetConnectAttr","ptr", _ $hdbc,"long",$SQL_AUTOCOMMIT,"long",$SQL_AUTOCOMMIT_ON,"long",$SQL_IS_INTEGER) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLDisconnect","ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_DBC,"ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(5,0,0) EndIf EndIf $Return = DllCall($odbc32,"short","SQLDriverConnectW", _ "ptr",$hdbc ,"HWND",$DshWnd,"wstr",$InConnectionString, _ "short",-3,"ptr",0,"short",0,"short*",0,"short",$SQL_DRIVER_NOPROMPT) if @error Or ($Return[0] <> $SQL_SUCCESS And $Return[0] <> $SQL_SUCCESS_WITH_INFO) Then DllCall($odbc32,"short","SQLDisconnect","ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_DBC,"ptr",$hdbc) DllCall($odbc32,"short","SQLFreeHandle","short",$SQL_HANDLE_ENV,"ptr",$henv) Return SetError(6,0,0) EndIf $hDatabase = DllStructCreate("ptr hdbc;ptr henv") DllStructSetData($hDatabase,"hdbc",$hdbc) DllStructSetData($hDatabase,"henv",$henv) Return SetError(0,0,$hDatabase) EndFunc Func MS_AccessDatabaseDisconnect($hDatabase) Local $SQL_HANDLE_ENV = 1,$SQL_HANDLE_DBC = 2 Local $hdbc = DllStructGetData($hDatabase,"hdbc") Local $henv = DllStructGetData($hDatabase,"henv") SQLDisconnect($hdbc) if @error Then Return SetError(1,0,False) SQLFreeHandle($SQL_HANDLE_DBC,$hdbc) if @error Then Return SetError(2,0,False) SQLFreeHandle($SQL_HANDLE_ENV,$henv) if @error Then Return SetError(3,0,False) Return SetError(0,0,True) EndFunc Func CreateTable($hDatabase,$TableName,$ColumnsListNameTypeSize) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "CREATE TABLE " & $TableName & " (" & $ColumnsListNameTypeSize & ")" Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func InsertInToTable($hDatabase,$TableName,$ColumnsList,$ValueList) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "INSERT INTO " & $TableName & " (" & $ColumnsList & _ ") VALUES(" & $ValueList & ")" Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func ColumnsAdd($hDatabase,$TableName,$ColumnsListNameTypeSize) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "ALTER TABLE " & $TableName & _ " ADD " & $ColumnsListNameTypeSize Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func UpdateTable($hDatabase,$TableList,$ColumnsList,$OperationsList) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "UPDATE " & $TableList & " SET " & _ $ColumnsList & " WHERE " & $OperationsList Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func DeleteFromTable($hDatabase,$TableName,$OperationsList) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "DELETE FROM " & _ $TableName & " WHERE " & $OperationsList Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func TableRemove($hDatabase,$TableName) Local $SQL_HANDLE_STMT = 3 Local $StatementText = "DROP TABLE " & $TableName Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,False) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(0,0,True) EndFunc Func SelectRecordsGroup($hDatabase,$TableName,$ColumnsList = "",$OperationList = "") ;$ColumnsList Can be empty string "" ;$OperationList Can be empty string "" Local $SQL_HANDLE_STMT = 3 , $SQL_Error = -1 , $SQL_INTEGER = 4 Local $CountStatText = "SELECT COUNT(*) FROM " & $TableName Local $StatementText = "SELECT " if StringLen($ColumnsList) Then $StatementText &= $ColumnsList & " FROM " & $TableName Else $StatementText &= "* FROM " & $TableName EndIf if StringLen($OperationList) Then $StatementText &= " WHERE " & $OperationList $CountStatText &= " WHERE " & $OperationList EndIf Local $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(1,0,0) SQLExecDirect($hStatement,$CountStatText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(2,0,0) EndIf SQLFetch($hStatement) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(3,0,0) EndIf Local $DataStruct = DllStructCreate("INT") , $Col_Num = 1 SQLGetData($hStatement,$Col_Num,$SQL_INTEGER,$DataStruct) if @error Or @extended = $SQL_Error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(4,0,0) EndIf Local $RowsCount = DllStructGetData($DataStruct,1) SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) $hStatement = GetStmtHandle($hDatabase) if @error Then Return SetError(5,0,0) SQLExecDirect($hStatement,$StatementText) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(6,0,0) EndIf Local $ColsCount = SQLGetColsCount($hStatement) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$hStatement) Return SetError(7,0,0) EndIf Local $ihStatement = 0, $tagSt = "" $tagSt = "PTR HST;INT RSC;INT CSC;WCHAR STT[" & (StringLen($StatementText) + 1) & "]" $ihStatement = DllStructCreate($tagSt) DllStructSetData($ihStatement,"HST",$hStatement) DllStructSetData($ihStatement,"RSC",$RowsCount) DllStructSetData($ihStatement,"CSC",$ColsCount) DllStructSetData($ihStatement,"STT",$StatementText) Return SetError(0,0,$ihStatement) EndFunc Func GetRecordsData(ByRef $hStatement,$hStatementFree = True) Local $SQL_TYPE_DATE = 91 , $SQL_TYPE_TIME = 92 , $SQL_TYPE_TIMESTAMP = 93 Local $SQL_BIT = -7,$SQL_WVARCHAR = -9,$SQL_WLONGVARCHAR = -10,$SQL_WCHAR = -8 Local $SQL_VARBINARY = -3 , $SQL_REAL = 7 , $SQL_GUID = -11 , $SQL_INTEGER = 4 Local $SQL_TINYINT = -6 , $SQL_DOUBLE = 8 , $Row_Num = 4 , $SQL_SMALLINT = 5 Local $SQL_LONGVARBINARY = -4 , $SQL_NUMERIC = 2 , $SQL_HANDLE_STMT = 3 Local $DatType , $ColSize , $ColName , $SQL_BINARY = -2 , $SQL_Error = -1 Local $HandleSta = DllStructGetData($hStatement,"HST") Local $RowsCount = DllStructGetData($hStatement,"RSC") Local $ColsCount = DllStructGetData($hStatement,"CSC") Local $StateText = DllStructGetData($hStatement,"STT") if Not($RowsCount) Or Not($ColsCount) Then Return SetError(1,0,0) Local $ReturnArray[$RowsCount + 3][$ColsCount] While(SQLFetch($HandleSta)) For $Col_Num = 1 To $ColsCount Local $DescribeArray = SQLDescribeCol($HandleSta,$Col_Num) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(2,0,0) EndIf $ColName = $DescribeArray[0] $ColSize = $DescribeArray[1] $DatType = $DescribeArray[2] if ($Row_Num = 4) Then $ReturnArray[0][$Col_Num - 1] = $ColName $ReturnArray[1][$Col_Num - 1] = $ColSize $ReturnArray[2][$Col_Num - 1] = $DatType EndIf Local $VALUES = "",$GetDataerror = 0 Switch $DatType Case $SQL_WCHAR , $SQL_WLONGVARCHAR , $SQL_WVARCHAR SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(3,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("WCHAR[" & ($Length + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(4,0,0) Else $VALUES = DllStructGetData($DataStruct,1) EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_BINARY , $SQL_VARBINARY , $SQL_LONGVARBINARY SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(5,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("BYTE[" & $Length & "]") SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(6,0,0) Else $VALUES = $DataStruct EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_TYPE_DATE if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(7,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;SHORT day") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_DATE,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(8,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIME if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(9,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else $DataStruct = DllStructCreate("SHORT hour;SHORT minute;SHORT second") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_TIME,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(10,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIMESTAMP if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(11,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;" & _ "SHORT day;SHORT hour;SHORT minute;SHORT second") if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(12,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_GUID if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(13,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("ulong Data1;" & _ "ushort Data2;ushort Data3;byte Data4[8]") $VALUES = $DataStruct SQLGetData($HandleSta,$Col_Num,$SQL_GUID,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(14,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TINYINT , $SQL_BIT Local $DataStruct = DllStructCreate("BYTE") SQLGetData($HandleSta,$Col_Num,$SQL_TINYINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(15,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_INTEGER Local $DataStruct = DllStructCreate("INT") SQLGetData($HandleSta,$Col_Num,$SQL_INTEGER,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(16,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_REAL Local $DataStruct = DllStructCreate("float") SQLGetData($HandleSta,$Col_Num,$SQL_REAL,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(17,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_DOUBLE,$SQL_NUMERIC Local $DataStruct = DllStructCreate("DOUBLE") SQLGetData($HandleSta,$Col_Num,$SQL_DOUBLE,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(18,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_SMALLINT Local $DataStruct = DllStructCreate("SHORT") SQLGetData($HandleSta,$Col_Num,$SQL_SMALLINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(19,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case Else Return SetError(20,0,0) EndSwitch $ReturnArray[$Row_Num - 1][$Col_Num - 1] = $VALUES Next $Row_Num += 1 WEnd if ($hStatementFree) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) $hStatement = 0 Else SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) EndIf ;$ReturnArray[0][Column Number] = Column Name ;$ReturnArray[1][Column Number] = Column Max Size ;$ReturnArray[2][Column Number] = Column Data Type Return SetError(0,0,$ReturnArray) EndFunc Func EnumRecordsData(ByRef $hStatement,$EnumRecDataProc,$hStatementFree = True) ;---------------------EnumRecDataProc---------------------------------------------------------- ;Func EnumRecDataProc($IsNullValue,$Value,$ColName,$ColFormat,$ColMaxSize,$RowNum,$ColNum) ;return ;True ;Continue ;False ; Stop ; ;return true; ;EndFunc ;---------------------EnumRecDataProc---------------------------------------------------------- Local $SQL_TYPE_DATE = 91 , $SQL_TYPE_TIME = 92 , $SQL_TYPE_TIMESTAMP = 93 Local $SQL_BIT = -7,$SQL_WVARCHAR = -9,$SQL_WLONGVARCHAR = -10,$SQL_WCHAR = -8 Local $SQL_VARBINARY = -3 , $SQL_REAL = 7 , $SQL_GUID = -11 , $SQL_INTEGER = 4 Local $SQL_TINYINT = -6 , $SQL_DOUBLE = 8 , $Row_Num = 4 , $SQL_SMALLINT = 5 Local $SQL_LONGVARBINARY = -4 , $SQL_NUMERIC = 2 , $SQL_HANDLE_STMT = 3 Local $DatType , $ColSize , $ColName , $SQL_BINARY = -2 , $SQL_Error = -1 Local $iReg = DllCallbackRegister($EnumRecDataProc,"int","int;int;int;int;int;int;int") if @error Then Return SetError(1,0,False) DllCallbackFree($iReg) Local $HandleSta = DllStructGetData($hStatement,"HST") Local $RowsCount = DllStructGetData($hStatement,"RSC") Local $ColsCount = DllStructGetData($hStatement,"CSC") Local $StateText = DllStructGetData($hStatement,"STT") if Not($RowsCount) Or Not($ColsCount) Then Return SetError(2,0,False) While(SQLFetch($HandleSta)) For $Col_Num = 1 To $ColsCount Local $DescribeArray = SQLDescribeCol($HandleSta,$Col_Num) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(3,0,0) EndIf $ColName = $DescribeArray[0] $ColSize = $DescribeArray[1] $DatType = $DescribeArray[2] Local $VALUES = "",$GetDataerror = 0 Switch $DatType Case $SQL_WCHAR , $SQL_WLONGVARCHAR , $SQL_WVARCHAR SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(4,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("WCHAR[" & ($Length + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(5,0,0) Else $VALUES = DllStructGetData($DataStruct,1) EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_BINARY , $SQL_VARBINARY , $SQL_LONGVARBINARY SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,0,True) ; $GetSize = True if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(6,0,0) EndIf if @extended <> $SQL_Error Then Local $Length = @extended Local $DataStruct = DllStructCreate("BYTE[" & $Length & "]") SQLGetData($HandleSta,$Col_Num,$SQL_BINARY,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(7,0,0) Else $VALUES = $DataStruct EndIf Else $VALUES = "" ;NULL VALUE EndIf Case $SQL_TYPE_DATE if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(8,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;SHORT day") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_DATE,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(9,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIME if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(10,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else $DataStruct = DllStructCreate("SHORT hour;SHORT minute;SHORT second") SQLGetData($HandleSta,$Col_Num,$SQL_TYPE_TIME,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(11,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TYPE_TIMESTAMP if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(12,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("SHORT year;SHORT month;" & _ "SHORT day;SHORT hour;SHORT minute;SHORT second") if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(13,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_GUID if ($StructToString) Then Local $DataStruct = DllStructCreate("WCHAR[" & ($ColSize + 1) & "]") SQLGetData($HandleSta,$Col_Num,$SQL_WCHAR,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(14,0,0) Else $GetDataerror = @extended $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Else Local $DataStruct = DllStructCreate("ulong Data1;" & _ "ushort Data2;ushort Data3;byte Data4[8]") $VALUES = $DataStruct SQLGetData($HandleSta,$Col_Num,$SQL_GUID,$DataStruct) if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(15,0,0) Else $GetDataerror = @extended $VALUES = $DataStruct if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf EndIf Case $SQL_TINYINT , $SQL_BIT Local $DataStruct = DllStructCreate("BYTE") SQLGetData($HandleSta,$Col_Num,$SQL_TINYINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(16,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_INTEGER Local $DataStruct = DllStructCreate("INT") SQLGetData($HandleSta,$Col_Num,$SQL_INTEGER,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(17,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_REAL Local $DataStruct = DllStructCreate("float") SQLGetData($HandleSta,$Col_Num,$SQL_REAL,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(18,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_DOUBLE,$SQL_NUMERIC Local $DataStruct = DllStructCreate("DOUBLE") SQLGetData($HandleSta,$Col_Num,$SQL_DOUBLE,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(19,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case $SQL_SMALLINT Local $DataStruct = DllStructCreate("SHORT") SQLGetData($HandleSta,$Col_Num,$SQL_SMALLINT,$DataStruct) $GetDataerror = @extended if @error Then SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) Return SetError(20,0,0) Else $VALUES = DllStructGetData($DataStruct,1) if ($GetDataerror = $SQL_Error) Then $VALUES = "" ;NULL VALUE EndIf Case Else Return SetError(21,0,0) EndSwitch Local $IsNullValue = ($GetDataerror == $SQL_Error) Local $Return = Call($EnumRecDataProc,$IsNullValue , _ $VALUES,$ColName,$DatType,$ColSize,$Row_Num - 3,$Col_Num) if Not($Return) Then if ($hStatementFree) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) $hStatement = 0 Else SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) EndIf Return SetError(0,0,True) EndIf Next $Row_Num += 1 WEnd if ($hStatementFree) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) $hStatement = 0 Else SQLFreeStmt($HandleSta,0) ; $SQL_CLOSE = 0 SQLExecDirect($HandleSta,$StateText) EndIf Return SetError(0,0,True) EndFunc Func SaveStreamFile($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$FilePath) Local $nBytes Local $ByteStruct = GetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue) if @error Then Return SetError(1,0,False) Local $hFile = _WinAPI_CreateFile($FilePath,1) if Not($hFile) Then Return SetError(2,0,False) Local $Return = _WinAPI_WriteFile($hFile,DllStructGetPtr($ByteStruct),DllStructGetSize($ByteStruct),$nBytes) if Not($Return) Then _WinAPI_CloseHandle($hFile) Return SetError(3,0,False) EndIf _WinAPI_CloseHandle($hFile) Return SetError(0,0,True) EndFunc Func SetStreamFile($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$FilePath) Local $nBytes Local $FileSize = FileGetSize($FilePath) if @error Then Return SetError(1,0,False) Local $hFile = _WinAPI_CreateFile($FilePath,2,2) if Not($hFile) Then Return SetError(2,0,False) Local $DataStruct = DllStructCreate("BYTE[" & $FileSize & "]") Local $Return = _WinAPI_ReadFile($hFile,DllStructGetPtr($DataStruct),$FileSize,$nBytes) if Not($Return) Then _WinAPI_CloseHandle($hFile) Return SetError(3,0,False) EndIf _WinAPI_CloseHandle($hFile) SetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$DataStruct) if @error Then Return SetError(4,0,False) Return SetError(0,0,True) EndFunc Func GetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue) Local $OpList = $PrimaryKeyName & " = " & $PrimaryKeyValue , $nBytes Local $SQL_BINARY = -2 , $SQL_VARBINARY = -3 , $SQL_LONGVARBINARY = -4 Local $hStatement = SelectRecordsGroup($hDatabase,$TableName,$ColumnName,$OpList) if @error Then Return SetError(1,0,0) Local $ReturnArray = GetRecordsData($hStatement) if @error Then Return SetError(2,0,0) Switch $ReturnArray[2][0] Case $SQL_BINARY,$SQL_VARBINARY,$SQL_LONGVARBINARY Local $ByteStruct = $ReturnArray[3][0] Return SetError(0,0,$ByteStruct) Case Else Return SetError(3,0,0) EndSwitch EndFunc Func SetBinary($hDatabase,$TableName,$ColumnName,$PrimaryKeyName,$PrimaryKeyValue,$DataStruct) Local $SQL_VARBINARY = -3 , $SQL_LONGVARBINARY = -4, $SQL_BINARY = -2 , $ColNu = 1 Local $BinarySize = DllStructGetSize($DataStruct),$ParamNu = 1,$SQL_PARAM_INPUT = 1 Local $SQL_C_BINARY = -2 , $SQL_HANDLE_STMT = 3 , $SizeAtOneTime = 1048576 Local $SQL_NEED_DATA = 99 ,$ByteData = DllStructGetPtr($DataStruct) , $InSize = 0 ;SizeAtOneTime = 1048576 bytes // 1 MB Local $hStatement = SelectRecordsGroup($hDatabase,$TableName,$ColumnName) if @error Then Return SetError(1,0,False) EndIf Local $HandleSta = DllStructGetData($hStatement,"HST") Local $DescribeArray = SQLDescribeCol($HandleSta,$ColNu) if @error Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(2,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Local $ColName = $DescribeArray[0] Local $ColSize = $DescribeArray[1] Local $DatType = $DescribeArray[2] Local $pBinary = ($DatType == $SQL_BINARY Or $DatType == $SQL_LONGVARBINARY Or $DatType == $SQL_VARBINARY) If Not($pBinary) Then Return SetError(3,0,False) Local $HandleSta = GetStmtHandle($hDatabase) if @error Then Return SetError(4,0,False) Local $LenAtExec = SQL_LEN_DATA_AT_EXEC($BinarySize) Local $ParameterValuePtrSt = DllStructCreate("INT") DllStructSetData($ParameterValuePtrSt,1,1) Local $LenAtExecSt = DllStructCreate("INT") DllStructSetData($LenAtExecSt,1,$LenAtExec) Local $Return = DllCall($odbc32,"short","SQLBindParameter","ptr",$HandleSta,"USHORT",$ParamNu, _ "short",$SQL_PARAM_INPUT,"short",$SQL_C_BINARY,"short",$DatType,"LONG" , $BinarySize , "short" , _ 0,"ptr" , DllStructGetPtr($ParameterValuePtrSt) ,"LONG" ,0,"ptr",DllStructGetPtr($LenAtExecSt)) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(5,0,0) EndIf Local $StatementText = "UPDATE " & $TableName & " SET " & $ColumnName & " = ? WHERE " & _ $PrimaryKeyName & " = " & $PrimaryKeyValue Local $Return = DllCall($odbc32,"short","SQLExecDirectW","ptr",$HandleSta, _ "wstr",$StatementText,"long",StringLen($StatementText)) if @error Or $Return[0] <> $SQL_NEED_DATA Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(6,0,False) EndIf Local $ValuePtrPtrSt = DllStructCreate("PTR") $Return = DllCall($odbc32,"short","SQLParamData","ptr",$HandleSta,"ptr",DllStructGetPtr($ValuePtrPtrSt)) if @error Or $Return[0] <> $SQL_NEED_DATA Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(7,0,False) EndIf While (($BinarySize > 0)) $InSize = _Min($SizeAtOneTime,$BinarySize) $Return = DllCall($odbc32,"short","SQLPutData","ptr",$HandleSta,"ptr",$ByteData,"LONG",$InSize) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(8,0,False) EndIf $BinarySize -= $InSize WEnd $Return = DllCall($odbc32,"short","SQLParamData","ptr",$HandleSta,"ptr",DllStructGetPtr($ValuePtrPtrSt)) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(9,0,False) EndIf SQLFreeHandle($SQL_HANDLE_STMT,$HandleSta) Return SetError(0,0,True) EndFunc Func SQLDisconnect($ConnectionHandle) Local $Return = DllCall($odbc32,"short","SQLDisconnect","ptr",$ConnectionHandle) if @error Or ($Return[0] <> 0) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLExecDirect($StatementHandle,$StatementText) Local $TextLength = StringLen($StatementText) Local $Return = DllCall($odbc32,"short","SQLExecDirectW","ptr",$StatementHandle, _ "wstr",$StatementText,"long",$TextLength) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLFreeStmt($StatementHandle,$Option) Local $Return = DllCall($odbc32,"short","SQLFreeStmt","ptr",$StatementHandle,"ushort",$Option) if @error Or ($Return[0] <> 0) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLFreeHandle($HandleType,$Handle) Local $Return = DllCall($odbc32,"short","SQLFreeHandle","short",$HandleType,"ptr",$Handle) if @error Or ($Return[0] <> 0) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func GetStmtHandle($hDatabase) Local $SQL_HANDLE_STMT = 3 Local $hdbc = DllStructGetData($hDatabase,"hdbc") Local $Return = DllCall($odbc32,"short","SQLAllocHandle","short",$SQL_HANDLE_STMT,"ptr",$hdbc,"ptr*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,0) Local $hStatement = $Return[3] Return SetError(0,0,$hStatement) EndFunc Func SQLFetch($StatementHandle) Local $Return = DllCall($odbc32,"short","SQLFetch","ptr",$StatementHandle) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,$Return[0],True) EndFunc Func SQLDescribeCol($StatementHandle,$ColumnNumber) Local $Return = DllCall($odbc32,"short","SQLDescribeColW","ptr",$StatementHandle _ ,"short",$ColumnNumber,"wstr*",0,"short",0,"short*",0,"short*",0,"ULONG*",0, _ "short*",0,"short*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,0) Local $NameLengthPtr = $Return[5] Local $ColumnNameSt = DllStructCreate("WCHAR[" & ($NameLengthPtr + 1) & "]") $Return = DllCall($odbc32,"short","SQLDescribeColW","ptr",$StatementHandle,"short", _ $ColumnNumber,"struct*",$ColumnNameSt,"short",($NameLengthPtr * 2),"ptr",0,"short*" _ ,0,"ULONG*",0,"short*",0,"short*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(2,0,0) Local $DescribeArray[3] $DescribeArray[0] = DllStructGetData($ColumnNameSt,1) $DescribeArray[1] = $Return[7] $DescribeArray[2] = $Return[6] Return SetError(0,0,$DescribeArray) EndFunc Func SQLGetData($StatementHandle,$Col_Num,$TargetType,$DataStruct,$GetSize = False) if ($GetSize) Then $Return = DllCall($odbc32,"short","SQLGetData","ptr",$StatementHandle _ ,"USHORT",$Col_Num,"short",$TargetType,"ptr",-1,"ULONG",0,"ULONG*",0) Else $Return = DllCall($odbc32,"short","SQLGetData","ptr",$StatementHandle _ ,"USHORT",$Col_Num,"short",$TargetType,"struct*",$DataStruct,"ULONG", _ DllStructGetSize($DataStruct),"ULONG*",0) EndIf if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,$Return[6],True) EndFunc Func SQLCOMMIT($hDatabase) Local $hdbc = DllStructGetData($hDatabase,"hdbc") , $SQL_HANDLE_DBC = 2,$SQL_COMMIT = 0 Local $Return = DllCall($odbc32,"short","SQLEndTran","short",$SQL_HANDLE_DBC _ ,"ptr",$hdbc,"short",$SQL_COMMIT) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,False) Return SetError(0,0,True) EndFunc Func SQLGetColsCount($StatementHandle) Local $Return = DllCall($odbc32,"short","SQLNumResultCols","ptr",$StatementHandle,"short*",0) if @error Or ($Return[0] <> 0 And $Return[0] <> 1) Then Return SetError(1,0,0) Return SetError(0,0,$Return[2]) EndFunc Func SQL_LEN_DATA_AT_EXEC($length) Local $SQL_LEN_DATA_AT_EXEC_OFFSET = (-100) Return (-($length)+$SQL_LEN_DATA_AT_EXEC_OFFSET) EndFunc2 points -
Simple SOAP Example For those who don't know what SOAP (Simple Object Access Protocol) is. In this SOAP example, you will learn what SOAP is, and how it uses XML to exchange information between applications. The next step will be, how to turn AU3 into a Web Services server. This is the SOAP CLIENT Dim $objHTTP Dim $strEnvelope Dim $strReturn Dim $objReturn Dim $dblTax Dim $strQuery Dim $value $value = InputBox("Testing", "Enter your new value here.", 10) ; Initialize COM error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $objHTTP = ObjCreate("Microsoft.XMLHTTP") $objReturn = ObjCreate("Msxml2.DOMdocument.3.0") ; Create the SOAP Envelope $strEnvelope = "<soap:envelope xmlns:soap=""urn:schemas-xmlsoap-org:soap.v1"">" & _ "<soap:header></soap:header>" & _ "<soap:body>" & _ "<m:getsalestax xmlns:m=""urn:myserver/soap:TaxCalculator"">" & _ "<salestotal>"&$value&"</salestotal>" & _ "</m:getsalestax>" & _ "</soap:body>" & _ "</soap:envelope>" ; Set up to post to our local server $objHTTP.open ("post", "http://localhost/soap.asp", False) ; Set a standard SOAP/ XML header for the content-type $objHTTP.setRequestHeader ("Content-Type", "text/xml") ; Set a header for the method to be called $objHTTP.setRequestHeader ("SOAPMethodName", "urn:myserver/soap:TaxCalculator#getsalestax") ConsoleWrite("Content of the Soap envelope : "& @CR & $strEnvelope & @CR & @CR) ; Make the SOAP call $objHTTP.send ($strEnvelope) ; Get the return envelope $strReturn = $objHTTP.responseText ; ConsoleWrite("Debug : "& $strReturn & @CR & @CR) ; Load the return envelope into a DOM $objReturn.loadXML ($strReturn) ConsoleWrite("Return of the SOAP Msg : " & @CR & $objReturn.XML & @CR & @CR) ; Query the return envelope $strQuery = "SOAP:Envelope/SOAP:Body/m:getsalestaxresponse/salestax" $dblTax = $objReturn.selectSingleNode($strQuery) $Soap = $objReturn.Text MsgBox(0,"SOAP Response","The Sales Tax is : " & $Soap) Func MyErrFunc() $HexNumber=hex($oMyError.number,8) Msgbox(0,"COM Test","We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext _ ) SetError(1) ; to check for after this function returns Endfunc This is the SOAP SERVER <% Dim oNode Set objReq = Server.CreateObject("Msxml2.DOMdocument.3.0") 'Load the request into XML DOM objReq.Load Request 'Query the DOM for the input parameter ' Remember: xpath is case sensitive. "SalesTotal" is not the same as "salestotal" strQuery = "SOAP:Envelope/SOAP:Body/m:getsalestax/salestotal" 'varSalesTotal = objReq.SelectSingleNode(strQuery).Text Set oNode = Nothing Set oNode = objReq.SelectSingleNode(strQuery) if not oNode is Nothing Then varSalesTotal = oNode.Text else 'handle the error - save the xml to a file so you can look at it varSalesTotal = objReq.Text end if 'Calculate the sales tax varSalesTax = varSalesTotal * 0.04 'Prepare the return envelope strTmp = _ "<soap:envelope xmlns:soap=""urn:schemas-xmlsoap-org:soap.v1"">" & _ "<soap:header></soap:header>" & _ "<soap:body>" & _ "<m:getsalestaxresponse xmlns:m=""urn:myserver/soap:Taxcalc"">" & _ "<salestax>" & varSalesTax & "</salestax>" & _ "</m:getsalestaxresponse>" & _ "</soap:body>" & _ "</soap:envelope>" 'Write the return envelope Response.Write strTmp %> Save the SOAP SERVER as SOAP.asp and put it in the root of your IIS server. Run the client and see what happenes. Enjoy !! Regards ptrex1 point
-
Short-Order Encrypter -- Updated March 6th, 2015
coffeeturtle reacted to MikahS for a topic
Short-Order Encrypter Just a fun project I had making a Crypt GUI that will encrypt and decrypt messages and files. All regular encryption types have been included for use. It will dynamically ask for a password, making it so there are never any passwords stored inside script. All dynamically built. I have included source code for your pleasure I wanted to get this onto the forum just see if anyone had any use for it. I am open and listening for questions, concerns, and comments Short-Order Encrypter.zip Short-Order EncrypterV1.0.5.zip Short-Order EncrypterV1.5.0.zip Short-Order Encrypter V1.6.0.zip Short-Order Encrypter V1.6.1.zip Current Version: 1.6.1.0 Version History:1 point -
PDFCreator in AutoIT 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII Someone in the help forum was wondering how to use the PDFCreator in AutoIT. When reading this, I was surprised to find that PDFCreator had a COM object in it's latest version. I have been using PDFCreator since years, but never know this :"> Anyhow here is the example on how to create a PDF Test page. ;; Testpage2PDF script ; Part of $PDFCreator ; License: GPL ; Homepage: http://www.sf.net/projects/pdfcreator ; Version: 1.0.0.0 ; Date: September, 1. 2005 ; Author: Frank Heindörfer ; Comments: Save the test page as pdf-file using the com interface of $PDFCreator. ; Translated by ptrex AutoItSetOption("MustDeclareVars", 1) Const $maxTime = 10 ; in seconds Const $sleepTime = 250 ; in milliseconds Dim $fso, $WshShell, $PDFCreator, $DefaultPrinter, $ReadyState, $c, _ $Scriptname, $Scriptbasename $fso = ObjCreate("Scripting.FileSystemObject") $Scriptbasename = $fso.GetBaseName(@ScriptFullPath) $WshShell = ObjCreate("WScript.Shell") $PDFCreator = ObjCreate("PDFCreator.clsPDFCreator") $PDFCreator.cStart ("/NoProcessingAtStartup") $ReadyState = 0 With $PDFCreator .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveDirectory") = $fso.GetParentFolderName(@ScriptFullPath) .cOption("AutosaveFilename") = "Testpage - PDFCreator" .cOption("AutosaveFormat") = 0 ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII $DefaultPrinter = .cDefaultprinter .cDefaultprinter = "PDFCreator" .cClearcache() .cPrintPDFCreatorTestpage() .cPrinterStop = 0 EndWith $c = 0 Do $c = $c + 1 Sleep ($sleepTime) Until ($ReadyState = 0) and ($c < ($maxTime * 1000 / $sleepTime)) With $PDFCreator .cDefaultprinter = $DefaultPrinter Sleep( 200) .cClose() EndWith If $ReadyState = 0 then Consolewrite ("Creating test page as pdf." & @CRLF & @CRLF & "An error is occured: Time is up!"& @CR) ProcessClose("PDFCreator.exe") EndIf ;--- $PDFCreator events --- Func PDFCreator_eReady() $ReadyState = 1 EndFunc Func PDFCreator_eError() Consolewrite ("An error is occured!" & @CRLF & @CRLF & _ "Error [" & $PDFCreator.cErrorDetail("Number") & "]: " & $PDFCreator.cErrorDetail("Description")& @CR) ;VA Wscript.Quit EndFunc ; Convert2PDF script ; Part of $PDFCreator ; License: GPL ; Homepage: http://www.sf.net/projects/pdfcreator ; Version: 1.0.0.0 ; Date: September, 1. 2005 ; Author: Frank Heindörfer ; Comments: This script convert a printable file in a pdf-file using the com interface of $PDFCreator. ; Translated by ptrex AutoItSetOption("MustDeclareVars", 1) Const $maxTime = 30 ; in seconds Const $sleepTime = 250 ; in milliseconds Dim $objArgs, $ifname, $fso, $PDFCreator, $DefaultPrinter, $ReadyState, _ $i, $c, $AppTitle, $Scriptname, $ScriptBasename, $File $fso = ObjCreate("Scripting.FileSystemObject") $Scriptname = $fso.GetFileName(@ScriptFullPath) $ScriptBasename = $fso.GetFileName(@ScriptFullPath) $AppTitle = "PDFCreator - " & $ScriptBasename $File = InputBox("FileName","Fill in the Path and filename","C:_AppsAutoIT3COMPDFCreatorVBScriptsGUI.vbs") $PDFCreator = ObjCreate("PDFCreator.clsPDFCreator") $PDFCreator.cStart ("/NoProcessingAtStartup") With $PDFCreator .cOption("UseAutosave") = 1 .cOption("UseAutosaveDirectory") = 1 .cOption("AutosaveFormat") = 1 ; 0=PDF, 1=PNG, 2=JPG, 3=BMP, 4=PCX, 5=TIFF, 6=PS, 7= EPS, 8=ASCII $DefaultPrinter = .cDefaultprinter .cDefaultprinter = "PDFCreator" .cClearcache() EndWith ; For $i = 0 to $objArgs.Count - 1 With $PDFCreator $ifname = $File ;"C:TmpTest.xls" ;$objArgs($i) If Not $fso.FileExists($ifname) Then MsgBox (0,"Error","Can't find the file: " & $ifname & @CR & $AppTitle) Exit EndIf If Not .cIsPrintable(String($ifname)) Then ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _ "An error is occured: File is not printable!" & @CRLF & $AppTitle & @CR) EndIf $ReadyState = 0 .cOption("AutosaveDirectory") = $fso.GetParentFolderName($ifname) .cOption("AutosaveFilename") = $fso.GetBaseName($ifname) .cPrintfile (String($ifname)) .cPrinterStop = 0 $c = 0 Do $c = $c + 1 Sleep ($sleepTime) Until ($ReadyState = 0) and ($c < ($maxTime * 1000 / $sleepTime)) If $ReadyState = 0 then ConsoleWrite("Converting: " & $ifname & @CRLF & @CRLF & _ "An error is occured: File is not printable!" & @CRLF & $AppTitle & @CR) Exit EndIf EndWith ;Next With $PDFCreator .cDefaultprinter = $DefaultPrinter .cClearcache() Sleep (200) .cClose() EndWith ProcessClose("PDFCreator.exe") ;--- $PDFCreator events --- Func PDFCreator_eReady() $ReadyState = 1 EndFunc Func PDFCreator_eError() MsgBox(0, "An error is occured!" , "Error [" & $PDFCreator.cErrorDetail("Number") & "]: " & $PDFCreator.cErrorDetail("Description")& @CR) EndFunc There are lot's of VBScript Examples distributed with the installation. As well as for other Scripting or Programming languages. Even for MS Office VBA So let's go and add your scripts to it. Enjoy !! ptrex1 point
-
4b0082, That will do the trick. It is a common problem and as soon as you find comparisons which do not appear to work correctly it should always be your first suspicion. Why does it happen? Because AutoIt variables are not typed and occasionally do not store values in the form you expect - for example anything read from an ini file is automatically stored as a string. Should it happen? Jon made a design decision all those years ago not to use typed variables for ease of use - too late to go back now and so the user has to take care in certain situations, with comparisons being the most frequent problem area. M231 point
-
4b0082, Although the values appear numeric, they may well be stored as strings within the array depending on how you filled it. Use VarGetType to check - and force them to number format with Number if necessary. M231 point
-
Are all your values numeric? Strings won't evaluate properly. You can cast them to numbers to be sure. Also, the whole code would be more helpful. Finally, I would suggest some debugging to measure all the values along the way and check for errors.1 point
-
mpower, When you resize the list, the parameters in the handler refer to that GUI and not the main one - hence the ListView vanishing as it was redrawn outside the main GUI. All you need do is check which GUI sent the SIZE message and ignore those from the list GUI: Func WM_SIZE($hwnd, $uMsg, $wParam, $lParam) If $hWnd <> $maingui Then Return 0 [...] M231 point
-
Run, Runwait or @ComSpec piping output using "|"
dynamitemedia reacted to MHz for a topic
In this case, your command starts with a double quote and you have more then 1 pair of quotes. CMD will strip the outer double quotes under this condition. A not so good example as I know wordpad will not redirect anything, though, it shows the behavior with the quotes: Run('cmd /k "%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt"') See above how the command starts with a double quote and that more then 1 pair of double quotes exist in the command as "test file.txt" has whitespace in it. CMD will see this and will strip the outer double quotes. So the command run is like this where %programfiles% is not expanded yet but imagine it has expanded with the whitespace in the files path showing: %ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt It may generate an error such as: 'C:\Program' is not recognized as an internal or external command, operable program or batch file. which is breaking at the 1st instance of whitespace in the command. The command has inadequate quoting due to the behavior of CMD. If you look at CMD /? to see the reason for this behavior, you may see this. If /C or /K is specified, then the remainder of the command line after the switch is processed as a command line, where the following logic is used to process quote (") characters: 1. If all of the following conditions are met, then quote character on the command line are preserved: - no /S switch - exactly two quote characters - no special characters between the two quote characters, where special is one of: &<>()@^| - there are one or more whitespace characters between the two quote characters - the string between the two quote characters is the name of an executable file. 2. Otherwise, old behavior is to see if the first character is a quote character and if so, strip the leading character and remove the last quote character on the command line, preserving any text after the last quote character. The explanation of above is that the command uses /k. In condition 1, exactly two quote characters has not been met with the command. So condition 2 applies, thus it mentions about stripping quotes as being the 1st character and the last character. To counter this behavior, you insert additional quotes that can be stripped so the original command is left intact. So with this information mentioned, the command is changed to: Run('cmd /k ""%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt""') Now the outer quotes will be stripped and the command processed will be this: "%ProgramFiles%\Windows NT\Accessories\wordpad.exe" > "test file.txt" and so no error should happen. At this point, you should probably be feeling better knowing how to resolve the behavior. A pair of backslashs i.e. separating segments of a path is interpreted the same as a single backslash by CMD i.e. . This is because within a path is meaningless as no path segment exists between the backslashs. Example of many backslashs: Run('cmd /k ""%ProgramFiles%\\\\\\\\\\Windows NT\Accessories\wordpad.exe" > "test file.txt""') All of those repetitive backslashs will be interpreted as 1 i.e. = . Probably not. My reference was to recognize your OS by your reference to "Documents and Settings". So long as you quote well, then issues hopefully will not happen.1 point -
I don't know / can't remember whether this is possible but you can do a workaroud: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 324, 222, 192, 124) $Radio1 = GUICtrlCreateRadio("", 104, 72, 14, 17) ;~ DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($Radio1), "wstr", 0, "wstr", 0) $Label = GUICtrlCreateLabel("Radio One", 120, 70, 100, 17) $hLabel = GUICtrlGetHandle($Label) GUICtrlSetFont(-1, 12, 400, 0, "Palatino Linotype") GUICtrlSetColor(-1, 0xFF0000) $Radio2 = GUICtrlCreateRadio("Radio Two", 104, 110, 113, 17) GUICtrlSetFont(-1, 12, 400, 0, "Palatino Linotype") GUICtrlSetColor(-1, 0xFF0000) GUISetState(@SW_SHOW) Global $hLabelWndProc = DllCallbackRegister("LabelWndProc", "long", "hwnd;uint;wparam;lparam") Global $hOldLabelProc = _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, DllCallbackGetPtr($hLabelWndProc)) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _WinAPI_SetWindowLong($hLabel, $GWL_WNDPROC, $hOldLabelProc) DllCallbackFree($hLabelWndProc) GUIDelete() Exit EndSwitch WEnd Func LabelWndProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $WM_LBUTTONDOWN GUICtrlSetState($Radio1, $GUI_CHECKED) GUICtrlSetState($Radio2, $GUI_UNCHECKED) EndSwitch Return _WinAPI_CallWindowProc($hOldLabelProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>EditWndProc Maybe you can use it. Edit: added cleanup of subclassing resources and unchecked 2nd radio button Br, UEZ1 point
-
Take webcam screenshot
Unc3nZureD reacted to rickjames for a topic
Hello, everyone. I believe I have found the reason for having the video source popup with Windows 7 /8... It relates to UAC and Run as Admin approach. If I run the script or compiled .exe as ADMIN, it always works AFTER I have initially selected a default device via that popup box. The good news is that the default device can be pre-configured, as it is simply a registry value in HKLM (which explains why if NOT run as admin - will never save the default selection via the popup, neither will succeed to read the registry if it is already setup)!!! So this is what I have done to figure it out and being able to set the default capture device on other machines to successfully use the webcam UDF and never have the video source popup appear (just remember that it ONLY works when run as admin): 1. Run the script as Admin, got the popup to select a default device as expected (even with only one webcam present); 2. Clicked the OK button - script completed successfully; 3. Used regedit to open and navigate to: HKLMSYSTEMCurrentControlSetControlMediaResourcesmsvideoMSVideo.VFWWDM A new STRING (REG_SZ) Value was created, named "DevicePath" (without the quotes), and its DATA is: ?root#image#0000#{GUID}global ... where GUID is the unique ID of the webcam you have on your device. It can be verified/found in: HKLMSYSTEMCurrentControlSetControlMediaCategories{GUID}Name(REG_SZ)=Capture There are many GUID registry keys there, but the correct one has a VALUE "Name"=Capture One good reference to point me in this direction was here: http://stackoverflow.com/questions/10721085/webcam-video-source-dialog-comes-up So at this point I don't think the script fails to close the dll or disconnect the driver after done...1 point -
Print pdf's and then move to another folder
mLipok reacted to JLogan3o13 for a topic
Perminator, first off welcome to the forum. Secondly, we get that you may be in a rush, but this forum operates on the "Teach a man to fish" model. We help others with their own scripts, rather than having people put in an "urgent" request and someone barfs up code for you. We can certainly assist you with your problem by pointing you in the right direction. Something like this should get you started. It is up to you to loop through your folder and then move the files. Look at _FileListToArray and FileMove in the help file. $oShell = ObjCreate("Shell.Application") $sFullPath = @DesktopDir $sFile = "Proof.pdf" If FileExists($sFullPath) Then $oFolder = $oShell.Namespace($sFullPath) $oItem = $oFolder.ParseName($sFile) EndIf $oItem.InvokeVerbEx("Print")1 point -
Simulating Key Ctrl C & Ctrl V
SkysLastChance reacted to JuanFelipe for a topic
Encontre la solucion, va y copia archivos de Excel y los pega en el espacio que digo... I found the solution, and will copy files from Excel and paste them in the space I want ... Send("{CTRLDOWN}c{CTRLUP}") Send("{CTRLDOWN}v{CTRLUP}")1 point -
First Interface call '?do=embed' frameborder='0' data-embedContent>> By the project you can call methods of classes And Interface through DispCallFunc function I think the project is important for all ... Thanks All project files Other_InterfaceCall.zip InterfaceCall.au3 ;enum $tagCALLCONV Global $CC_FASTCALL = 0 Global $CC_CDECL = 1 Global $CC_MSCPASCAL = $CC_CDECL + 1 Global $CC_PASCAL = $CC_MSCPASCAL Global $CC_MACPASCAL = $CC_PASCAL + 1 Global $CC_STDCALL = $CC_MACPASCAL + 1 Global $CC_FPFASTCALL = $CC_STDCALL + 1 Global $CC_SYSCALL = $CC_FPFASTCALL + 1 Global $CC_MPWCDECL = $CC_SYSCALL + 1 Global $CC_MPWPASCAL = $CC_MPWCDECL + 1 Global $CC_MAX = $CC_MPWPASCAL + 1 ;enum $tagCALLCONV Global $OleAut32 = DllOpen("OleAut32.dll") Global $tagVariant = "USHORT vt;WORD wReserved1;WORD wReserved2;WORD wReserved3;byte union[8]" Global $SizeOfUlong_Ptr = DllStructGetSize(DllStructCreate("ULONG_PTR")) Func InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0,$Type2 = 0,$Param2 = 0 _ ,$Type3 = 0,$Param3 = 0, $Type4 = 0,$Param4 = 0 ,$Type5 = 0 ,$Param5 = 0,$Type6 = 0,$Param6 = 0 _ ,$Type7 = 0,$Param7 = 0, $Type8 = 0,$Param8 = 0,$Type9 = 0,$Param9 = 0,$Type10 = 0,$Param10 = 0 _ ,$Type11= 0,$Param11= 0,$Type12= 0,$Param12= 0,$Type13= 0,$Param13 = 0,$Type14 = 0,$Param14 = 0 _ ,$Type15= 0,$Param15= 0,$Type16= 0,$Param16= 0,$Type17= 0,$Param17 = 0,$Type18 = 0,$Param18 = 0 _ ,$Type19= 0,$Param19= 0,$Type20= 0,$Param20= 0,$Type21= 0,$Param21 = 0,$Type22 = 0,$Param22 = 0 _ ,$Type23= 0,$Param23= 0,$Type24= 0,$Param24= 0,$Type25= 0,$Param25 = 0,$Type26 = 0,$Param26 = 0 _ ,$Type27= 0,$Param27= 0,$Type28= 0,$Param28= 0,$Type29= 0,$Param29 = 0,$Type30 = 0,$Param30 = 0) ;Call Only Virtual Methods Form any Class Or From any Interface ;$MethodNum ==> Virtual Method Number In (Virtual Methods Table) ;See the examples ;-------------------------------------------------------------------;C++ Example1 ;C++ Example1 ;class iClass ;{ ;public: ;void MethodA() ;{ ;MessageBox(0,"MethodA","MSG",0); ;} ;virtual void VirtualMethodB() ;{ ;MessageBox(0,"VirtualMethodB","MSG",0); ;} ;virtual void VirtualMethodC() ;{ ;MessageBox(0,"VirtualMethodC","MSG",0); ;} ;void MethodB() ;{ ;MessageBox(0,"MethodB","MSG",0); ;} ;virtual void VirtualMethodA() ;{ ;MessageBox(0,"VirtualMethodA","MSG",0); ;} ;}; ;-----------------------------------------------------------;Virtual Methods Table ;Virtual Methods Table ;virtual void VirtualMethodB() ==> Virtual Method Number Is 1 ;virtual void VirtualMethodC() ==> Virtual Method Number Is 2 ;virtual void VirtualMethodA() ==> Virtual Method Number Is 3 ;-----------------------------------------------------------;Virtual Methods Table ;-------------------------------------------------------------------;C++ Example1 ;//////////////////////////////////////////////////////////////////////////////// ;-------------------------------------------------------------------;C++ Example2 ;C++ Example2 ;class iClassA ;{ ;public: ;void MethodA() ;{ ;MessageBox(0,"MethodA","MSG",0); ;} ;virtual void VirtualMethodB() ;{ ;MessageBox(0,"VirtualMethodB","MSG",0); ;} ;virtual void VirtualMethodC() ;{ ;MessageBox(0,"VirtualMethodC","MSG",0); ;} ;}; ;class iClassB : public iClassA ;{ ;public: ;void MethodD() ;{ ;MessageBox(0,"MethodD","MSG",0); ;} ;virtual void VirtualMethodF() ;{ ;MessageBox(0,"VirtualMethodF","MSG",0); ;} ;virtual void VirtualMethodE() ;{ ;MessageBox(0,"VirtualMethodE","MSG",0); ;} ;}; ;//////////////////////////////////////////////////////////////////////////////// ;//////////////////////////////////////////////////////////////////////////////// ;------------------------------------------;Virtual Methods Table Of iClassA Class ;Virtual Methods Table Of iClassA Class ;virtual void VirtualMethodB() ==> Virtual Method Number Is 1 ;virtual void VirtualMethodC() ==> Virtual Method Number Is 2 ;------------------------------------------;Virtual Methods Table Of iClassA Class ;//////////////////////////////////////////////////////////////////////////////// ;/////////////////////////////////////////////////////////////////////////////// ;------------------------------------------;Virtual Methods Table Of iClassB Class ;class iClassB : public iClassA ;base class ==> iClassA ;derived class ==> iClassB ;http://msdn.microsoft.com/en-us/library/hzk8a7d3.aspx ;When preceding the name of a base class, the public keyword specifies that the public ;and protected members of the base class are public and protected members, respectively, ;of the derived class. ;------------------------------------------------------------------------------------- ;Virtual Methods Table Of iClassB Class ;virtual void VirtualMethodB() In (iClassA) ==> Virtual Method Number Is 1 ;virtual void VirtualMethodC() In (iClassA) ==> Virtual Method Number Is 2 ;virtual void VirtualMethodF() In (iClassB) ==> Virtual Method Number Is 3 ;virtual void VirtualMethodE() In (iClassB) ==> Virtual Method Number Is 4 ;------------------------------------------;Virtual Methods Table Of iClassB Class ;-------------------------------------------------------------------;C++ Example2 ;//////////////////////////////////////////////////////////////////////////////// if ((@NumParams > 3) And (Mod((@NumParams - 3),2) <> 0)) Then Return SetError(1,0,0) Local $NumParams = ((@NumParams - 3) / 2) Local $nReturn[$NumParams + 1][3], $Variant = 0,$BOOLREF = 0,$RtVariant = 0 Local $Value = "",$DataType = "",$DataTypeNu = 0,$RtTypeNu = 0,$CALLCONV = $CC_STDCALL Local $VARIANTARG = DllStructCreate("PTR[" & $NumParams & "]") Local $VARTYPE = DllStructCreate("WORD[" & $NumParams & "]") $ReturnType = StringUpper($ReturnType) if (StringRight($ReturnType,6) == ";CDECL") Then $ReturnType = StringReplace($ReturnType,";CDECL","") $CALLCONV = $CC_CDECL EndIf For $i = 0 To $NumParams if ($i = 0) Then ; $i = 0 Is Return $DataType = $ReturnType $Value = "" $DataTypeNu = InfaceDataTypeNu($DataType) if @error Then Return SetError(2,0,0) $BOOLREF = @extended $RtTypeNu = $DataTypeNu $Variant = DllStructCreate($tagVariant) $RtVariant = $Variant $nReturn[$i][0] = $Variant DllStructSetData($Variant,"vt",$DataTypeNu) $DataType = StringReplace($DataType,"*","") Else $Value = Eval("Param" & $i) $DataType = Eval("Type" & $i) $DataTypeNu = InfaceDataTypeNu($DataType) if @error Then Return SetError(2,0,0) $BOOLREF = @extended $Variant = DllStructCreate($tagVariant) $nReturn[$i][0] = $Variant DllStructSetData($Variant,"vt",$DataTypeNu) DllStructSetData($VARTYPE,1,$DataTypeNu,$i) DllStructSetData($VARIANTARG,1,DllStructGetPtr($Variant),$i) EndIf $DataType = StringReplace(StringUpper($DataType),"*","") Switch $DataType Case "STR" if ($i = 0) Then $BOOLREF = True ; $i = 0 Is Return Switch $BOOLREF Case True $nReturn[$i][1] = MakByRef() $nReturn[$i][2] = 3 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($nReturn[$i][1])) Case False $StringSt = DllStructCreate("CHAR[" & (StringLen($Value) + 1) & "]") DllStructSetData($StringSt,1,$Value) $nReturn[$i][1] = $StringSt $nReturn[$i][2] = 2 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($StringSt)) EndSwitch Case "WSTR" if ($i = 0) Then $BOOLREF = True ; $i = 0 Is Return Switch $BOOLREF Case True $nReturn[$i][1] = MakByRef() $nReturn[$i][2] = 4 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($nReturn[$i][1])) Case False $StringSt = DllStructCreate("WCHAR[" & (StringLen($Value) + 1) & "]") DllStructSetData($StringSt,1,$Value) $nReturn[$i][1] = $StringSt $nReturn[$i][2] = 2 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($StringSt)) EndSwitch Case "STRUCT" $nReturn[$i][1] = $Value SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($Value)) $nReturn[$i][2] = 0 Case Else Switch $BOOLREF Case True $nReturn[$i][1] = MakByRef($DataType) $nReturn[$i][2] = 1 SetUnionOfVariant($Variant,"ptr",DllStructGetPtr($nReturn[$i][1])) Case False $nReturn[$i][1] = $Value $nReturn[$i][2] = 0 SetUnionOfVariant($Variant,$DataType,$Value) EndSwitch EndSwitch Next Local $oVft = ($SizeOfUlong_Ptr * ($MethodNum - 1));$MethodNum ==> Virtual Method Number In Virtual Methods Table Start From 1 $HRESULT = DllCall($OleAut32,"long","DispCallFunc","ptr",$Inface,"ULONG_PTR",$oVft,"int",$CALLCONV _ ,"WORD",$RtTypeNu,"UINT",$NumParams,"struct*",$VARTYPE,"struct*",$VARIANTARG ,"struct*",$RtVariant) if @error Or $HRESULT[0] <> 0 Then Return SetError(3,0,0) Local $vReturn[($NumParams + 1)] For $i = 0 To $NumParams $Value = $nReturn[$i][1] $IsOutDllStruct = $nReturn[$i][2] if ($i = 0) Then ; $i = 0 Is Return Switch $IsOutDllStruct Case 0 ;WtheOut ByRef $vReturn[$i] = GetUnionOfVariant($RtVariant,$ReturnType) Case 1 ;Wthe ByRef $vReturn[$i] = GetByRefValue($Value) Case 3 ;Wthe ByRef Ans String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),False) Case 4 ;Wthe ByRef UniCode String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),True) EndSwitch Else ; Else Params Switch $IsOutDllStruct Case 0 ;WtheOut ByRef $vReturn[$i] = $Value Case 1 ;Wthe ByRef $vReturn[$i] = GetByRefValue($Value) Case 2 ;WtheOut ByRef Ans Or UniCode String Data Type $vReturn[$i] = DllStructGetData($Value,1) ;Get String From $StringSt Case 3 ;Wthe ByRef Ans String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),False) Case 4 ;Wthe ByRef UniCode String Data Type $vReturn[$i] = StringFromPtr(GetByRefValue($Value),True) EndSwitch EndIf Next Return $vReturn EndFunc Func StringFromPtr($StringPtr,$UniCode = False) if (Not(IsPtr($StringPtr)) Or $StringPtr = Ptr(0)) Then Return SetError(1,0,"") if ($UniCode) Then $StrLen = DllCall("Kernel32.dll","int","lstrlenW","ptr",$StringPtr) if @error Then Return SetError(2,0,"") $StrLen = $StrLen[0] Return DllStructGetData(DllStructCreate("WCHAR[" & ($StrLen + 1) & "]",$StringPtr),1) Else $StrLen = DllCall("Kernel32.dll","int","lstrlenA","ptr",$StringPtr) if @error Then Return SetError(2,0,"") $StrLen = $StrLen[0] Return DllStructGetData(DllStructCreate("CHAR[" & ($StrLen + 1) & "]",$StringPtr),1) EndIf EndFunc Func InfaceDataTypeNu($DataType) ;VARIANT structure ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221627%28v=vs.85%29.aspx ;VARENUM enumeration ;http://msdn.microsoft.com/en-us/library/windows/desktop/ms221170%28v=vs.85%29.aspx Local $DataTypeNu , $VT_BYREF = 0x4000 $DataType = StringUpper($DataType) Switch $DataType Case "STRUCT*","STR","WSTR" $DataType = "PTR" Case "STR*","WSTR*" $DataType = "PTR*" EndSwitch Local $BOOLREF = (StringInStr($DataType,"*") <> 0) $DataType = StringReplace($DataType,"*","") Switch $DataType Case "NONE" $DataTypeNu = 24 Case "BYTE","BOOLEAN" $DataTypeNu = 17 Case "SHORT" $DataTypeNu = 2 Case "USHORT","WORD" $DataTypeNu = 18 Case "INT","LONG","BOOL" $DataTypeNu = 22 Case "UINT","ULONG","DWORD" $DataTypeNu = 23 Case "INT64" $DataTypeNu = 20 Case "UINT64" $DataTypeNu = 21 Case "FLOAT" $DataTypeNu = 4 Case "DOUBLE" $DataTypeNu = 5 ;--------------------------------------------------------------------------------------------- ;_____________ C++ 6.0 wtypes.h __________ ;VT_I8 = 20 ;VT_UI8 = 21 ;VT_I4 = 3 ;VT_UI4 = 19 ;#ifdef _WIN64 ;#define VT_INT_PTR VT_I8 ;#define VT_UINT_PTR VT_UI8 ;#else ;#define VT_INT_PTR VT_I4 ;#define VT_UINT_PTR VT_UI4 ;#endif ;_____________ C++ 6.0 wtypes.h __________ ; _WIN64 Macro Defined for applications for Win64. ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt. Case "HWND" ;32bit(4bytes) integer $DataTypeNu = 3 ;VT_I4 Case "HANDLE" ;32bit(4bytes) integer $DataTypeNu = 3 ;VT_I4 Case "LPARAM","INT_PTR","LONG_PTR","LRESULT" ;32 or 64bit signed integer if (@AutoItX64) Then $DataTypeNu = 20 ;VT_I8 Else $DataTypeNu = 3 ;VT_I4 EndIf Case "PTR","UINT_PTR","ULONG_PTR","DWORD_PTR","WPARAM" ;32 or 64bit unsigned integer if (@AutoItX64) Then $DataTypeNu = 21 ;VT_UI8 Else $DataTypeNu = 19 ;VT_UI4 EndIf ;_____________ C++ 6.0 wtypes.h __________ ;VT_I8 = 20 ;VT_UI8 = 21 ;VT_I4 = 3 ;VT_UI4 = 19 ;#ifdef _WIN64 ;#define VT_INT_PTR VT_I8 ;#define VT_UINT_PTR VT_UI8 ;#else ;#define VT_INT_PTR VT_I4 ;#define VT_UINT_PTR VT_UI4 ;#endif ;_____________ C++ 6.0 wtypes.h __________ ; _WIN64 Macro Defined for applications for Win64. ;@AutoItX64 Returns 1 if the script is running under the native x64 version of AutoIt ;--------------------------------------------------------------------------------------------- Case Else Return SetError(1,0,-1) EndSwitch if ($BOOLREF) Then $DataTypeNu = BitOR($VT_BYREF,$DataTypeNu) Return SetError(0,$BOOLREF,$DataTypeNu) EndFunc Func MakByRef($DataType = "ptr") Return DllStructCreate(String($DataType & " ByRef")) EndFunc Func GetByRefValue($ByRefSt) Return DllStructGetData($ByRefSt,1) EndFunc Func SetUnionOfVariant($VariantSt,$DataType,$Value) Return DllStructSetData(DllStructCreate($DataType,DllStructGetPtr($VariantSt,"union")),1,$Value) EndFunc Func GetUnionOfVariant($VariantSt,$DataType) Return DllStructGetData(DllStructCreate($DataType,DllStructGetPtr($VariantSt,"union")),1) EndFunc Func CLSIDFromString($psz) $GUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]") $Oleerror = DllCall("Ole32.dll","int","CLSIDFromString","WSTR",$psz,"struct*",$GUID) if @error Or $Oleerror[0] <> 0 Then Return SetError(1,0,0) Return SetError(0,0,$Oleerror[2]) EndFunc Func IIDFromString($psz) $GUID = DllStructCreate("ulong Data1;ushort Data2;ushort Data3;byte Data4[8]") $Oleerror = DllCall("Ole32.dll","int","IIDFromString","WSTR",$psz,"struct*",$GUID) if @error Or $Oleerror[0] <> 0 Then Return SetError(1,0,0) Return SetError(0,0,$Oleerror[2]) EndFunc IPictureInterface.au3 #include "InterfaceCall.au3" #include <WinAPI.au3> ;IPicture interface---------------------------------------------------------;IPicture interface ;EXTERN_C const IID IID_IPicture; ; ; ; ;#if defined(__cplusplus) && !defined(CINTERFACE) ; ; ; ; MIDL_INTERFACE("7BF80980-BF32-101A-8BBB-00AA00300CAB") ; ; IPicture : public IUnknown ; ; { ; ; public: ; ; virtual HRESULT STDMETHODCALLTYPE get_Handle( ; ; /* [out] */ OLE_HANDLE __RPC_FAR *pHandle) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_hPal( ; ; /* [out] */ OLE_HANDLE __RPC_FAR *phPal) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Type( ; ; /* [out] */ SHORT __RPC_FAR *pType) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Width( ; ; /* [out] */ OLE_XSIZE_HIMETRIC __RPC_FAR *pWidth) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Height( ; ; /* [out] */ OLE_YSIZE_HIMETRIC __RPC_FAR *pHeight) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE Render( ; ; /* [in] */ HDC hDC, ; ; /* [in] */ LONG x, ; ; /* [in] */ LONG y, ; ; /* [in] */ LONG cx, ; ; /* [in] */ LONG cy, ; ; /* [in] */ OLE_XPOS_HIMETRIC xSrc, ; ; /* [in] */ OLE_YPOS_HIMETRIC ySrc, ; ; /* [in] */ OLE_XSIZE_HIMETRIC cxSrc, ; ; /* [in] */ OLE_YSIZE_HIMETRIC cySrc, ; ; /* [in] */ LPCRECT pRcWBounds) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE set_hPal( ; ; /* [in] */ OLE_HANDLE hPal) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_CurDC( ; ; /* [out] */ HDC __RPC_FAR *phDC) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE SelectPicture( ; ; /* [in] */ HDC hDCIn, ; ; /* [out] */ HDC __RPC_FAR *phDCOut, ; ; /* [out] */ OLE_HANDLE __RPC_FAR *phBmpOut) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_KeepOriginalFormat( ; ; /* [out] */ BOOL __RPC_FAR *pKeep) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE put_KeepOriginalFormat( ; ; /* [in] */ BOOL keep) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE PictureChanged( void) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE SaveAsFile( ; ; /* [in] */ LPSTREAM pStream, ; ; /* [in] */ BOOL fSaveMemCopy, ; ; /* [out] */ LONG __RPC_FAR *pCbSize) = 0; ; ; ; ; virtual HRESULT STDMETHODCALLTYPE get_Attributes( ; ; /* [out] */ DWORD __RPC_FAR *pDwAttr) = 0; ; ; ; ; }; ;IPicture interface---------------------------------------------------------;IPicture interface ;------------------------------- ;IPicture : public IUnknown ;-------------------------------- ;base class ==> IUnknown ;derived class ==> IPicture ;--------------------------------- ;http://msdn.microsoft.com/en-us/library/hzk8a7d3.aspx ;When preceding the name of a base class, the public keyword specifies that the public ;and protected members of the base class are public and protected members, respectively, ;of the derived class. ;--------------------------------- ;IUnknown interface---------------------------------------------------------;IUnknown interface ;#if (_MSC_VER >= 1100) && defined(__cplusplus) && !defined(CINTERFACE) ; ; EXTERN_C const IID IID_IUnknown; ; ; extern "C++" ; ; { ; ; MIDL_INTERFACE("00000000-0000-0000-C000-000000000046") ; ; IUnknown ; ; { ; ; public: ; ; BEGIN_INTERFACE ; ; virtual HRESULT STDMETHODCALLTYPE QueryInterface( ; ; /* [in] */ REFIID riid, ; ; /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject) = 0; ; ; ; ; virtual ULONG STDMETHODCALLTYPE AddRef( void) = 0; ; ; ; ; virtual ULONG STDMETHODCALLTYPE Release( void) = 0; ; ; ; ; template<class Q> ; ; HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp) ; ; { ; ; return QueryInterface(__uuidof(Q), (void **)pp); ; ; } ; ; ; ; END_INTERFACE ; ; }; ;IUnknown interface---------------------------------------------------------;IUnknown interface ;------------------------------------------;Virtual Methods Table Of IPicture interface ;Virtual Methods Table Of IPicture interface ;virtual HRESULT QueryInterface() In (IUnknown interface) ==> Virtual Method Number Is 1 ;virtual ULONG AddRef() In (IUnknown interface) ==> Virtual Method Number Is 2 ;virtual ULONG Release() In (IUnknown interface) ==> Virtual Method Number Is 3 ;virtual HRESULT get_Handle() In (IPicture interface) ==> Virtual Method Number Is 4 ;virtual HRESULT get_hPal() In (IPicture interface) ==> Virtual Method Number Is 5 ;virtual HRESULT get_Type() In (IPicture interface) ==> Virtual Method Number Is 6 ;virtual HRESULT get_Width() In (IPicture interface) ==> Virtual Method Number Is 7 ;virtual HRESULT get_Height() In (IPicture interface) ==> Virtual Method Number Is 8 ;virtual HRESULT Render() In (IPicture interface) ==> Virtual Method Number Is 9 ;virtual HRESULT set_hPal() In (IPicture interface) ==> Virtual Method Number Is 10 ;virtual HRESULT get_CurDC() In (IPicture interface) ==> Virtual Method Number Is 11 ;virtual HRESULT SelectPicture() In (IPicture interface) ==> Virtual Method Number Is 12 ;virtual HRESULT get_KeepOriginalFormat() In (IPicture interface) ==> Virtual Method Number Is 13 ;virtual HRESULT put_KeepOriginalFormat() In (IPicture interface) ==> Virtual Method Number Is 14 ;virtual HRESULT PictureChanged() In (IPicture interface) ==> Virtual Method Number Is 15 ;virtual HRESULT SaveAsFile() In (IPicture interface) ==> Virtual Method Number Is 16 ;virtual HRESULT get_Attributes() In (IPicture interface) ==> Virtual Method Number Is 17 ;The Count Of Virtual Methods Is 17 ;------------------------------------------;Virtual Methods Table Of IPicture interface $IPicture = GetIPictureInterface("Image.jpg") ;-------------------------------------------------- ;-------------------------------------------------- ;////////////////////////////////////////////////// ;-------------------------------------------------- ; C++ virtual HRESULT STDMETHODCALLTYPE get_Handle(OLE_HANDLE __RPC_FAR *pHandle); ;get_Handle() Virtual Method Number Is 4 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 4 // Virtual Method Number ;$Type1 = "ptr*" Out Ptr ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",4,"ptr*",0) ;Return Array Of DllCallAddress if Not @error Then $Handle = $Rt[1] MsgBox(0,"get_Handle","Image Handle Is " & $Handle) EndIf ;-------------------------------------------------- ;////////////////////////////////////////////////// ;C ++ virtual HRESULT STDMETHODCALLTYPE get_Type(SHORT __RPC_FAR *pType); ;get_Type() Virtual Method Number Is 6 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 6 // Virtual Method Number ;$Type1 = "SHORT*" Out SHORT ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",6,"SHORT*",0) ;Return Array Of DllCallAddress if Not @error Then $Type = $Rt[1] MsgBox(0,"get_Type()","Image Type Is " & $Type) EndIf ;virtual HRESULT STDMETHODCALLTYPE get_Width(OLE_XSIZE_HIMETRIC __RPC_FAR *pWidth); ;get_Width() Virtual Method Number Is 7 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 7 // Virtual Method Number ;$Type1 = "LONG*" Out LONG Or Out OLE_XSIZE_HIMETRIC ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",7,"LONG*",0) ;Return Array Of DllCallAddress if Not @error Then $Width = $Rt[1] $Width = MulDiv($Width,GetDeviceCaps(GetDC(0),88),2540); 88 => LOGPIXELSX MsgBox(0,"get_Width()","Image Width Is " & $Width) EndIf ;C++ virtual HRESULT STDMETHODCALLTYPE get_Height(OLE_YSIZE_HIMETRIC __RPC_FAR *pHeight) ;get_Height() Virtual Method Number Is 8 ;InterfaceCall($Inface,$ReturnType,$MethodNum,$Type1 = 0,$Param1 = 0) ;$Inface = $IPicture ;$ReturnType = "Long" Or HRESULT ;$MethodNum = 8 // Virtual Method Number ;$Type1 = "LONG*" Out LONG Or Out OLE_YSIZE_HIMETRIC ;$Param1 = 0 $Rt = InterfaceCall($IPicture,"long",8,"LONG*",0) ;Return Array Of DllCallAddress if Not @error Then $Height = $Rt[1] $Height = MulDiv($Height,GetDeviceCaps(GetDC(0),90),2540); 90 => LOGPIXELSY MsgBox(0,"get_Height()","Image Height Is " & $Height) EndIf Func GetIPictureInterface($ImageFileName) Local $nBytes $FileSize = FileGetSize($ImageFileName) + 1 if @error Then Return SetError(1,0,0) $tBuffer = DllStructCreate("byte[" & $FileSize & "]") $hFile = _WinAPI_CreateFile($ImageFileName, 2, 2) if @error Then Return SetError(2,0,0) _WinAPI_ReadFile($hFile,DllStructGetPtr($tBuffer),$FileSize,$nBytes) if @error Then Return SetError(3,0,0) _WinAPI_CloseHandle($hFile) $LPVOID = DllStructGetPtr($tBuffer) $hMem = GlobalAlloc(0x0042,$FileSize) ;$GHND = 0x0042 if @error Then SetError(4,0,0) $hLock = GlobalLock($hMem) if @error Then GlobalFree($hMem) Return SetError(5,0,0) EndIf MoveMemory($LPVOID,$hLock,$FileSize) $lpstream = CreateStreamOnHGlobal($hLock,True) if @error Then SetError(6,0,0) $riid = IIDFromString("{7BF80980-BF32-101A-8BBB-00AA00300CAB}") if @error Then SetError(7,0,0) $HRESULT = DllCall($OleAut32,"LONG","OleLoadPicture","PTR",$lpstream,"LONG", _ $FileSize,"BOOL",True,"ptr",DllStructGetPtr($riid),"PTR*",0) if @error Or $HRESULT[0] <> 0 Then GlobalUnlock($hMem) GlobalFree($hMem) Return SetError(8,0,0) EndIf GlobalUnlock($hMem) GlobalFree($hMem) $IPicture = $HRESULT[5] Return SetError(0,0,$IPicture) EndFunc Func GlobalAlloc($uFlags,$dwBytes) $HGLOBAL = DllCall("Kernel32.dll","ptr","GlobalAlloc","UINT",$uFlags,"ULONG_PTR",$dwBytes) if @error Or $HGLOBAL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$HGLOBAL[0]) EndFunc Func GlobalLock($hMem) $LPVOID = DllCall("Kernel32.dll","ptr","GlobalLock","ptr",$hMem) if @error Or $LPVOID[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$LPVOID[0]) EndFunc Func GlobalUnlock($hMem) $BOOL = DllCall("Kernel32.dll","BOOL","GlobalUnlock","ptr",$hMem) if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0) Return SetError(0,$BOOL[0]) EndFunc Func GlobalFree($hMem) $HGLOBAL = DllCall("Kernel32.dll","ULONG_PTR","GlobalFree","ptr",$hMem) if (@error Or ($HGLOBAL[0])) Then Return SetError(1,0,$HGLOBAL[0]) Return SetError(0,0,0) EndFunc Func CreateStreamOnHGlobal($hGlobal,$fDeleteOnRelease) $WINOLE = DllCall("Ole32.dll","PTR","CreateStreamOnHGlobal","ptr",$hGlobal,"BOOL",$fDeleteOnRelease _ ,"PTR*",0) if @error Or $WINOLE[0] <> 0 Then Return SetError(1,0,0) Return SetError(0,0,$WINOLE[3]) EndFunc Func MulDiv($nNumber,$nNumerator,$nDenominator) $Rt = DllCall("Kernel32.dll","int","MulDiv","int",$nNumber,"int",$nNumerator,"int",$nDenominator) Return $Rt[0] EndFunc Func GetDeviceCaps($hdc,$nIndex) $Rt = DllCall("Gdi32.dll","int","GetDeviceCaps","ptr",$hdc,"int",$nIndex) Return $Rt[0] EndFunc Func GetDC($hWnd) $HDC = DllCall("User32.dll","ptr","GetDC","ptr",$hWnd) if @error Or $HDC[0] = 0 Then Return SetError(1,0,0) Return SetError(0,0,$HDC[0]) EndFunc Func MoveMemory($Source,$Destination,$Length) DllCall("Kernel32.dll","none","RtlMoveMemory","PTR",$Destination,"PTR",$Source,"INT",$Length) EndFunc IRichEditOleInterface.au3 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiRichEdit.au3> #include <SendMessage.au3> #include "InterfaceCall.au3" $hGui = GUICreate("InsertObject Example",500,390) $hRichEdit = _GUICtrlRichEdit_Create($hGui,"", 10, 10,480,300, _ BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) $Button1 = GUICtrlCreateButton("InsertObject",10,320,200,50) GUICtrlSetFont(-1,18,600) GUISetState() InsertObject($hRichEdit,@ScriptDir & "\Image.bmp") While True $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE _GUICtrlRichEdit_Destroy($hRichEdit) Exit Case $iMsg = $Button1 $var = FileOpenDialog("", @MyDocumentsDir & "\","All (*.*)", 1 + 4) if Not @error Then InsertObject($hRichEdit,$var) EndIf EndSelect WEnd ;http://msdn.microsoft.com/en-us/library/windows/desktop/dd387916%28v=vs.85%29.aspx ;Use a Rich Edit Interface ;Rich edit controls expose some of their functionality through Component Object Model ;(COM) interfaces. By obtaining an interface from a control, you gain the ability to ;work with other objects within the control. You can obtain this interface by sending ;the EM_GETOLEINTERFACE message. From the IRichEditOle interface, you can then obtain ;interfaces used in the Text Object Model. ;Another interface, IRichEditOleCallback, is implemented by applications to define the ;behavior of the control when it interacts with objects. ;Insert an Object into a Rich Edit Control ;The following code example inserts a file object into a rich edit control. If a program ;is associated with the file type on the user's machine (for example, Microsoft Excel for ;an .xls file), the contents of the file display in the control; otherwise, an icon appears. Func InsertObject($hRichEdit,$pszFileName) Local $hr = 0, $Rt = 0 , $EM_GETOLEINTERFACE = 1084 , $pRichEditOle = 0 $pRichEditOle = _SendMessage($hRichEdit,$EM_GETOLEINTERFACE,0,0,4,"wparam","ptr*") if ($pRichEditOle == 0) Then return FALSE; EndIf Local $pLockBytes = 0 $hr = DllCall("Ole32.dll","long","CreateILockBytesOnHGlobal","ptr",0,"BOOL",True,"Ptr*",0) if (@error Or $hr[0] <> 0) Then return FALSE; EndIf $pLockBytes = $hr[3] Local $pStorage = 0 $hr = DllCall("Ole32.dll","long","StgCreateDocfileOnILockBytes","ptr",$pLockBytes, _ "DWORD",BitOR(0x00000010,0x00001000,0x00000002), _ "DWORD",0,"Ptr*",0) if (@error Or $hr[0] <> 0) Then return FALSE; EndIf $pStorage = $hr[4] $tagFORMATETC = "int cfFormat;ptr ptd;DWORD dwAspect;LONG lindex;DWORD tymed" $formatEtc = DllStructCreate($tagFORMATETC) DllStructSetData($formatEtc,"cfFormat",0) DllStructSetData($formatEtc,"ptd",0) DllStructSetData($formatEtc,"dwAspect",1) DllStructSetData($formatEtc,"lindex",-1) DllStructSetData($formatEtc,"tymed",0) Local $pClientSite ;hr = pRichEditOle->GetClientSite(&pClientSite); ;GetClientSite Virtual Method Number Of GetClientSite Is 4 in (IRichEditOle interface) $hr = InterfaceCall($pRichEditOle,"long",4,"ptr*",0) if (@error Or $hr[0] <> 0) Then return FALSE; EndIf $pClientSite = $hr[1] Local $pUnk,$clsid = CLSIDFromString("{00000000-0000-0000-0000-000000000000}") Local $IID_IUnknown = IIDFromString("{00000000-0000-0000-C000-000000000046}") $hr = DllCall("Ole32.dll","long","OleCreateFromFile","ptr",DllStructGetPtr($clsid),"wstr", _ $pszFileName,"ptr",DllStructGetPtr($IID_IUnknown),"DWORD",1,"ptr",DllStructGetPtr($formatEtc) _ ,"ptr",$pClientSite,"ptr",$pStorage,"Ptr*",0) ;pClientSite->Release(); ;IOleClientSite interface inherits from the IUnknown Or IOleClientSite : public IUnknown ;Release() Virtual Method Number Of Release() Is 3 In (IOleClientSite interface) InterfaceCall($pClientSite,"long",3) if ($hr[0] <> 0) Then return FALSE; EndIf $pUnk = $hr[8] Local $pObject,$IID_IOleObject = IIDFromString("{00000112-0000-0000-C000-000000000046}") ;hr = pUnk->QueryInterface(IID_IOleObject, (void**)&pObject); ;New pUnk (IOleObject) interface inherits from the IUnknown Or IOleObject : public IUnknown ;QueryInterface() Virtual Method Number Of QueryInterface() Is 1 In (IOleObject) $hr = InterfaceCall($pUnk,"long",1,"ptr",DllStructGetPtr($IID_IOleObject),"ptr*",0) ;Release() Virtual Method Number Of Release() Is 3 In (IOleObject interface) ;pUnk->Release(); InterfaceCall($pUnk,"long",3) if ($hr[0] <> 0) Then return FALSE; EndIf $pObject = $hr[2] DllCall("Ole32.dll","long","OleSetContainedObject","ptr",$pObject,"BOOL",True) $tagREOBJECT = "DWORD cbStruct;LONG cp;ulong Data1;ushort Data2;ushort Data3;byte Data4[8]" & _ ";ptr poleobj;ptr pstg;ptr polesite;long x;long y;DWORD dvaspect;DWORD dwFlags;DWORD dwUser" $reobject = DllStructCreate($tagREOBJECT) DllStructSetData($reobject,"cbStruct",DllStructGetSize($reobject)) ;hr = pObject->GetUserClassID(&clsid); ;GetUserClassID Virtual Method Number Of GetUserClassID Is 16 in (IOleObject interface) $hr = InterfaceCall($pObject,"long",16,"ptr",DllStructGetPtr($clsid)) if (@error Or $hr[0] <> 0) Then ;pObject->Release(); ;Release() Virtual Method Number Of Release() Is 3 In (IOleObject interface) InterfaceCall($pObject,"long",3) return FALSE EndIf MoveMemory(DllStructGetPtr($clsid),DllStructGetPtr($reobject) + 8,16) ;8 ==> SizeOf "DWORD cbStruct;LONG cp;" ;16 ==> sizeOf $clsid DllStructSetData($reobject,"cp",-1) DllStructSetData($reobject,"dvaspect",1) DllStructSetData($reobject,"dwFlags",BitOR(0x00000001,0x00000002)) DllStructSetData($reobject,"dwUser",0) DllStructSetData($reobject,"poleobj",$pObject) DllStructSetData($reobject,"polesite",$pClientSite) DllStructSetData($reobject,"pstg",$pStorage) $SIZEL = DllStructCreate("long;long"); DllStructSetData($reobject,"SIZEL",DllStructGetPtr($SIZEL)) _SendMessage($hRichEdit, 0xB1, 0, -1);EM_SETSEL $Rt = _SendMessage($hRichEdit, 0xB0,0,0,-1,"DWORD*","DWORD*");EM_GETSEL Local $dwStart = $Rt[3], $dwEnd = $Rt[4] _SendMessage($hRichEdit,0xB1, $dwEnd+1, $dwEnd+1);EM_SETSEL _SendMessage($hRichEdit, 0xC2, TRUE,@CRLF,0,"BOOL","wstr");EM_REPLACESEL ;hr = pRichEditOle->InsertObject(&reobject); ;InsertObject Virtual Method Number Of InsertObject Is 8 in (IRichEditOle interface) $hr = InterfaceCall($pRichEditOle,"long",8,"ptr",DllStructGetPtr($reobject)) ;pObject->Release(); ;Release() Virtual Method Number Of Release() Is 3 In (IOleObject interface) InterfaceCall($pObject,"long",3) ;pRichEditOle->Release(); ;Release() Virtual Method Number Of Release() Is 3 In (IRichEditOle interface) InterfaceCall($pRichEditOle,"long",3) if ($hr[0] <> 0) Then return FALSE; EndIf return TRUE; EndFunc Func MoveMemory($Source,$Destination,$Length) DllCall("Kernel32.dll","none","RtlMoveMemory","PTR",$Destination,"PTR",$Source,"INT",$Length) EndFunc1 point
-
No...not like that...sorry I can't explained it in detail, because my english is not good.. this is the sample code and I hope you understand ; ---------------------------------------------------------------------------- ; Set Hotkey for All CD-ROM (WIN+ALT+1 for First CD-ROM...) ; ---------------------------------------------------------------------------- $var = DriveGetDrive( "CDROM" ) If NOT @error Then For $i = 1 to $var[0] $setting = "#!" & $i $DriveLetter = $var[$i] HotKeySet($setting, "OpenCDROM($DriveLetter)") Next EndIf ; ---------------------------------------------------------------------------- Func OpenCDROM($Drive) MsgBox(64, "Try", $Drive) EndFunc so, If I have 10 CD-Roms or 100 CD-Roms, I don't care...the code above can handle it (if AutoIt support function parameter in HotKeySet)... Now, is it clear?1 point