Hi Alexander:
I took a look at making comdlg32.dll bindings some time ago, but I don't know 
much about calling conventions or how the Factor FFI stuff works, so it was a 
struggle. I just gave up shortly after.
Is there somewhere to look at how you did it?
If I can help with something please let me know! 



El Viernes, 26 de mayo, 2017 7:46:02, Alexander Ilin <ajs...@yandex.ru> 
escribió:
 

 Thank you for the `calloc` tip. I have updated my code. There was a source of 
crashes that I've identified to be the calling convention. Apparently, 
comdlg32.dll works with the stdcall convention, not cdecl that I copy-pasted 
from somewhere. Answering my own question, the sizeof() for structs is called 
`heap-size` in Factor. The code now works, will submit a PR when I have some 
free time. Thanks for the help! 26.05.2017, 05:18, "cat" <cat...@protonmail.ch>:
As for zeroing out the bytes, there is a word `calloc` which functions 
identically to C's calloc, allocating `n` bytes of size `size" and zeroing the 
entire region for you. Indeed, it is overkill and a small performance hit 
depending on the size of the region, but it's definitely simpler for now.

See http://docs.factorcode.org/content/word-calloc,libc.html and
-------- Original Message --------
On May 24, 2017, 14:09, Alexander Ilin < ajs...@yandex.ru> wrote:
Hello!

I need some help figuring out how to receive a string from a WinAPI call.
I must allocate a buffer for the string, and pass a pointer to it into the 
function (along with the buffer size, in characters).
I want the buffer to contain zeroes at the beginning so that the function I'm 
calling would not think that I'm passing some random junk left in there by 
malloc.
Here's my code so far:

CONSTANT: OFN_OVERWRITEPROMPT 2

STRUCT: OPENFILENAME
{ lStructSize DWORD }
{ hwndOwner HWND }
{ hInstance HINSTANCE }
{ lpstrFilter LPCTSTR }
{ lpstrCustomFilter LPTSTR }
{ nMaxCustFilter DWORD }
{ nFilterIndex DWORD }
{ lpstrFile LPTSTR }
{ nMaxFile DWORD }
{ lpstrFileTitle LPTSTR }
{ nMaxFileTitle DWORD }
{ lpstrInitialDir LPCTSTR }
{ lpstrTitle LPCTSTR }
{ Flags DWORD }
{ nFileOffset WORD }
{ nFileExtension WORD }
{ lpstrDefExt LPCTSTR }
{ lCustData LPARAM }
{ lpfnHook PVOID }
{ lpTemplateName LPCTSTR } ;

TYPEDEF: OPENFILENAME* LPOPENFILENAME

FUNCTION: BOOL GetSaveFileName ( LPOPENFILENAME lpofn )

: ask-file-name ( -- string/f )
[
OPENFILENAME malloc-struct &free dup size-of >>lStructSize
MAX_UNICODE_PATH malloc &free >>lpstrFile
MAX_UNICODE_PATH 2 /i 1 - >>nMaxFile
OFN_OVERWRITEPROMPT >>Flags
dup GetSaveFileName
[ lpstrFile>> >string ] [ drop f ] if
] with-destructors ;

As you can see, I've used malloc, but I don't know how to set the initial few 
bytes of the resulting alien to 0.
Also, I can't find the equivalent of sizeof() for the struct. What should I use 
in Factor?
Lastly, do you think my calculation of nMaxFile (in characters) is valid, or is 
there room for improvement there?

Thank you for any help you can spare.

 ---=====---Александр   
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to