Power Builder - funciones api win 32

 
Vista:

funciones api win 32

Publicado por luis (50 intervenciones) el 13/06/2007 19:04:30
Encontre este documento en la red espero les sea util.
Saludos,

Function name
Library
Description

GetComputerName kernel32.dll Retrieve computer system name

Sleep kernel32.dll Stop processing (sleep process) for specified number of miliseconds

GetSystemDirectory kernel32.dll Retrieve path to the system directory

GetTempPath kernel32.dll Retrieve temporary folder path

GetTempFileName kernel32.dll Generate unique temporary filename

GetUserName advapi32.dll Get logged user name

GetWindowsDirectory kernel32.dll Get windows directory

SHAddToRecentDoc shell32.dll Add last edited document into “Recent documents” folder

SHBrowseForFolder shell32.dll Open “browse for folder” dialog screen used to choose folder.

ShellExecute shell32.dll Execute program or file using windows mechanizm

FindFirstFile kernel32.dll Find first matching file in single directory

FindNextFile kernel32.dll Find next file using expresions

FindClose kernel32.dll Close handle opened by FindFirstFile function

GetDiskFreeSpace kernel32.dll Get user quota , free disk and total space on any disk

GetFullPathName kernel32.dll Append filename to the current directory

RemoveDirectory kernel32.dll Remove empty folder

GetEnvironmentVariable kernel32.dll Read system variable

SetEnvironmentVariable kernel32.dll Set system variable




GetComputerName

Returns computer system name as you seen it in Network Neighborhood

Declare:
//computer name
Function long GetComputerName(ref String lpBuffer , long nSize ) Library "kernel32.dll" Alias for "GetComputerNameA"


--------------------------------------------------------------------------------

Sleep

Sleep process for specified number of miliseconds

Declare:
//sleep
Subroutine Sleep( long dwMilliseconds ) Library "kernel32.dll"

Execution:
//sleep process for 1 second
Sleep(1000)


--------------------------------------------------------------------------------

GetSystemDirectory

Retrieve windows system directory eq. c:\WINNT\system32

Declare:
//system directory
Function long GetSystemDirectory(ref string lpBuffer , long ByVal ) Library "kernel32.dll" Alias for "GetSystemDirectoryA"

Execution:
ls_buffer= space(50)
li_ret = GetSystemDirectory( ls_buffer, 50 )
MessageBox("system directory", trim( ls_buffer ) )


--------------------------------------------------------------------------------

GetTempPath

Retrieve path to the temporary folder of the system

Declare:
//temp path
Function long GetTempPath(long nBufferLength, ref string lpBuffer ) Library "kernel32.dll" Alias For "GetTempPathA"


--------------------------------------------------------------------------------

GetTempFileName

Generate temporary and unique filename

Declare:
//temporary random file
Function long GetTempFileName(string lpszPath, string lpPrefixString, long wUnique, ref String lpTempFileName) Library "kernel32.dll" Alias for "GetTempFileNameA"


Execution:
//temporary file
li_ret = GetTempFileName(trim(ls_temppath), 'tmp', 0, ls_buffer)
MessageBox("temporary file", trim(ls_buffer))


--------------------------------------------------------------------------------

GetUserName

Get user name that is currently logged to the system

Declare:
//user name
Function long GetUserName(ref string lpBuffer, ref long nSize ) Library "advapi32.dll" Alias for "GetUserNameA"


Execution:
//user name
ls_buffer = space(100)
li_ret = GetUserName(ref ls_buffer, 100 )
MessageBox("user name", trim(ls_buffer))


--------------------------------------------------------------------------------

GetWindowsDirectory

Get windows directory eq. c:\WINNT

Declare:
//windows directory
Function long GetWindowsDirectory(ref String lpBuffer , long nSize ) Library "kernel32.dll" Alias For "GetWindowsDirectoryA"


Execution:
ls_buffer = space(50)
li_ret = GetWindowsDirectory( ls_buffer , 50 )
MessageBox("windows directory", trim(ls_buffer))


--------------------------------------------------------------------------------

SHAddToRecentDocs

Declare:
//add last used document into document history
subroutine SHAddToRecentDocs( Long uFlags, String pv ) Library "shell32.dll"

Execution:
//add document to the last edited documents
SHAddToRecentDocs(2 , 'c:\custdata.txt' )


--------------------------------------------------------------------------------

SHBrowseForFolder

Open system dialog for selecting dialog screen

Declare:
type BROWSEINFO from structure
long hwndOwner
long pidlRoot
string pszDisplayName
string lpszTitle
long ulFlags
long lpfn
long lParam
long iImage
end type

//browse for folder
Function long SHBrowseForFolder(ref BROWSEINFO lpbi ) Library "shell32.dll" Alias for "SHBrowseForFolderA"

Execution:
BROWSEINFO lstr_browserinfo
lstr_browserinfo.hwndOwner = Handle(parent)
lstr_browserinfo.pszDisplayName = space(300)
lstr_browserinfo.lpszTitle='test'
lstr_browserinfo.lpfn=0
SHBrowseForFolder( ref lstr_browserinfo )


--------------------------------------------------------------------------------

|ShellExecute

Execute program attached to the file:

Declare:
//shell execute
Function long ShellExecute(long hwnd, string lpOperation , string lpFile , string lpParameters , string lpDirectory , long nShowCmd) Library "shell32.dll" Alias for "ShellExecuteA"


Execution:
ShellExecute(Handle(parent), "open" , "iexplore" , "" , "" , 3 )


--------------------------------------------------------------------------------

ShFileOperation

Copy, delete, move files using the standard windows dialog boxes (

Declare:
type SHFILEOPSTRUCT from structure
long hwnd
long wFunc
string pFrom
string pTo
integer pFlags
long fAnyOperationsAborted
long hNameMappings
string lpszProgressTitle
end type
//copy, rename, delete files
Function long SHFileOperation(ref SHFILEOPSTRUCT lpFileOp ) Library "shell32.dll" Alias for "SHFileOperationA"

FindFirstFile, FindNextFile

Declare:
type FILETIME from structure
long dwLowDateTime
long dwHighDateTime
end type

type win32_find_data from structure
long dwfileattributes
filetime ftcreationtime
filetime ftlastaccesstime
filetime ftlastwritetime
long nfilesizehigh
long nfilesizelow
long dwreserved0
long dwreserved1
char actercfilename[260]
char actercalternate[14]
end type
//find first file
Function long FindFirstFile(string lpFileName, ref WIN32_FIND_DATA lpFindFileData ) Library "kernel32.dll" Alias for "FindFirstFileA"


Execution:
long ll_ret
WIN32_FIND_DATA lstr_find_info , l_empty

ll_ret = FindFirstFile("C:\temp\*.txt", lstr_find_info )
If ll_ret = -1 Then
MessageBox("","there are no files C:\temp\*.txt")
return
End If

MessageBox("first file founded",trim(lstr_find_info.cFileName) )

lstr_find_info = l_empty
//find next file
ll_ret = FindNextFile(ll_ret, lstr_find_info )
If ll_ret = 0 Then
MessageBox("","there are no more files C:\temp\*.txt")
return
End If

MessageBox("second file founded",trim(lstr_find_info.cFileName) )

FindClose

Declare:
//close
Function long FindClose(long hFindFile ) library "kernel32.dll"

GetDiskFreeSpaceEx

Declare:
//get disk free space
Function long GetDiskFreeSpaceEx(String lpDirectoryName , ref ULARGE_INTEGER lpFreeBytesAvailableToCaller , ref ULARGE_INTEGER lpTotalNumberOfBytes, ref ULARGE_INTEGER lpTotalNumberOfFreeBytes ) Library "kernel32.dll" Alias For "GetDiskFreeSpaceExA"

GetFileSize

GetFullPathName

Declare:
//get file path
Function long GetFullPathName(string lpFileName , long nBufferLength , ref string lpBuffer , string lpFilePart ) Library "kernel32.dll" Alias for "GetFullPathNameA"

Execution:
//get file path
String ls_buffer = space(255)
GetFullPathName('trala.txt' , 255, ls_buffer, '' )
MessageBox("", "full path : "+ trim( ls_buffer))

RemoveDirectory:

Declare:
//remove directory
Function long RemoveDirectory(string lpPathName) Library "kernel32.dll" Alias for "RemoveDirectoryA"

GetEnvironmentVariable

Declare:
//get system variable
Function long GetEnvironmentVariable(string lpName , ref string lpBuffer , long nSize ) Library "kernel32.dll" Alias for "GetEnvironmentVariableA"

Execution:
string ls_buffer = space(255)
//get system variable
GetEnvironmentVariable('TEMP' , ls_buffer , 255 )
MessageBox("","temp path "+ trim(ls_buffer))

SetEnvironmentVariable

Declare:
//set system variable
Function long SetEnvironmentVariable(string lpName , string lpValue ) Library "kernel32.dll" Alias for "SetEnvironmentVariableA"

Execution:
string ls_buffer = space(255)

//set system variable
SetEnvironmentVariable('TEST' , 'tralalalal' )
//get system variable
GetEnvironmentVariable('TEST' , ls_buffer , 255 )
MessageBox("","added variable"+ trim(ls_buffer))
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE: funciones winSockets

Publicado por luis (50 intervenciones) el 13/06/2007 19:07:47
Function name
Library
Description

CloseSocket wsock32.dll Close opened socket

WSASturtup wsock32.dll Initialize socket mechanizm

WSACleanup wsock32.dll free resources bused by windows socket mechanizm

inet_ntoa wsock32.dll Convert IP address into readable text

Connect wsock32.dll Connect to the socket

Send wsock32.dll Send data via socket

Recv wsock32.dll Read data from socket

Socket wsock32.dll Create socket

htons wsock32.dll converts host byte order into network byte order

CopyMemory kernel32.dll Function used to copy memory from pointer to structure

GetHostByName wsock32.dll Get information about komputer

WSAGetLastError wsock32.dll Get last error that raise during using socket mechanizm




CloseSocket
//close socket opened previously by socket function
Function long Closesocket(Long s ) Library"wsock32.dll"

WSAStartup
//initialize Windows Socket windows mechanizm
Function long WSAStartup(Integer wVersionRequested, ref WSADATA lpWSAData ) Library "wsock32.dll"

type WSADATA from structure
integer wversion
integer whighversion
character szdescription[257]
character szsystemstatus[129]
long imaxsockets
long imaxudpdg
long lpvendorinfo
end type


WSACleanup
//free the resources used by Windows Socket mechanizm
Function long WSACleanup() Library "wsock32.dll"

Inet_Ntoa
//converts IP address into readable text
Function long inet_ntoa(long inaddr) Library "wsock32.dll"

Connect
//establishes connection via socket
Function long connectA(long s , sockaddr name , long namelen ) Library "wsock32.dll" alias for "connect"

type SOCKADDR from structure
integer sin_family
integer sin_port
long sin_addr
character sin_zero[8]
end type

Send
//send data via opened socket
Function long send(Long ByVal, string buf, long length, long flags ) Library "wsock32.dll"

Recv
//received data from socket
Function long recv(long s, ref String buf, long length, long flags) Library "wsock32.dll"

Socket
//create socket
Function long socket(long af , long prototype , long protocol) Library "wsock32.dll"

Htons
//converts host byte order into network byte order
Function integer htons(integer hostshort ) Library "wsock32.dll"

CopyMemory
//use function to copy data from pointer to structure
Subroutine CopyMemory(ref HOSTENT Destination , long Source , long Length) Library "kernel32.dll" Alias for "RtlMoveMemory"
Subroutine CopyMemory(ref long destination, long Source , long Length) Library "kernel32.dll" Alias for "RtlMoveMemory"

type HOSTENT from structure
long h_name
long h_aliases
integer h_addrtype
integer h_length
long h_addr_list
end type

GetHostByName
//get information about komputer
Function long gethostbyname(string name ) Library "wsock32.dll"

WSAGetLastError
//.get last error
Function long WSAGetLastError() Library "wsock32.dll"

GetHostName
//get host name
Function long GetHostName(ref String name , ref long namelen ) Library "wsock32.dll"

Htonl
//converts value from host byte order to network byte order
Function long htonl(long hostlong) Library "wsock32.dll"

Inet_Addr
//converts an IP string to IP address in network byte order
Function long inet_addr(String cp) Library "wsock32.dll"

IoctlSocket
//manipulate input/output mode of the socket
Function long ioctlsocket(Long s , long cmd , long argp ) Library "wsock32.dll"




Example (connecting to web server):

long ll_ret, ll_socket
wsadata lstr_sockinfo
sockaddr lstr_sockaddr
HOSTENT lstr_hostent

//Begin a Winsock session
ll_ret = WSAStartup(514, lstr_sockinfo)
If ll_ret <> 0 Then
MessageBox("","Unable to initialize Winsock! --")
return
End If

long ll_hostinfo
ll_hostinfo = GetHostByName("www.onet.pl")
if ll_hostinfo = 0 then
MessageBox("","invalid host")
return
end if

CopyMemory( lstr_hostent, ll_hostinfo, 16 )

//open socket
Constant long INVALID_SOCKET = 4294967295

ll_socket = socket(2, 0, 0)
if ll_socket = INVALID_SOCKET then
MessageBox("", "Error in opening socket")
end if

//connect to socket
// Use Internet Protocol (IP)
lstr_sockaddr.sin_family = 2
//Connect to port 80.
lstr_sockaddr.sin_port = htons(80)

long pipaddress, ipAddress, tmp
tmp = lstr_hostent.h_addr_list
//Get the server's IP address out of the structure.
CopyMemory( pIPAddress, tmp, 4 )
CopyMemory( ipAddress, pIPAddress, 4)

//Connect to this IP address.
lstr_sockaddr.sin_addr = ipAddress
//Padding characters.
lstr_sockaddr.sin_zero = space(8)

ll_ret = connectA(ll_socket, lstr_sockaddr, 16)
If ll_ret <> 0 Then
MessageBox("","cannot connect "+ String(WSAGetLastError()))
End If

// Send an HTTP/GET request for the /index.html file.
string buffer
buffer = "GET / HTTP/1.1 Host: www.onet.pl User-Agent: HTTP-Test-Program"
ll_ret = send(ll_socket, buffer, Len(buffer), 0)

//read from socket
buffer = Space(1024)
do
ll_ret = recv(ll_socket, buffer, Len(buffer), 0)
loop Until ll_ret = 0

//closesocket( ll_socket)
//WSACleanup()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE: funciones winSockets

Publicado por Saulo (1 intervención) el 24/04/2014 18:34:04
Ótimo. Ajudou bastante.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar