Pavel Posted December 17, 2006 Posted December 17, 2006 Hi, Can anyone explain me, why thic function is not working ?? Func _get_computer_name() Local $MAX_COMPUTERNAME_LENGTH = 15 Local $x = DllCall("kernel32.dll","int","GetComputerName","wstr","","int",$MAX_COMPUTERNAME_LENGTH + 1) If Not @error And $x[0] <> 0 Then Return $x[2] EndFunc Func _get_computer_name() Local $MAX_COMPUTERNAME_LENGTH = 15 Local $dll_struct = DllStructCreate("char[" & $MAX_COMPUTERNAME_LENGTH + 1 & "]") Local $x = DllCall("kernel32.dll","int","GetComputerName","char",$dll_struct,"int",$MAX_COMPUTERNAME_LENGTH + 1) Return DllStructGetData($dll_Struct,1) EndFunc I found it in MSDN : BOOL GetComputerName( LPTSTR lpBuffer, LPDWORD lpnSize );
BigDod Posted December 17, 2006 Posted December 17, 2006 Why re-invent the wheel $name=@ComputerName MsgBox(0,"Computer Name is",$name) Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
martin Posted December 17, 2006 Posted December 17, 2006 (edited) Hi, Can anyone explain me, why thic function is not working ?? Func _get_computer_name() Local $MAX_COMPUTERNAME_LENGTH = 15 Local $x = DllCall("kernel32.dll","int","GetComputerName","wstr","","int",$MAX_COMPUTERNAME_LENGTH + 1) If Not @error And $x[0] <> 0 Then Return $x[2] EndFunc Func _get_computer_name() Local $MAX_COMPUTERNAME_LENGTH = 15 Local $dll_struct = DllStructCreate("char[" & $MAX_COMPUTERNAME_LENGTH + 1 & "]") Local $x = DllCall("kernel32.dll","int","GetComputerName","char",$dll_struct,"int",$MAX_COMPUTERNAME_LENGTH + 1) Return DllStructGetData($dll_Struct,1) EndFunc I found it in MSDN : BOOL GetComputerName( LPTSTR lpBuffer, LPDWORD lpnSize ); I have been trying to get an answer to an almost identical question for a while so I don't know the answer, however I am sure the "char" is wrong because that would indicate that the following item was a character. Have you tried 'str' or 'ptr'? But this is the bit I am having problems with myself. Also I think that lpBuffer is a pointer to a buffer so instead of $dll_struct you should use DllStructGetPtr($dll_struct) I will watch this thread because if your problem is fixed then so is mine I hope. EDIT - Oh dear, looks like BidDod has killed this thread Edited December 17, 2006 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Pavel Posted December 17, 2006 Author Posted December 17, 2006 yeah, i tried Thanks BigDod, i know that this macro exists Who can re-write this functions?? BOOL GetComputerNameEx( COMPUTER_NAME_FORMAT NameType, LPTSTR lpBuffer, LPDWORD lpnSize);BOOL SetComputerNameEx( COMPUTER_NAME_FORMAT NameType, LPCTSTR lpBuffer);http://msdn.microsoft.com/library/default....puternameex.asphttp://msdn.microsoft.com/library/default....puternameex.asp
BigDod Posted December 17, 2006 Posted December 17, 2006 Have a look at This topic Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother
martin Posted December 17, 2006 Posted December 17, 2006 Have a look at This topic This works Func _get_computer_name() Local $MAX_COMPUTERNAME_LENGTH = 15 Local $dll_struct = DllStructCreate("char[" & $MAX_COMPUTERNAME_LENGTH + 2 & "]") $sz = DllStructCreate('int') Local $x = DllCall("kernel32.dll","int","GetComputerName","ptr",DllStructGetPtr($dll_struct),"int_ptr",DllStructGetPtr($sz)) ;msgbox(0,'name',DllStructGetData($dll_Struct,1)) Return DllStructGetData($dll_Struct,1) EndFunc Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Pavel Posted December 17, 2006 Author Posted December 17, 2006 Thanks, martin, this is exactly that what I want
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