Author Topic: OpenFileDialog  (Read 25722 times)

0 Members and 3 Guests are viewing this topic.

Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #45 on: June 28, 2014, 10:00:04 AM »
An lpstr is a char ptr, not an Oxygen string. The pointer must be set, rather than performing a string character copy.

Code: [Select]
Type OPENFILENAME
    lStructSize As Long
    hwndOwner As Long
    hInstance As Long
    lpstrFilter As sys
    lpstrCustomFilter As sys
    nMaxCustFilter As Long
    nFilterIndex As Long
    lpstrFile As sys
    nMaxFile As Long
    lpstrFileTitle As sys
    nMaxFileTitle As Long
    lpstrInitialDir As sys
    lpstrTitle As sys
    flags As Long
    nFileOffset As word
    nFileExtension As word
    lpstrDefExt As sys
    lCustData As Long
    lpfnHook As Long
    lpTemplateName As sys
End Type



« Last Edit: June 28, 2014, 10:35:55 AM by Charles Pegge »

Aurel

  • Guest
Re: OpenFileDialog
« Reply #46 on: June 28, 2014, 10:55:22 AM »
Ok Charles
I copy OPENFILE structure as you suggest and what is now in conflict.
FileDialog function is also fixed as you suggested.
I compile ASciEdit and o2 said OK.
I run program and looks that work fine,then i click on toolbar button Open
looks ok again file is loaded...then i click again button Open
and program is closed why is that ?
I simply cannot figured reason why ASciEdit close  :-\
Do you can try compile Asciedit.o2bas  ?
« Last Edit: June 28, 2014, 02:19:14 PM by Aurel »

Mike Lobanovsky

  • Guest
Re: OpenFileDialog
« Reply #47 on: June 28, 2014, 12:20:39 PM »
Do you can try compile Asciedit.o2bas  ?

We picked this up before, do you must be working with an older version.

Hey Charles,

Your British English is obviously deteriorating. Too much of Aurel lately?

:D

Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #48 on: June 28, 2014, 12:29:51 PM »
 ;D I should attend some of your English classes, Mike.

Aurel,

Unfortunately, I can't spare the time for this one. May I suggest using some print tracers to check each param and to find out where the program fails.

JRS

  • Guest
Re: OpenFileDialog
« Reply #49 on: June 28, 2014, 01:02:01 PM »
Quote
Too much of Aurel lately?

Can you imagine being Aurel's roommate, living in the same town, ...  :o

Aurel

  • Guest
Re: OpenFileDialog
« Reply #50 on: June 28, 2014, 01:52:34 PM »
where
in Canada or in Bjelorusija  ;D

Aurel

  • Guest
Re: OpenFileDialog
« Reply #51 on: June 28, 2014, 01:58:37 PM »
Quote
Unfortunately, I can't spare the time for this one. May I suggest using some print tracers to check each param and to find out where the program fails.
ok

Mike Lobanovsky

  • Guest
Re: OpenFileDialog
« Reply #52 on: June 28, 2014, 02:05:41 PM »
John,

I think I could manage in the same town, yes. But I would certainly die of creak and rattle of Aurel's aging computer, so not in the same room, no. :)

Aurel,

Byelorussia died 21 years ago together with the USSR, and let bygones be bygones. My country is called Belarus' ("s" palatalized).

Aurel

  • Guest
Re: OpenFileDialog
« Reply #53 on: July 24, 2014, 06:31:01 AM »
Charles...
I have found what is a problem with ASciEdit function doOpen()

Code: [Select]
'open file
Sub doOpen

INT hsize=0
fName=""
string dir=""
string script
string sep=chr(0)
'filter = "All Files"+sep+"*.*"+sep"Text files"+sep+"*.txt"+ sep
filter = "All files "+sep+"*.*"+sep+"Oxygen files "+sep+"*.o2bas"
title="Open File... "
hwnd=0
fName = FileDialog(dir,filter,title,0,0,"rub")
fileName = fName
print "FNAME IS: " + fName
'IF fName = "" Then Return
SendMessage edit1,SCI_SETTEXT,0,strptr(fName)
print "EDIT(FilePath)...OK!"
 tx =  GetFile fName
print "FILE-LEN: " + LEN(tx)  'OK!
print "GETFILE(load)...OK!"
script = tx   '
SendMessage hsci,SCI_SETTEXT,0, strptr script   ' tx is in direct conflict with scintilla why?
'SendMessage hsci,SCI_SETSAVEPOINT, 0, 0
'SendMessage hsci,SCI_EMPTYUNDOBUFFER,0,0

'If fName <> ""
'FindNewTab()
'End If

End Sub

as you can see i tested step by step and check everything in awinh.inc
it looks that scintilla simply don't load file and program is closed  ???
i have try to change type of tx variable ( default is char[] ) to bstring,zstring etc..etc
but nothing
How is then possible that work with older version of dll ?
« Last Edit: July 24, 2014, 06:58:19 AM by Aurel »

Aurel

  • Guest
Re: OpenFileDialog
« Reply #54 on: July 24, 2014, 07:52:33 AM »
Charles
In my testing  WM_SETTEXT work in RichEdit control but  SCI_SETTEXT not in scintilla but
work in old release.
Infact i have found that small file under 400 bytes is loaded ...
so i think that something is wrong with oxygen internal string buffer or memory allocation.

Mike Lobanovsky

  • Guest
Re: OpenFileDialog
« Reply #55 on: July 24, 2014, 10:42:48 AM »
@Charles:

Quote
filter = "All files "+sep+"*.*"+sep+"Oxygen files "+sep+"*.o2bas"

Is this sort of concatenation possible in OxygenBasic at all if sep is a chr(0)? :o

@Aurel:

The filter string in a File Open/Save dialog must explicitly end in two zero bytes. Your filter string will end only in one zero byte at best even if such concatenation is allowed in O2 at all.

This may cause all sorts of memory corruption in other data used in conjunction with such a malformed function call.

Aurel

  • Guest
Re: OpenFileDialog
« Reply #56 on: July 24, 2014, 12:41:54 PM »
Mike
Yes filter string looks like a crazy train... ;D
But that is because i cannot create most standard way used in VB like style.
and i think that problem is not in filter even look crazy...

If you look again in SUB doOpen...
main problem is with scintilla SCI_SETTEXT message
which work in old version of oxygen BUT not in last release...why ?
i don't know  :o

Mike Lobanovsky

  • Guest
Re: OpenFileDialog
« Reply #57 on: July 24, 2014, 06:50:38 PM »
main problem is with scintilla SCI_SETTEXT message
which work in old version of oxygen BUT not in last release...why ?

Aurel,

You shouldn't underestimate the gravity of your filter string problem. It's nature is unpredictable and it may change its behavior randomly under different Oxygen versions that generate different data layouts in the process heap.

The two zero bytes at the end of it are a formal attribute of the end of filter string that signals the File dialog function to stop chopping the string into zero terminated chunks for the dialog's file type prompt combo. If the process heap memory that surrounds your malformed filter string is (unpredictably) tightly packed with meaningful data and there are no two successive zeros found, the function will carry on chopping memory in pieces until it finds (asolutely unpredictably again) a succession of at least two consecutive zero bytes somewhere else. God knows how much valuable data, possibly including that which is related to your edit or Scintilla control calls/messages, may get corrupted in this process.

To kill the bug reliably, you should eliminate all possible bottlenecks that are evident from your code analysis.

Quote
i don't know

To be absolutely sure it won't happen, I'd suggest you do it according to the classic and safest C-style algo:

1. Count the sum of lengths of all the file descriptions and extension patterns that will form up your final filter string.

2. Add the number of zero bytes in between the descriptions and patterns and the two trailing bytes to the above sum.

3. Allocate a fixed-length string buffer (or a byte array) filled with zeros to a length at least equal to the above sum.

4. Use RtlCopyMemory() from kernel32.dll or memcpy() from msvcrt.dll to copy your file description strings and extension patterns successively one after another into that buffer allowing for exactly one zero byte in between them and make sure there are at least two trailing zero bytes at the end of the buffer.

5. Assign the pointer to that string (or byte array) buffer to the lpstrFilter member of OPENFILENAME structure.


Hope this helps to at least make your File Open dialog call programmatically clean.

JRS

  • Guest
Re: OpenFileDialog
« Reply #58 on: July 24, 2014, 08:27:36 PM »
OR

You could use IUP that is known to work.



We have enough wheels in stock, thank you.


Charles Pegge

  • Guest
Re: OpenFileDialog
« Reply #59 on: July 24, 2014, 11:24:53 PM »

OxygenBasic's dynamic string system is based on bstr (olestrings), which are terminated by at least one null. So to ensure 2 nulls, add one more at the end of the filter train.