41 views
in System Integration by
Hi,I am using EW for the target platform Win32.

Is it possible to use the OPENFILENAME (https://docs.microsoft.com/en-us/windows/win32/dlgbox/open-and-save-as-dialog-boxes)  function or another straight from native in slot metod.

 

 

Kyo,

1 Answer

0 votes
by
 
Best answer

Hello Kyo,

yes, this should be possible. Finally you want to invoke a C function. Please note, the C function does belong to Win32 SDK. Accordingly, you will need to include the appropriate Win32 header files (e.g. windows.h). For this purpose use the Inline Code member. Some further hint: while the file dialog is opened, the Embedded Wizard generated GUI application will be paused waiting for the return of the invoked function (e.g. GetOpenFileName()).

I hope it helps you further.

Best regards

Paul Banach

by
Hi, Paul Banach.

Thank you for answer. I am having trouble returning a file name from this function to a string.
Could you please give an example of the easiest way to do this in native.

Thanks for help.

Kyo,
by

Hello Kyo,

according to Microsoft documentation, the selected file name is stored as zero terminated string in the data field lpstrFile in the OPENFILENAME data structured passed to the Win32 function GetOpenFileName(). To relay this string to Embedded Wizard application use the function EwNewStringAnsi() or EwNewString(). These function will take care of the proper memory management for the new string. Whether you use the first or second function depends on the version of the GetOpenFileName() function. Win32 provides in this case the functions for ANSI or WCHAR strings (identifier by a final A or W sign in the name according to Microsoft).

Following could be the code to obtain an Embedded Wizard conform string from the ANSI version of the GetOpenFileName() function:

var string fileName = "";

native ( fileName )
{
  OPENFILENAMEA data;

  /* Initialize the data structure ... */
  data.lStructSize = sizeof( data );
  [...]

  if ( GetOpenFileNameA( &data ))
    fileName = EwNewStringAnsi( data.lpstrFile );
}

// Again in Embedded Wizard world -> use the name returned by Windows.
trace "User has selected the file:", fileName;

I hope it helps you further. See also: Be careful when exchanging strings

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...