Page 5 of 29

Re: yaP - yet another Portablizer

Posted: Fri Dec 28, 2012 8:31 am
by tproli
My first tries were also disappointing but the file size depends on what compiler you use and on the included symbols. Currently I have 200+ lines of code and the resulting exe is 14.5 KB , and a 4.1 KB icon is also included (using BCX). I'm expecting the final size somewhere around 20 KB.

Re: yaP - yet another Portablizer

Posted: Fri Dec 28, 2012 10:20 am
by guinness
Yeh after I posted I thought the compiler would be the issue. What one are you using?

Re: yaP - yet another Portablizer

Posted: Fri Dec 28, 2012 1:24 pm
by Ascend4nt
guinness wrote:I just compiled this with MingGW gcc and the exe came out as 527 KB.
guinness, try using the 'strip' tool on the executable. mingw and the like have a habit of tacking on humongous amounts of debug information, even if you don't ask for it in the compile. It should be in the mingw\bin folder. (use: strip -s filename.exe)

Re: yaP - yet another Portablizer

Posted: Fri Dec 28, 2012 1:40 pm
by tproli
I'm using lcc that came with the BCX download (http://www.bcxgurus.com/). Switched to PellesC but as it produced larger exe I returned (probably it could be tweaked too).

Re: yaP - yet another Portablizer

Posted: Fri Dec 28, 2012 1:44 pm
by Ascend4nt
Since tproli sent me a message looking for easy-to-use and small-executable-producing languages, I PM'd him about FreeBASIC. I decided I'd post it here since others seem to be following his interest as well.

FreeBASIC is an odd little mix of Basic and object-oriented programming that has won me over as a casual programming language with semi-powerful additions. I don't know how many people have worked with object-oriented languages, but it really does make a big difference in productivity. And the fact that the Basic/OOP code is compiled directly to executables that are quite small makes it a great combo.

Here's some useful links for anyone wishing to mess with it:
FreeBASIC Programming Language: http://www.freebasic.net/
FBIDE - Simple useful IDE: http://fbide.freebasic.net/
FreeBasic.net Forums - Tutorials and FAQs: http://www.freebasic.net/forum/viewtopi ... =2&t=10830
VISG - GUI Editor & Code Generator: http://www.dreamincode.net/forums/topic ... you-think/

Btw, there's only 32-bit support as of the moment, but that's hardly an issue with 90% of the programs anyone will write.

Re: yaP - yet another Portablizer

Posted: Sat Dec 29, 2012 5:42 pm
by Midas
tproli wrote:@Midas
Mind to care your findings? All I got when visiting the forum you linked is
"Sorry Guest, you are banned from using this forum!"
(yesterday it was working)
It's working alright from here, with Pale Moon 15.3.2-x64... :|

Re: yaP - yet another Portablizer

Posted: Sat Dec 29, 2012 11:46 pm
by tproli
FreeBasic looks nice. The IDE and the compiler seems perfectly portable though I haven't tested thoroughly.

Unfortunately I would need to modify many things in my BCX script to make it work in FB.

In the Help I couldn't find how to run .bat files silently (no window to show). I guess it is possible somehow - is it? Even in the forum I haven't find anything but it is an important feature of yaP.

@Midas
I'm still banned from the forum. Probably because I'm on a shared network atm, will try again from elsewhere a few days later.

Re: yaP - yet another Portablizer

Posted: Sun Dec 30, 2012 6:41 am
by SYSTEM
tproli wrote: In the Help I couldn't find how to run .bat files silently (no window to show). I guess it is possible somehow - is it? Even in the forum I haven't find anything but it is an important feature of yaP.
This might work:

Code: Select all

SHELL "CALL script.bat"

Re: yaP - yet another Portablizer

Posted: Sun Dec 30, 2012 11:13 am
by Ascend4nt
Here's a way to run a batch file hidden (in FreeBASIC) and wait for it to exit:

Code: Select all

#define _UNICODE 1
#define UNICODE 1
#include "windows.bi"
#include "win\shellapi.bi"
#include "win\objbase.bi"

'' The easy way (can't wait for termination though):
''ShellExecute(0,"","test.bat",0,0,SW_HIDE)

'' The longer way..
Function ShellExWait(ByRef sFile As WString, _
    ByRef sParams As WString,_
    ByRef sDir As WString, _
    ByVal nShow As Integer) _
     As Integer
    
    Dim stShEx As SHELLEXECUTEINFOW 
    With stShEx
        .cbSize = sizeof(SHELLEXECUTEINFOW)
        .fMask = SEE_MASK_NOCLOSEPROCESS
        .hwnd = 0
        .lpVerb = 0
        .lpFile = @sFile
        .lpParameters = @sParams
        .lpDirectory = @sDir
        .nShow = nShow
        .hInstApp = 0
        .lpIDList = 0
        .lpClass = 0
        .hkeyClass = 0
        .dwHotKey = 0
        .hIcon = 0
        .hProcess = 0
    End With
    
    If (ShellExecuteEx(@stShEx) = FALSE) Then
        Return -1
    End If
    
    Dim hProcess As HANDLE
    hProcess = stShEx.hProcess
''
    WaitForSingleObject(hProcess, INFINITE)
    
    Dim dwExitCode As DWORD
    dwExitCode = -1

    GetExitCodeProcess(hProcess, @dwExitCode)
    CloseHandle(hProcess)
    
    Return dwExitCode
End Function

    '' Important for certain 'ShellExecute' commands (requires linking in libole32):
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED Or COINIT_DISABLE_OLE1DDE)

    '' Prevent critical errors pop-ups
	SetErrorMode(SEM_NOOPENFILEERRORBOX Or SEM_FAILCRITICALERRORS)

    Dim nExitCode As Integer
    
    '' Change to SW_SHOW to show the command prompt:
    nExitCode = ShellExWait("test.bat", "", "", SW_HIDE)
    Print "ExitCode = ";nExitCode
    Sleep
Note that you'll need to link in 'libole32' if you keep CoInitializeEx (it's not needed for running batch files).To compile with it, however, your command line to fbc.exe should include "-l libole32". (This can be adjusted in the IDE in View->Settings->FreeBASIC). You can also adjust it to compile a GUI version of the application with "-s gui", which won't show any command prompts at all.

*edit: added CloseHandle(). Also.. note that 'CreateProcess' is an alternative method of launching batch files.

Re: yaP - yet another Portablizer

Posted: Sun Dec 30, 2012 11:49 am
by tproli
Thanks for the examples. I figured out how to make things work in FB and the two missing features are also included (that I couldn't add with BCX).

File size of yaP.exe started to grow when testing some features in FB. I had to add user contributed libraries to make some things work, e.g. reading ini files, manipulating the registry, embedding a file in the exe. Though the size is not as large as in the case of AutoIt but multiplies of the BCX version (which is 14.5 KB uncompressed, pretty impressive).

So basically everything is ready to move it to FB but I don't know if it's really worth the trouble. I'm also waiting to see the BCX forum as now I cannot access it and see if there's anything about those missing features. Neither of them is essential so I'm about to say that the BCX version of yaP is just fine in its current state.

Re: yaP - yet another Portablizer

Posted: Sun Dec 30, 2012 12:50 pm
by Ascend4nt
tproli,

Well the main reason I encouraged you to use FreeBASIC, besides the extras, was wide string (unicode) support. If you ignore unicode in windows, you're leaving out support for any foreign characters or languages. And choosing to live in the dark ages, basically.

When I looked at BCX last it seemed like it only supports ANSI strings natively. However, there are 'LPOLESTR' windows types (see ANSITOWIDE at BCX Unicode Functions), and BSTR types (see SYSSTR function). However, it doesn't appear there is support for BSTR or LPOLESTR strings in the native functions where these types matter (registry, file and string functions). I haven't tested this myself, but there seems to be a lack of documentation or discussion on it.

But hey, its your program.. I was only trying to nudge you in the right direction.

Oh, and if you need to reach that BCX forum you can just use a proxy.. the simplest are web-based ones - see Proxy 4 Free.

Re: yaP - yet another Portablizer

Posted: Sun Dec 30, 2012 11:42 pm
by tproli
Proxy helped, thanks. Not so much noise on that forum though...

Looks like I cannot avoid FreeBASIC, right? :)

Is there any special thing that I have to watch in FB, or using "standard" code would add unicode support automatically?

Re: yaP - yet another Portablizer

Posted: Mon Dec 31, 2012 3:04 am
by tproli
First issue in FreeBasic: getting name of the executable, eg. yaP.exe -> yaP, MyAppPortable.exe -> MyAppPortable:

Code: Select all

#Include Once "windows.bi"

Const AppName = "yaP"

Dim BaseName As ZString * 14 = RTRIM(dir(command$(0)), ".exe")

MessageBox(NULL, BaseName, AppName, 0+16+262144)
When renaming the exe to "Árvíztűrő tükörfúrógép" the exe shows up nothing.

In BCX the messagebox shows "Árvízturo tükörfúrógép". Notice the difference between "ű" and "u". Tried using unicode functions too but with no luck.

As for AutoIt, all fine.

Re: yaP - yet another Portablizer

Posted: Mon Dec 31, 2012 4:54 am
by Ascend4nt
So, I messed about with FBX a bit.. apparently theres a '-u' option on the command-line that sets 'unicode output'.. however, the code that's generated is anything but! The only difference on the output is there's the '#define UNICODE' stuff.. which makes it impossible to compile properly because char != wchar_t!! FBX is pretty neat otherwise..

I also looked at QB64, but it looks like unicode support was 'planned' but never implemented.. so, of all the modern basic's out there, it appears FreeBASIC is as close to full unicode support as you'll get. The only thing is the deal with the allocation/resizing requirements for WStrings - which is why I developed that 'WideString' class I mentioned..

But anyway, getting to the recent matter. For unicode support, you'll always need to '#define UNICODE' and '_UNICODE' before any windows or CRT includes - this will ensure the right CRT/API functions are invoked. As for getting the module name.. here's one way to do it:

Code: Select all

#define _UNICODE 1
#define UNICODE 1
#include "windows.bi"

Function ExeName() As WString Ptr
  Dim sExeName As WString * MAX_PATH
  Dim nLen As Integer
  Dim sRet As WString Ptr
  nLen = GetModuleFileName(NULL, sExeName, MAX_PATH)
  
  sRet = Allocate( (nLen + 1) * Len(WString) )
  If nLen = 0 Then
      *sRet = ""
  Else
      *sRet = sExeName
  End If
  Return sRet
End Function

'' == MAIN ==

Dim sFileName As WString Ptr
sFileName = ExeName()

MessageBox(0, !"Filename:\n" + *sFileName, "Name of Executable", MB_OK Or MB_ICONINFORMATION)
Note the ugly 'Allocate'.. that's not something we really should be doing manually in that language. Also note that 'sFileName' will need to be DeAllocated after your done with it. WideString fixes both issues relatively easily. For now the above should suffice for what you need so far..

I'm thinking perhaps there's a more proper place to discuss this, as opposed to spamming the thread with code.. maybe on the freebasic forum?

Re: yaP - yet another Portablizer

Posted: Mon Dec 31, 2012 6:15 am
by guinness
No, I'm learning from this! :mrgreen: