format PE GUI 4.0 DLL
entry DllEntryPoint

include 'win32a.inc'

;DATA

section '.data' data readable writeable
	title	db 'Hello!',0
	message db 'This is an example!',0
	filenm	db 'c:\dllrun.txt',0
	open	db 'open',0
	desktop db 'WinSta0\Default',0
	logon	db 'WinSta0\winlogon',0

	FileHandle	dd ?
	FileBuffer	rb 1024


section '.udata' readable writeable
	sinfo STARTUPINFO
	pinfo PROCESS_INFORMATION

section '.code' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
	mov	eax,TRUE
	ret
endp

;PROC

proc GetFileContents
	invoke	CreateFile,filenm,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
	mov	[FileHandle],eax
	invoke	ReadFile,[FileHandle],FileBuffer,1023,FileHandle,NULL

	invoke	CloseHandle,FileHandle
	ret
endp

proc StartProcessLogon
	mov	[sinfo.cb],sizeof.STARTUPINFO
	mov	[sinfo.dwFlags],0
	mov	[sinfo.wShowWindow],SW_SHOW
	mov	[sinfo.lpDesktop],logon

	call	GetFileContents
	invoke	CreateProcess,0,FileBuffer,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,sinfo,pinfo
	ret
endp

proc StartProcess
	mov	[sinfo.cb],sizeof.STARTUPINFO
	mov	[sinfo.dwFlags],0
	mov	[sinfo.wShowWindow],SW_SHOW
	mov	[sinfo.lpDesktop],desktop

	call	GetFileContents
	invoke	CreateProcess,0,FileBuffer,NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,sinfo,pinfo
	ret
endp

proc StartApp
	call	GetFileContents
	invoke	ShellExecute,NULL,open,FileBuffer,NULL,NULL,SW_SHOWNORMAL
	ret
endp

proc Message
	invoke	MessageBox,NULL,message,title,MB_ICONINFORMATION+MB_OK
	ret
endp

;IMPORT

section '.idata' import data readable writeable

  library kernel, 'KERNEL32.DLL',\
	  user,   'USER32.DLL',\
	  shell,  'SHELL32.DLL'

  import kernel,\
	 CreateFile,	'CreateFileA',\
	 ReadFile,	'ReadFile',\
	 CloseHandle,	'CloseHandle',\
	 CreateProcess, 'CreateProcessA'

  import shell,\
	 ShellExecute,'ShellExecuteA'

  import user,\
	 MessageBox,  'MessageBoxA'

;EXPORT

section '.edata' export data readable

  export 'SIMPLESTART.DLL',\
	 Message, 'Message',\
	 StartProcessLogon, 'StartProcessLogon',\
	 StartProcess, 'StartProcess',\
	 StartApp, 'StartApp'

section '.reloc' fixups data discardable
