File: n_inetresult.sru
Size: 2710
Date: Thu, 14 Jul 2022 19:24:02 +0200
$PBExportHeader$n_inetresult.sru
forward
global type n_inetresult from internetresult
end type
end forward

global type n_inetresult from internetresult
end type
global n_inetresult n_inetresult

type prototypes
Function longptr CreateFile ( &
   string lpFileName, &
   ulong dwDesiredAccess, &
   ulong dwShareMode, &
   ulong lpSecurityAttributes, &
   ulong dwCreationDisposition, &
   ulong dwFlagsAndAttributes, &
   ulong hTemplateFile &
   ) Library "kernel32.dll" Alias For "CreateFileW"

Function boolean WriteFile ( &
   longptr hFile, &
   blob lpBuffer, &
   ulong nNumberOfBytesToWrite, &
   Ref ulong lpNumberOfBytesWritten, &
   longptr lpOverlapped &
   ) Library "kernel32.dll"

Function boolean CloseHandle ( &
   longptr hObject &
   ) Library "kernel32.dll"

Function ulong GetTempPath ( &
   ulong nBufferLength, &
   Ref string lpBuffer &
   ) Library "kernel32.dll" Alias For "GetTempPathW"

end prototypes

type variables
Blob iblob_data

// constants for CreateFile API function
Constant ULong INVALID_HANDLE_VALUE = -1
Constant ULong GENERIC_READ     = 2147483648
Constant ULong GENERIC_WRITE    = 1073741824
Constant ULong FILE_ATTRIBUTE_NORMAL = 128
Constant ULong FILE_SHARE_READ  = 1
Constant ULong FILE_SHARE_WRITE = 2
Constant ULong CREATE_NEW        = 1
Constant ULong CREATE_ALWAYS     = 2
Constant ULong OPEN_EXISTING     = 3
Constant ULong OPEN_ALWAYS       = 4
Constant ULong TRUNCATE_EXISTING = 5

end variables

forward prototypes
public function integer internetdata (blob data)
public function integer of_writefile (string as_filename, blob ablob_data)
public function string of_gettemppath ()
end prototypes

public function integer internetdata (blob data);// save the data to an instance variable
//
// Return - 1=Success, -1=Failure
//

iblob_data = data

Return 1

end function

public function integer of_writefile (string as_filename, blob ablob_data);Boolean lb_rtn
Longptr ll_file
ULong lul_written

// open file for write
ll_file = CreateFile(as_filename, GENERIC_WRITE, &
               FILE_SHARE_WRITE, 0, CREATE_ALWAYS, 0, 0)
If ll_file = INVALID_HANDLE_VALUE Then
   Return -1
End If

// write file to disk
lb_rtn = WriteFile(ll_file, ablob_data, &
               Len(ablob_data), lul_written, 0)

// close the file
CloseHandle(ll_file)

Return 1

end function

public function string of_gettemppath ();Constant Long MAX_PATH = 260
String ls_path

ls_path = Space(MAX_PATH)

GetTempPath(MAX_PATH, ls_path)

Return ls_path

end function

on n_inetresult.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_inetresult.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on