We are starting to replace good old clarion standard procedures with our linux ported binding emulation machine to windows 32.. with the goal of adding the binding machine to clarion template ABC apps with AI generated features…
Heres the call to file dialog as a UBS (universal Binding Machine) macro. Objects can also be bound to call win32 api and CPP bound code. we will demo these as we go and if UBS can live in windows land put it up later next year on GITHUB separate from our linux runtimes… Since this is only old window 32 it will be free.
CPP code updated for Threading.
void scriptFileDialog(ScriptInterface *ifc)
{
// AI Generated Anthropic add in to UBS win32 version.
// This does not run on the Linux cloud Azure version and is win32 windows only.
void scriptFileDialog(ScriptInterface *ifc)
{
REFSTART();
int argc = ifc->getParamCount();
if (argc < 2)
{
ifc->setReturnString("");
REFEND();
return;
}
string_t title = ifc->getParamAsString(0);
string_t filter = ifc->getParamAsString(1);
// Shared result storage
std::string result;
bool completed = false;
std::mutex resultMutex;
std::condition_variable cv;
// Launch dialog on separate thread
std::thread dialogThread([&]() {
// Convert UBS filter format to Windows format
char winFilter[1024];
char *wp = winFilter;
const char *fp = filter;
// Convert "Description|*.ext|Description2|*.ext2" to "Description\0*.ext\0Description2\0*.ext2\0\0"
while (*fp && (wp - winFilter) < 1020)
{
if (*fp == '|')
*wp++ = '\0';
else
*wp++ = *fp;
fp++;
}
*wp++ = '\0';
*wp = '\0';
char fileName[MAX_PATH] = "";
OPENFILENAMEA ofn;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = winFilter;
ofn.lpstrFile = fileName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = (LPSTR)title;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR;
std::lock_guard<std::mutex> lock(resultMutex);
if (GetOpenFileNameA(&ofn))
{
result = fileName;
}
else
{
result = "No File";
}
completed = true;
cv.notify_one();
});
// Wait for completion
std::unique_lock<std::mutex> lock(resultMutex);
cv.wait(lock, [&] { return completed; });
dialogThread.join();
ifc->setReturnString(result.c_str());
REFEND();
}
Callable from Clarion..
UBS App Module -
cexpression = 'filedialog("Select File", "All Files |*.*");'
UBSAppModule.IFileDialog.FileFolder Procedure(string Titleselect,string defaultfilter)
Foldercontents ANY
lcexpression cstring(555)
CODE
Foldercontents = ''
if Self.folderdialoghandle = FALSE
lcexpression = 'filedialog("Select File", "All Files|*.*");'
if len(Clip(lcexpression)) > FALSE
! Call UBS via the local clarion APP Module document interface.
Self.folderdialoghandle = self.AppiUBSref.Document(lcexpression)
END
END
! message(' after document registered with universal binding service. ')
if Self.folderdialoghandle> FALSE
! Execute scriptbindale handle.
Foldercontents = self.AppiUBSref.DocStrId(Self.folderdialoghandle)
END
return(Foldercontents)
! WIndow Control styling to come in a few weeks… very busy on linux Azure in the cloud… where the future of computing blues skys calls.

