implementation module DynamicLink;

//1.3
from StdMisc import abort;
from StdString import String, +++;
from StdInt import <;
//3.1

/*2.0
import StdEnv;
0.2*/

import StdClass;

from ExtFile import ExtractPathFileAndExtension;

import code from library "StdDynamic_kernel32_library";

import code from library "ServerChannel_library";
import code from library "DynamicLink_library";
import code from "sharing.obj";

from pdExtFile import FetchFileTime, CompareFileTimes;
//1.3
from ioTypes import IOState;
//3.1
/*2.0
from ioTypes import ::IOState;
0.2*/

GetDynamicLinkerPath :: !String;
GetDynamicLinkerPath
	= code {
		ccall GetDynamicLinkerPath "-S"
	};

/* OLD
StartProcess :: !Bool !String !String !String -> (!Bool,!Int,!String);
StartProcess _ _ _ _ 
	= code {
 		ccall StartProcess "ISSS-IIS"

	};
*/

StartProcess :: !Bool !String !String !String !String -> (!Bool,!Int,!String);
StartProcess _ _ _ _ _
	= code {
 		ccall StartProcess "ISSSS-IIS"

	};
	
	
// cmd_line must be zeroterminated
StartProcess2 :: !String !String !String -> (!Bool,!Int);
StartProcess2  current_directory file_name cmd_line
	= code {
		ccall StartProcess2 "SSS-II"
	};
	
	/*
RESOURCEAPI void StartProcess2(CLEAN_STRING commandline,
				   CLEAN_BOOL *ok, int *client_id);
	*/


import ProcessSerialNumber;
		
KillClient :: !Int -> !Bool;
KillClient _ =
	code {
		ccall KillClient "I-I"
	}
	
ReceiveReq :: !Bool -> (!Int,!String);
ReceiveReq _ = 
	code {
		ccall ReceiveReq "I-IS"
	}
	
import ProcessSerialNumber;

ReceiveReqWithTimeOut :: !Bool -> (!Bool,!Int,!String);
ReceiveReqWithTimeOut _ = 
	code {
		ccall ReceiveReqWithTimeOut "I-IIS"
	}


ReceiveReqWithTimeOutE :: !Bool -> (!Bool,!ProcessSerialNumber,!String);
ReceiveReqWithTimeOutE static_application_as_client
	#! (ok,client_id,s)
		= ReceiveReqWithTimeOut static_application_as_client;
	= (ok,CreateProcessSerialNumber client_id,s);
	
ReplyReq :: !Int -> !Bool;
ReplyReq q =
	code {
		ccall ReplyReq "I-I"
	}
	
ReplyReqS :: !String -> !Bool;
ReplyReqS _ = 
	code {
		ccall ReplyReqS "S-I"
	}
	
ReceiveCodeDataAdr :: !Int !Int -> (!Bool,!*Int,!*Int);
ReceiveCodeDataAdr _ _ =
	code {
		ccall ReceiveCodeDataAdr "II-III"
	}

GenerateObjectFileOld :: !String !String -> !Bool;
GenerateObjectFileOld cgpath commandline =
	code {
		ccall GenerateObjectFileOld "SS-I"
	}


FirstInstanceOfServer2 :: !Bool -> !Bool;
FirstInstanceOfServer2 _ =
	code {
		ccall FirstInstanceOfServer2 "I-I"
	}
	
is_first_instance :: !Bool;
is_first_instance 
	= code {
		ccall is_first_instance ":I"
	};


StoreLong :: !String !Int !Int -> !Bool;
StoreLong s adr int
	= storelong adr int
where
{
	storelong :: !Int !Int -> !Bool;
	storelong _ _ =
		code {
			ccall StoreLong "II-I"
		}
}		

SetCurrentLibrary :: !String -> (!Bool,!*Int);
SetCurrentLibrary lib_name =
	code {
		ccall SetCurrentLibrary "S-II"
	}
	
GetFuncAddress :: !String !Int !*Int -> (!Int, !*Int);
GetFuncAddress _ _ _ =
	code {
		ccall GetFuncAddress "SII-II"
	}
	
mwrites :: !Int !Int !{#Char} !*Int -> !*Int;
mwrites kind offset text mem_ptr =
	code {
		ccall mwrites "IISI-I"
	}

MakeNonUnique :: !*Int -> (!*Int, !Int);
MakeNonUnique _ = 
	code {
		ccall MakeNonUnique "I-II"
	}

FlushBuffers :: !Int -> !Int;
FlushBuffers _ =
	code {
		ccall FlushBuffers "I-I"
	}