VisualFBEditor - IDE for FreeBasic

User projects written in or related to FreeBASIC.
Post Reply
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: VisualFBEditor - IDE for FreeBasic

Post by Avata »

Examples: This code can delete the running exe file.

Delete yourself.frm

Code: Select all

'https://github.com/LloydLabs/delete-self-poc
'#Region "Form"
	#ifndef _WIN32_WINNT
		#define _WIN32_WINNT &H0600  '仅仅工作在Windows Vista及以上,编译为64位就只能在Windows系统是64位上正常工作 works with Windows Vista and above. only
	#endif
	#if defined(__FB_MAIN__) AndAlso Not defined(__MAIN_FILE__)
		#ifdef __FB_WIN32__
			#cmdline "Form1.rc"
		#endif
		Const _MAIN_FILE_ = __FILE__
	#endif
	#include once "mff/Form.bi"
	#include once "mff/CommandButton.bi"
	#include once "mff/TextBox.bi"
	#include once "mff/Dialogs.bi"
	
	Function RenameHandle(HHANDLE As HANDLE) As Boolean '重命名文件
		Dim fRename  As FILE_RENAME_INFO '文件重命名结构体
		RtlSecureZeroMemory(@fRename, SizeOf(fRename))
		Dim lpwStream As WString Ptr = @":666666"  ' @":666666" '文件名 'CAllocate((MAX_PATH + 1) * SizeOf(WString))  ' 
		fRename.FileNameLength = SizeOf(lpwStream) '文件名长度
		'SizeOf(lpwStream)=8  SizeOf(fRename)=24     Print "SizeOf(lpwStream)=" & SizeOf(lpwStream) & "  SizeOf(fRename)=" & SizeOf(fRename)  
		RtlCopyMemory(@fRename.FileName, lpwStream, SizeOf(lpwStream)) '填充文件名
		'FileRenameInfo 应更改文件名,用于文件句柄(来源 FILE_INFO_BY_HANDLE_CLASS枚举值)
		'SetFileInformationByHandle 设置指定文件的文件信息
		Return SetFileInformationByHandle(HHANDLE, FileRenameInfo, @fRename, SizeOf(fRename))
	End Function
	
	Function DepositeHandle(HHANDLE As HANDLE) As Boolean
		Dim fDelete As FILE_DISPOSITION_INFO
		fDelete.DeleteFileW = True '指示是否应删除该文件,设置为TRUE以删除文件。如果该句柄使用FILE_FLAG_DELETE_ON_CLOSE打开,则此成员不起作用。
		'FileDispositionInfo应删除该文件,用于任何句柄(来源 FILE_INFO_BY_HANDLE_CLASS枚举值)
		Return SetFileInformationByHandle(HHANDLE, FileDispositionInfo, @fDelete, SizeOf(fDelete))
	End Function
	
	Function DeleteSelf(ByRef wcPath As WString) As Boolean
		'1.打开自身文件,给定 DELETE 权限(仅需要DELETE,在FB中DELETE是关键字,故写成DELETE__)
		Dim hCurrent As HANDLE = CreateFileW(wcPath, DELETE__, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
		If hCurrent = INVALID_HANDLE_VALUE Then 
			Debug.Print "failed to acquire handle to current running process" & hCurrent  '无法获取当前正在运行的进程的句柄
			Return False
		End If
		
		'2.使用 SetFileInformationByHandle 将主文件流 :$DATA 重命名为 :wtfbbq。
		Debug.Print "attempting to rename file name"
		If RenameHandle(hCurrent) = False Then
			Debug.Print "failed to rename to stream!"  '试图重命名文件名,无法重命名
			Return False
		End If
		
		'3.关闭HANDLE
		Debug.Print "successfully renamed file primary :$DATA ADS to specified stream, closing initial handle"
		CloseHandle(hCurrent)
		
		'4.打开自身文件,将 FileDispositionInfo 类的 DeleteFile 设置为 TRUE。
		hCurrent = CreateFileW(wcPath, DELETE__, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
		If hCurrent = INVALID_HANDLE_VALUE  Then 
			Debug.Print "failed to reopen current module! hCurrent=" & hCurrent  '无法重新打开当前模块
			Return False
		End If
		If DepositeHandle(hCurrent) = False Then 
			Debug.Print "failed to set delete deposition!"  '无法设置删除
			Return False
		End If
		
		'5.关闭HANDLE以触发文件处置
		Debug.Print "closing handle to trigger deletion deposition"
		CloseHandle(hCurrent)
		If FileExists(wcPath) = True Then 
			Debug.Print "failed to delete copy, file still exists!" '文件仍然存在,删除失败
			Return False 
		End If
		Return True
	End Function
	
	Using My.Sys.Forms
	
	Type Form1Type Extends Form
		Declare Static Sub _CommandButton1_Click(ByRef Sender As Control)
		Declare Sub CommandButton1_Click(ByRef Sender As Control)
		Declare Static Sub _cmdBrows_Click(ByRef Sender As Control)
		Declare Sub cmdBrows_Click(ByRef Sender As Control)
		Declare Constructor
		
		Dim As CommandButton CommandButton1, cmdBrows
		Dim As TextBox txtFileName
		Dim As OpenFileDialog OpenFileDialog1
	End Type
	
	Constructor Form1Type
		' Form1
		With This
			.Name = "Form1"
			.Text = "Form1"
			.Designer = @This
			.SetBounds 0, 0, 600, 70
		End With
		' CommandButton1
		With CommandButton1
			.Name = "CommandButton1"
			.Text = "Delete yourself"
			.TabIndex = 0
			.SetBounds 10, 10, 90, 20
			.Designer = @This
			.OnClick = @_CommandButton1_Click
			.Parent = @This
		End With
		' txtFileName
		With txtFileName
			.Name = "txtFileName"
			.Text = ExePath & "\" & App.ExeName & ".exe"
			.TabIndex = 1
			.Anchor.Right = AnchorStyle.asAnchor
			.Anchor.Left = AnchorStyle.asAnchor
			.SetBounds 100, 10, 420, 20
			.Designer = @This
			.Parent = @This
		End With
		' cmdBrows
		With cmdBrows
			.Name = "cmdBrows"
			.Text = "..."
			.TabIndex = 2
			.ControlIndex = 0
			.Caption = "..."
			.Anchor.Right = AnchorStyle.asAnchorProportional
			.Anchor.Left = AnchorStyle.asAnchorProportional
			.SetBounds 528, 10, 62, 20
			.Designer = @This
			.OnClick = @_cmdBrows_Click
			.Parent = @This
		End With
		' OpenFileDialog1
		With OpenFileDialog1
			.Name = "OpenFileDialog1"
			.SetBounds 10, 40, 16, 16
			.Designer = @This
			.Parent = @This
		End With
	End Constructor
	
	Private Sub Form1Type._cmdBrows_Click(ByRef Sender As Control)
		(*Cast(Form1Type Ptr, Sender.Designer)).cmdBrows_Click(Sender)
	End Sub
	
	Private Sub Form1Type._CommandButton1_Click(ByRef Sender As Control)
		(*Cast(Form1Type Ptr, Sender.Designer)).CommandButton1_Click(Sender)
	End Sub
	
	Dim Shared Form1 As Form1Type
	
	#if _MAIN_FILE_ = __FILE__
		App.DarkMode = True
		Form1.MainForm = True
		Form1.Show
		App.Run
	#endif
'#End Region

Private Sub Form1Type.CommandButton1_Click(ByRef Sender As Control)
	If FileExists(txtFileName.Text) Then
		'txtFileName.Text = IIf(DeleteSelf(txtFileName.Text), "删除成功", "删除失败")
		MsgBox IIf(DeleteSelf(txtFileName.Text), "Delete successfully", "Delete failed")
	End If
End Sub

Private Sub Form1Type.cmdBrows_Click(ByRef Sender As Control)
	Dim As OpenFileDialog OpenD
	OpenD.InitialDir = ExePath
	OpenD.Caption = "Select a files..." '选择一个文件
	OpenD.Filter = "All Files" & "|*.*|"
	If Not OpenD.Execute Then Exit Sub
	txtFileName.Text = OpenD.FileName
	
End Sub
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: VisualFBEditor - IDE for FreeBasic

Post by Avata »

Who know how to make the same code in OS Linux?
hugodd
Posts: 2
Joined: Apr 13, 2023 23:05

Re: VisualFBEditor - IDE for FreeBasic

Post by hugodd »

Hi, this project is awesome..

But, how do i reduce compilation time?
In my modest machine, the time for compile the basic Form1.frm proyect (gui) without any control or module is close to 20 seconds.. The greatest wait occur in transform .bas to .asm
It seems to compile all Framework. Is there any way to have the framework compiled in a library and only link the exe with it?

Code: Select all

19:57:09: Compilation: "C:\hugo\portableapps\fb\fbc.exe"  -b "Form1.frm" -exx -v -R -s gui -i "C:\hugo\portableapps\visualFBEditor\Controls\MyFbFramework" -d _DebugWindow_=133156

19:57:09: FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win32 (32bit)
19:57:09: Copyright (C) 2004-2021 The FreeBASIC development team.
19:57:09: standalone 
19:57:09: target :       win32, 486, 32bit
19:57:09: backend :      gas
19:57:10: compiling :    Form1.frm -o Form1.asm (main module)
19:57:25: assembling :   C:\hugo\portableapps\fb\bin\win32\as.exe --32 --strip-local-absolute "Form1.asm" -o "Form1.o"
19:57:25: compiling rc :
19:57:25: C :\hugo\portableapps\fb\bin\win32\GoRC.exe /ni /nw /o /fo "Form1.obj" "Form1.rc"
19:57:26: linking :      C:\hugo\portableapps\fb\bin\win32\ld.exe -m i386pe -o "Form1.exe" -subsystem windows -T "C:\hugo\portableapps\fb\lib\win32\fbextra.x" --stack 1048576,1048576 -s -L "C:\hugo\portableapps\fb\lib\win32" -L "." "C:\hugo\portableapps\fb\lib\win32\crt2.o" "C:\hugo\portableapps\fb\lib\win32\crtbegin.o" "C:\hugo\portableapps\fb\lib\win32\fbrt0.o" "Form1.o" "Form1.obj" "-(" -lkernel32 -lgdi32 -lmsimg32 -luser32 -lversion -ladvapi32 -limm32 -lcomctl32 -lcomdlg32 -luuid -lole32 -loleaut32 -liphlpapi -lrasapi32 -lws2_32 -lshlwapi -lshell32 -lddraw -ldxguid -lgdiplus -luxtheme -lfbmt -lgcc -lmsvcrt -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)" "C:\hugo\portableapps\fb\lib\win32\crtend.o"

19:57:27: Layout succeeded! Elapsed Time: 17,93 Seconds
Visual FB Editor (32-bit) version 1.3.4.1925
with FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win32 (32bit) installed on another folder
Windows 11

Thanks!
PeterHu
Posts: 152
Joined: Jul 24, 2022 4:57

Re: VisualFBEditor - IDE for FreeBasic

Post by PeterHu »

Hi my friend,
Is there any document or a workable example for sqlite3component?Thanks.
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: VisualFBEditor - IDE for FreeBasic

Post by Xusinboy Bekchanov »

hugodd wrote: Apr 13, 2023 23:32 Hi, this project is awesome..
Thanks.
hugodd wrote: Apr 13, 2023 23:32 But, how do i reduce compilation time?
In my modest machine, the time for compile the basic Form1.frm proyect (gui) without any control or module is close to 20 seconds.. The greatest wait occur in transform .bas to .asm
It seems to compile all Framework.
The entire library is not included. Only attached files are included. Takes only used functions from included files.
hugodd wrote: Apr 13, 2023 23:32 Is there any way to have the framework compiled in a library and only link the exe with it?
It's not done yet. The convenience of this is that you do not need to carry an extra dll with the exe.
PeterHu wrote: Apr 14, 2023 13:49 Hi my friend,
Is there any document or a workable example for sqlite3component?Thanks.
Added: SQLite3 example:
https://github.com/XusinboyBekchanov/Vi ... 0cf13bcfe1
PeterHu
Posts: 152
Joined: Jul 24, 2022 4:57

Re: VisualFBEditor - IDE for FreeBasic

Post by PeterHu »

Xusinboy Bekchanov wrote: Apr 14, 2023 16:44
hugodd wrote: Apr 13, 2023 23:32 Hi, this project is awesome..
Thanks.
hugodd wrote: Apr 13, 2023 23:32 But, how do i reduce compilation time?
In my modest machine, the time for compile the basic Form1.frm proyect (gui) without any control or module is close to 20 seconds.. The greatest wait occur in transform .bas to .asm
It seems to compile all Framework.
The entire library is not included. Only attached files are included. Takes only used functions from included files.
hugodd wrote: Apr 13, 2023 23:32 Is there any way to have the framework compiled in a library and only link the exe with it?
It's not done yet. The convenience of this is that you do not need to carry an extra dll with the exe.
PeterHu wrote: Apr 14, 2023 13:49 Hi my friend,
Is there any document or a workable example for sqlite3component?Thanks.
Added: SQLite3 example:
https://github.com/XusinboyBekchanov/Vi ... 0cf13bcfe1
Thank you!

It works.

But,In VFBEditor,it doen't run automatically after buiding.Check from the folder the exe has been generated and can run.
compiler message:

Code: Select all

11:07:54: Compilation: "E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\fbc64.exe"  -b "testapp.bas" -exx -v -s console -i "E:\Learning\FreeBasic\VisualFBEditor\Controls\MariaDBBox" -i "E:\Learning\FreeBasic\VisualFBEditor\Controls\MyFbFramework" -i "E:\Learning\FreeBasic\VisualFBEditor\Controls\SQLite3" -d _DebugWindow_=14293296

11:07:54: FreeBASIC Compiler - Version 1.09.0 (2021-12-31), built for win64 (64bit)
11:07:54: Copyright (C) 2004-2021 The FreeBASIC development team.
11:07:54: standalone 
11:07:54: target :       win64, x86-64, 64bit
11:07:54: backend :      gcc
11:07:54: compiling :    testapp.bas -o testapp.c (main module)
11:07:58: compiling C :  E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\bin\win64\gcc.exe -m64 -march=x86-64 -S -nostdlib -nostdinc -Wall -Wno-unused -Wno-main -Werror-implicit-function-declaration -O0 -fno-strict-aliasing -frounding-math -fno-math-errno -fwrapv -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wno-format -masm=intel "testapp.c" -o "testapp.asm"
11:08:00: assembling :   E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\bin\win64\as.exe --64 --strip-local-absolute "testapp.asm" -o "testapp.o"
11:08:00: compiling rc :               E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\bin\win64\GoRC.exe /ni /nw /o /machine X64 /fo "Form1.obj" "Form1.rc"
11:08:00: linking :      E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\bin\win64\ld.exe -m i386pep -o "./release/win64/Untitled.exe" -subsystem console -T "E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\lib\win64\fbextra.x" --stack 2097152,2097152 -s -L "./lib/win64" -L "E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\lib\win64" -L "." "E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\lib\win64\crt2.o" "E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\lib\win64\crtbegin.o" "E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\lib\win64\fbrt0.o" "testapp.o" "Form1.obj" "-(" -lkernel32 -lgdi32 -lmsimg32 -luser32 -lversion -ladvapi32 -limm32 -lcomctl32 -lcomdlg32 -luuid -lole32 -loleaut32 -liphlpapi -lrasapi32 -lws2_32 -lshlwapi -lshell32 -lgdiplus -lddraw -ldxguid -luxtheme -lsqlite3 -lfbmt -lgcc -lmsvcrt -lmingw32 -lmingwex -lmoldname -lgcc_eh "-)" "E:\Learning\FreeBasic\VisualFBEditor\Compilers\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\lib\win64\crtend.o"

11:08:00: Do not build file. Elapsed Time: 6.44 Seconds
I renamed the untitled.bas (before and after renaming,the compiling result is the same,executable file generated successfully but is not running automatically from the IDE.
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: VisualFBEditor - IDE for FreeBasic

Post by Xusinboy Bekchanov »

PeterHu wrote: Apr 15, 2023 3:14 I renamed the untitled.bas (before and after renaming,the compiling result is the same,executable file generated successfully but is not running automatically from the IDE.
You must download the latest unreleased version from github. I fixed it yesterday before posting this example.
PeterHu
Posts: 152
Joined: Jul 24, 2022 4:57

Re: VisualFBEditor - IDE for FreeBasic

Post by PeterHu »

Xusinboy Bekchanov wrote: Apr 15, 2023 4:35
PeterHu wrote: Apr 15, 2023 3:14 I renamed the untitled.bas (before and after renaming,the compiling result is the same,executable file generated successfully but is not running automatically from the IDE.
You must download the latest unreleased version from github. I fixed it yesterday before posting this example.
Yes I did this morning,a full overwrite to the previous VFBEditor folder.
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: VisualFBEditor - IDE for FreeBasic

Post by Xusinboy Bekchanov »

PeterHu wrote: Apr 15, 2023 5:21 Yes I did this morning,a full overwrite to the previous VFBEditor folder.
After you need to build the IDE. To do this, you can rename the current IDE and compile VisualFBEditor.vfp.
PeterHu
Posts: 152
Joined: Jul 24, 2022 4:57

Re: VisualFBEditor - IDE for FreeBasic

Post by PeterHu »

Xusinboy Bekchanov wrote: Apr 15, 2023 5:28
PeterHu wrote: Apr 15, 2023 5:21 Yes I did this morning,a full overwrite to the previous VFBEditor folder.
After you need to build the IDE. To do this, you can rename the current IDE and compile VisualFBEditor.vfp.
c.
how to eliminate console window?The default compiling setting is GUI,but I noticed the compiling process log -console was there.
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: VisualFBEditor - IDE for FreeBasic

Post by Xusinboy Bekchanov »

PeterHu wrote: Apr 15, 2023 5:48 c.
how to eliminate console window?The default compiling setting is GUI,but I noticed the compiling process log -console was there.
Maybe you have a console selected in the toolbar, you must select or gui, or not setted.
PeterHu
Posts: 152
Joined: Jul 24, 2022 4:57

Re: VisualFBEditor - IDE for FreeBasic

Post by PeterHu »

Xusinboy Bekchanov wrote: Apr 15, 2023 5:52
PeterHu wrote: Apr 15, 2023 5:48 c.
how to eliminate console window?The default compiling setting is GUI,but I noticed the compiling process log -console was there.
Maybe you have a console selected in the toolbar, you must select or gui, or not setted.
Done.
Thank you.
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: VisualFBEditor - IDE for FreeBasic

Post by Avata »

The numbering the whole project is terrible output message and useless. I agree that it is better changed to Numbering within current module only. The user can numbering one by one module if they have to do.
Avata
Posts: 102
Joined: Jan 17, 2021 7:27

Re: VisualFBEditor - IDE for FreeBasic

Post by Avata »

The compiler FBC 1.10 released, Any plan to update the VisualFBEditor IDE?
Xusinboy Bekchanov
Posts: 789
Joined: Jul 26, 2018 18:28

Re: VisualFBEditor - IDE for FreeBasic

Post by Xusinboy Bekchanov »

Avata wrote: May 18, 2023 2:43 The compiler FBC 1.10 released, Any plan to update the VisualFBEditor IDE?
When I have time I will release the IDE.
Post Reply