Page 1 of 1
Expose WinMain parameters as predefined constants
Posted: Fri May 02, 2008 11:10 pm
by Tipperton
In a C/C++ program you'd define the main function as:
Code: Select all
long main(unsigned long hInstance, unsigned long hPrevInst, char *lpszCmdLine, long nCmdShow)
to have access to the parameters Windows passes to the program, since PureBasic doesn't use a main function, it would be nice if these parameters were exposed as predefined constants so we could have access to them as well if needed.
Another way would be to allow us to define our own main function, like this:
Code: Select all
Procedure.l main(hInstance.l, hPrevInst.l, lpszCmdLine.s, nCmdShow.l)
PureBasic would behave normaly, but if you define this main function, PureBasic's startup code would call it instead of the first line of code outside any procedures.
Posted: Fri May 02, 2008 11:20 pm
by Joakim Christiansen
You do know about the ProgramParameter() function right? I don't get why you would need a "main function" really.
Posted: Fri May 02, 2008 11:37 pm
by Tipperton
I know about ProgramParameter function and I also know that you can get hInstance through the Windows API with GetModuleHandle_(0), but so far I haven't figured out an easy way to get the two parameters.
I just think it'd be nice if PureBasic made them readily available as other languages do.
And no, a main function isn't needed, I just presented that as an option, predefined constants would work fine too.
Code: Select all
#INSTANCE
#PREVINST
#CMDLINE
#CMDSHOW
Posted: Sat May 03, 2008 12:54 am
by Joakim Christiansen
Aha, okay, then I agree

Posted: Sat May 03, 2008 1:09 am
by Edwin Knoppert
For dll's pb does pass the minimal info like hinstance.
For your exe you can use GetModuleHandle_( "" ) which imo is a poor way of doing this.
The instance handle *should* be present somehow imo.
The winapi previnstance variable is obsolete in win32.
To know the showcommand you can use GetStartupInfo_()
So it is solvable but if it's nice..?
Posted: Sat May 03, 2008 1:44 am
by Tipperton
So something like this:
Code: Select all
hInstance.l=GetModuleHandle_(0)
hPrevInst.l=0
GetStartupInfo_(info.STARTUPINFO)
nCmdShow.l=info\wShowWindow
lpszCmdLine.s=""
n.l=CountProgramParameters()-1
For i.l=0 To n
If i
lpszCmdLine+" "
EndIf
p.s=Trim(ProgramParameter(i))
If Len(p)=0
lpszCmdLine+#DOUBLEQUOTE$+#DOUBLEQUOTE$
ElseIf FindString(p, " ", 1)>0
lpszCmdLine+#DOUBLEQUOTE$+p+#DOUBLEQUOTE$
Else
lpszCmdLine+p
EndIf
Next i
I know the hPrevInst and the lpszCmdLine stuff isn't really needed, just showing it for completeness of what Windows would pass to a program.
Posted: Sat May 03, 2008 1:52 am
by ts-soft
This is win only, PureBasic isn't win only.
For what should this usefull?
Posted: Sat May 03, 2008 2:50 am
by Tipperton
ts-soft wrote:This is win only
So are the Windows API calls like GetModuleHandle_() and GetStartupInfo_().
ts-soft wrote:PureBasic isn't win only.
So we should remove anything that is platform specific from it?
Posted: Sat May 03, 2008 3:56 am
by ts-soft
Tipperton wrote:
So we should remove anything that is platform specific from it?
No, for this is the API.
The Values only usefull for API, so you can find the values with API.
Posted: Sat May 03, 2008 2:26 pm
by Tipperton
OK
Although this feature would be more convenient, I'll just save the code that gets the information in a template and just add it to any project where it's needed.
I didn't know about the GetStartupInfo_() call before as a way to get nCmdShow so I thought adding this feature was the only way to get it.
Moderators, you can move this topic to Windows programming if you like.