You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
FUNCTION WINMAIN(BYVAL Instance AS LONG, _
BYVAL hPrevInstance AS LONG, _
lpszCmdLine AS ASCIIZ PTR, _
BYVAL nCmdShow AS LONG) AS LONG
END FUNCTION
FUNCTION PBMAIN() AS LONG
END FUNCTION
When using PBMain instead of WINMAIN in PB, how would I retrieve
the Instance (which is available in the WINMAIN Function)?
I agree with Semen... GetModuleHandle is the appropriate function to use. It does not require the creation of a window.
Consider this: In order to create a window with any of the CreateWindow*, CreateDialog* or DialogBox* APIs, you need to use an instance handle for one of the parameters. So you can't really create a window in order to get the instance handle. True, if you use DDT it takes care of the instance handle internally, but it's pretty likely that it uses GetModuleHandle under the hood, (or maybe it captures the WinMain value, I don't know) so you are really going "the long way around" if you create a window in order to get the instance.
And it's pretty inconvenient to create a window in a PB/CC program just to get the instance.
"PBMain" isn't an official Windows function name. I'd speculate that when you type PBMain, the compiler subsitutes WinMain with the appropriate parameters. But if you type WinMain it uses the parameters that you specify. Then, if Windows puts the standard four parameters on the stack when it starts the app, but your program only declares (and thereby automatically removes) one of them... trouble's a-brewing.
It might be perfectly ok to use a single-parameter WinMain, but your code would be responsible for popping the other three off the stack.
Semen & Eric, I totally agree with your first comments!
GetModuleHandle does what I need it to do!
It's interesting to see the different approaches here!
Although I did have a solution, the problem is that PB
(being so powerful), allows me to program without knowing
the faults/traps that await me! which is the
programmers responsiblity in the end.!
However, how can one know without asking? (just what I did)...
Although I knew enough in getting an application (Instance),
what I didn't know, was my coding correct?
In this case, I would have been totally wrong, even though for
the moment, the program function'd correctly!
I'm not gonna butter you all up, but you guys are great!
I think something has been missed here, PBmain() is a lower level
function than WinMain(). WinMain is a leftover from 16 bit windows
but with 32 bit windows, a start function like PBmain is free of the
assumptions of a WinMain.
The instance handle is the actual start address of the PE file
so if you need the instance handle for certain API calls, the correct
way to get it is to use GetModuleHandle(). In PowerBASIC you
usually don't use the API to get the command line but use COMMAND$
instead.
With pseudo code like as follows,
Code:
GLOBAL hInstance as LONG
GLOBAL cmd$
FUNCTION PBmain() as LONG
LOCAL returnval as LONG
hInstance = GetModulehandle(ByVal %NULL)
cmd$ = command$
' allocate memory etc ... here
returnval = MyApplication_Code()
' deallocate memory etc ... here
FUNCTION = returnval
END FUNCTION
The WinMain function is called by the system as the initial entry point for a Win32-based application.
It lists the four standard parameters. It may be a leftover from the days of 16 bits, and at least one of the parameters no longer does anything, but it is still a required function.
However, doesn't the PB-Compiler - when faced with options - trigger which
point of entry ---> WinMain or DllMain etc...
that made when we compile our program EXE or DLL ect...
that's what determines the actual call???
From memory Microsoft C at the time of the change to 32 bit code
had to use WinMain as its entry point as it was still working in
both 16 and 32 bit but at a lower level, 32 bit code does not have
to be done that way.
In MASM you construct the WinMain if you wish to code it that way.
PowerBASIC gives you the option to do the same if you want to do it
that way, you would of course have to call it something else as WinMain
is a reserve word in PowerBASIC.
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Comment