neity Posted August 2, 2010 Share Posted August 2, 2010 expandcollapse popupNot known to be documented by Microsoft -------------------------------------------------------------------------------- As I was try to find what .DLL I should use for my app I came to find this API calls ********* Path functions ******************** Declare Function SHGetExtension Lib "shell32" Alias "#31" _ (ByVal szPath As String) As Long Returns pointer to the last dot in szPath and the string following it (includes the dot with the extension). Returns 0 if szPath contains no dot. For the function to succeed, szPath should be null terminated and be allocated to MAX_PATH bytes (260). Does not check szPath for validity. (could be called "GetStrAtLastDot") -------------------------------------------------------------------------------- Declare Function SHAddBackslash Lib "shell32" Alias "#32" _ (ByVal szPath As String) As Long Inserts a backslash before the first null char in szPath. szPath is unchanged if it already contains a backslash before the first null char or contains no null char at all. Returns pointer to ??? Does not check szPath for validity. (the name almost fits...) -------------------------------------------------------------------------------- Declare Function SHGetFileName Lib "shell32" Alias "#34" _ (ByVal szPath As String) As Long Returns a pointer to the string in szPath after the last backslash. Returns 0 if szPath contains no backslash or no char follows the last backslash. For the function to succeed, szPath should be null terminated and be allocated to MAX_PATH bytes (260). Does not check szPath for validity. (could be called "GetStrAfterLastBackslash") -------------------------------------------------------------------------------- Declare Function SHGetPath Lib "shell32" Alias "#35" _ (ByVal szPath As String) As Long Returns a pointer to the string in szPath before the last backslash. Returns 0 if szPath contains no backslash or no char follows the last backslash. For the function to succeed, szPath should be null terminated and be allocated to MAX_PATH bytes (260). Does not check szPath for validity. (could be called "GetStrBeforeLastBackslash") -------------------------------------------------------------------------------- Declare Function SHPathIsRelative Lib "shell32" Alias "#40" _ (ByVal szPath As String) As Long Returns non-zero if szPath does not evaluate to a UNC path (if either the first char is not a backslash "\" or the 2nd char is not a colon ":"). Does not check szPath for validity. (the name almost fits...) -------------------------------------------------------------------------------- Declare Function SHPathIsExe Lib "shell32" Alias "#43" _ (ByVal szPath As String) As Long Returns non-zero if szPath has an executable extension (if last 4 char are either ".exe", ".com", ".bat" or ".pif"). Does not check szPath for validity. (could have been called "HasExeExtension") -------------------------------------------------------------------------------- Declare Function SHFileExists Lib "shell32" Alias "#45" _ (ByVal szPath As String) As Long Returns non-zero if szPath is valid absolute UNC path. Accepts file, folder or network paths. Returns True for a relative path only if it exists in the current directory. (the name actually fits...) -------------------------------------------------------------------------------- Declare Function SHGetPathArgs Lib "shell32" Alias "#52" _ (ByVal szPath As String) As Long Returns a pointer to the string after first space in szPath. Returns null pointer if szPath contains no space or no char following the first space. For the function to succeed, szPath should be null terminated and be allocated to MAX_PATH bytes (260). Does not check szPath for validity. (could be called "GetStrAfterFirstSpace") -------------------------------------------------------------------------------- Declare Function SHAddPathQuotes Lib "shell32" Alias "#55" _ (ByVal szPath As String) As Long Returns a pointer to a string embraced in quotes if the original passed string contained a space. Returns the original string otherwise. Does not check szPath for validity. (could be called "AddQuotesIfPathHasASpace") -------------------------------------------------------------------------------- Declare Function SHRemovePathQuotes Lib "shell32" Alias "#56" _ (ByVal szPath As String) As Long Returns a pointer to a string without embracing quotes if the original passed string contained was originally quoted. Returns the original string otherwise. Does not check szPath for validity. (could be called "RemoveQuotesIfPathHasASpace") -------------------------------------------------------------------------------- Declare Function SHGetShortPathName Lib "shell32" Alias "#92" _ (ByVal szPath As String) As Long Fills szPath with its DOS (8.3) file system string. If successful, returns non-zero (sometimes is a pointer to szPath, sometimes not!) Returns zero if path is invalid. szPath must be a valid, absolute path. Returns non-zero for a relative path only if it exists in the current directory. For the function to work correctly, szPath should be null terminated and be allocated to MAX_PATH bytes (260). (the name definitely fits.) How to call these functions?I write these code: Func _WINAPI_SHGetExtension($path) $aRet = DllCall("shell32.dll", "dword_ptr",31,"str", $path) If @error Then $aRet = 1 ; $text = Chr($aRet[0] ) Return $aRet EndFunc Func _WINAPI_SHAddBackslash($path) $aRet = DllCall("shell32.dll", "long",32,"str", $path) If @error Then Return SetError(@error, @extended, False) Return $aRet EndFunc Func _WINAPI_SHPathIsRelative($path) $aRet = DllCall("shell32.dll", "long",40,"str", $path) If @error Then Return SetError(@error, @extended, False) Return $aRet EndFunc but return Value is digit,why?? Link to comment Share on other sites More sharing options...
trancexx Posted August 2, 2010 Share Posted August 2, 2010 You have several issues in your code. Since DllCall() returns array it would be better to return the actual result of the function and not the whole array. Second is if there is no documentation for the function then it's not meant to be called by you. There are good reasons why is that so.Function you mention are so called "Path functions". Description for path functions can be found here. As you can see all is documented. They are exported by shlwapi.dll for public use. Also there are "string functions" available and so on...This is the proper way of using them in AutoIt:; Your function: ConsoleWrite(_WINAPI_SHGetExtension("aa.exe") & @CRLF) ; Proper function: ConsoleWrite(_PathFindExtension("aa.exe") & @CRLF) Func _WINAPI_SHGetExtension($sPath) $aRet = DllCall("shell32.dll", "wstr", 31, "wstr", $sPath) If @error Then Return "" Return $aRet[0] EndFunc ;==>_WINAPI_SHGetExtension Func _PathFindExtension($sPath) $aRet = DllCall("shlwapi.dll", "wstr", "PathFindExtensionW", "wstr", $sPath) ; suffix W is for the unicode version of the function If @error Then Return "" Return $aRet[0] EndFunc ;==>_PathFindExtensionNow, this is important; don't use that functions in AutoIt. Not because they are not good, but because in AutoIt they have very little sense. Much (much!) better is to use StringRegExp() and related functions. Something like this:ConsoleWrite(StringRegExpReplace("aa.exe", ".*\.", ".") & @CRLF) ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
neity Posted August 2, 2010 Author Share Posted August 2, 2010 expandcollapse popupFunc _WINAPI_SHAddBackslash($spath) Local $tData = DllStructCreate('wchar[1024]') DllStructSetData($tData, 1, $sPath) $Ret = DllCall("shell32.dll", "long",32,"ptr", DllStructGetPtr($tData)) If @error Then Return SetError(@error, @extended, False) Local $tResult = DllStructCreate('wchar[1024]', $Ret[1]) Return DllStructGetData($tResult, 1) ; Return $Ret EndFunc Func _WINAPI_SHPathIsExe($spath) Local $tData = DllStructCreate('wchar[1024]') DllStructSetData($tData, 1, $sPath) $Ret = DllCall("shell32.dll", "bool",43,"ptr", DllStructGetPtr($tData)) If @error Then Return SetError(@error, @extended, False) Local $tResult = DllStructCreate('wchar[1024]', $Ret[0]) Return DllStructGetData($tResult, 1) EndFunc Func _WINAPI_SHPathIsRelative($spath) Local $tData = DllStructCreate('wchar[1024]') DllStructSetData($tData, 1, $sPath) $Ret = DllCall("shell32.dll", "long",40,"ptr", DllStructGetPtr($tData)) If @error Then Return SetError(@error, @extended, False) Local $tResult = DllStructCreate('wchar[1024]', $Ret[0]) Return DllStructGetData($tResult, 1) EndFunc Func _WINAPI_SHFileExists($spath) Local $tData = DllStructCreate('wchar[1024]') DllStructSetData($tData, 1, $sPath) $Ret = DllCall("shell32.dll", "bool",45,"ptr", DllStructGetPtr($tData)) If @error Then Return SetError(@error, @extended, False) Local $tResult = DllStructCreate('wchar[1024]', $Ret[0]) Return DllStructGetData($tResult, 1) EndFunc Func _WINAPI_SHGetPathArgs($spath) Local $tData = DllStructCreate('wchar[1024]') DllStructSetData($tData, 1, $sPath) $Ret = DllCall("shell32.dll", "long",52,"str", DllStructGetPtr($tData)) If @error Then Return SetError(@error, @extended, False) Local $tResult = DllStructCreate('wchar[1024]', $Ret[0]) Return DllStructGetData($tResult, 1) EndFunc Func _WINAPI_SHGetShortPathName($spath) $aRet = DllCall("shell32.dll", "wstr",92,"wstr", $sPath) If @error Then Return SetError(@error, @extended, False) Return $aRet[0] EndFunc call these function,exit code -1073741819,why? Link to comment Share on other sites More sharing options...
trancexx Posted August 2, 2010 Share Posted August 2, 2010 Because you made a mistake. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now