Jump to content

Recommended Posts

Posted

Hi,

Can anyone explain me, why thic function is not working ?? :P

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

);

Posted

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

Posted (edited)

Hi,

Can anyone explain me, why thic function is not working ?? :P

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 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.
Posted

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

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...