Handling of WinAPI strings in MQL5 with MQL Standard Library

 

To get back a string or a list of strings from a Windows API functions, you pass in a pointer to a buffer. I like to use the wide character functions like GetPrivateProfileSectionNamesW(), see https://docs.microsoft.com/en-gb/windows/desktop/api/winbase/nf-winbase-getprivateprofilesectionnamesw. This function returns its result in a buffer, filled with several strings. Each string is terminated with 0x00 and the last string is followed with 2 times 0x00.

There are code samples that use ushort arrays to pass as buffer. For example https://www.mql5.com/en/code/20842 That works for me and allows to extract all the strings returned by GetPrivateProfileSectionNamesW().

I would like to use the “Standard Library” of MT5. The definition of the function is in WinAPI\winbase.mql:

uint GetPrivateProfileSectionNamesW(string return_buffer,uint size,const string file_name);

I am not able to call the function with this type of declaration. Any suggestions?

If I would get the calling convention right, would it be possible to extract data from the buffer after the first 0x00?

The integer data types in 32bit and 64bit versions of MT5 are the same size (like Java). At the moment I have only a 64bit version (build 1940, 2.Nov.2018) running on Windows 10. But I would prefer to run a 32bit version on Linux, where the 64bit versions do not work.