flat assembler
Message board for the users of flat assembler.
Index
> Windows > Saving current directory to text file |
Author |
|
shutdownall 30 Oct 2014, 20:30
Regarding this
Code: DWORD WINAPI GetCurrentDirectory( _In_ DWORD nBufferLength, _Out_ LPTSTR lpBuffer ); you can code it like this: Code: buffer db 200h dup(0) buffersize = $ - buffer invoke GetCurrentDirectory,buffersize,buffer |
|||
30 Oct 2014, 20:30 |
|
typedef 31 Oct 2014, 02:24
Code: invoke GetCurrentDirectoryA, PATH_LENGTH, pszBuffer invoke CreateFileA, pszFileName, 0, GENERIC_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 invoke lstrlenA, pszBuffer invoke WriteFile, [hFile], pszBuffer, eax, dwWritten, 0 invoke CloseHandle, [hFile] |
|||
31 Oct 2014, 02:24 |
|
Traxler 31 Oct 2014, 09:19
buffer db 200 dup(0) instead of buffer db ? solved my problem
Thans a lot. shutdownall wrote: Regarding this |
|||
31 Oct 2014, 09:19 |
|
Picnic 01 Nov 2014, 15:12
typedef wrote:
Mind the handle Code: invoke CreateFileA, pszFileName, 0, GENERIC_WRITE, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 mov [hFile], eax |
|||
01 Nov 2014, 15:12 |
|
typedef 01 Nov 2014, 20:43
Yeah. I left out a lot assuming that they know how to weave that code together.
|
|||
01 Nov 2014, 20:43 |
|
shutdownall 02 Nov 2014, 13:55
Traxler wrote: buffer db 200 dup(0) instead of buffer db ? solved my problem Just in case, the 200 means the size of the buffer. So for bigger directories you may choose more buffer (1000h = 4096 bytes) and to be more general it would be good to allocate memory dynamically. But this maybe too much for a hello world project. |
|||
02 Nov 2014, 13:55 |
|
baldr 02 Nov 2014, 15:44
shutdownall,
Dynamic allocation is good when data is really dynamic. |
|||
02 Nov 2014, 15:44 |
|
TheRaven 15 Jan 2015, 13:37
Traxler wrote: buffer db 200 dup(0) instead of buffer db ? solved my problem Buffer sizes are explicit with Windows and a ? in best case scenario will result in a buffer of zero length. By general convention, text file buffers are 1024 or a megabyte. _________________ Nothing so sought and avoided more than the truth. I'm not insane, I know the voices in my head aren't real! |
|||
15 Jan 2015, 13:37 |
|
macgub 16 Jan 2015, 11:16
Hi. I have similar problem. I have something write to file. But there are some problems with file handler. File appears only if I leave program and ex. change current directory Who help me fix my code
Code: ;--code invoke GetStdHandle, STD_OUTPUT_HANDLE mov [file_handle],eax invoke CreateFile,file_name, GENERIC_WRITE, 0, 0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 invoke WriteFile,eax,file_buffer,[file_size], byteswritten, 0 invoke CloseHandle,[file_handle] ;--data file_handle dd ? file buffer rb 65536 bytes_written dd ? |
|||
16 Jan 2015, 11:16 |
|
AsmGuru62 16 Jan 2015, 16:33
Not sure what do you want to do with the code.
When you close the handle - you're closing the handle returned by GetStdHandle(), not the one returned by CreateFile(). Also, [file_size] and [file_name] are not declared. |
|||
16 Jan 2015, 16:33 |
|
macgub 16 Jan 2015, 16:47
Now the code is:
Code: ;---code invoke CreateFile,file_name, GENERIC_WRITE, 0, 0,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 mov [file_handle],eax invoke WriteFile,eax,file_buffer,[file_size], byteswritten, 0 invoke CloseHandle,[file_handle] ] ;--data file_handle dd ? file buffer rb 65536 bytes_written dd ? file_name db 'surface.3ds',0 file_size dd 1024 And all works as I want. Thanks AsmGuru62 for the tip. [/b] |
|||
16 Jan 2015, 16:47 |
|
bitshifter 17 Jan 2015, 05:41
my win32 version, was bored...
Code: format PE GUI 4.0 entry start include 'win32axp.inc' section '.text' code readable executable start: invoke GetCurrentDirectoryA,0,0 mov [dwLength],eax invoke LocalAlloc,LPTR,[dwLength] mov [pszBuffer],eax invoke GetCurrentDirectoryA,[dwLength],[pszBuffer] invoke CreateFileA,pszFileName,GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 mov [hOutputFile],eax mov eax,[dwLength] sub eax,sizeof.TCHAR invoke WriteFile,[hOutputFile],[pszBuffer],eax,dwBytesWritten,0 invoke CloseHandle,[hOutputFile] invoke LocalFree,[pszBuffer] invoke ExitProcess,0 section '.data' data readable writeable pszFileName db 'spit.txt',0 hOutputFile dd INVALID_HANDLE_VALUE dwBytesWritten dd ? pszBuffer dd ? dwLength dd ? section '.idata' import data readable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
17 Jan 2015, 05:41 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.