Modules first initialize at the first use
Modules first initialize at the first use
Modules first initialize at the first use or a new command InitModule for dll's
When starting an application or loading a dll, the code is always executed in the module.
This is not always good. Had problems when using modules in dll's with windows 10 x64 as COM-DLL at the registration.
When starting an application or loading a dll, the code is always executed in the module.
This is not always good. Had problems when using modules in dll's with windows 10 x64 as COM-DLL at the registration.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Modules first initialize at the first use
That's not quite right -- it depends on the code. If all executable code is inside of procedures, nothing will be executed automaticallymk-soft wrote:When starting an application or loading a dll, the code is always executed in the module.
(except from those 4 special procedures in case of a DLL).
Re: Modules first initialize at the first use
I do not mean that.
Of course, procedure is not called automatically.
But the code in the module.
Logfile from ClassDebug. Link http://www.purebasic.fr/english/viewtop ... 12&t=68101
Of course, procedure is not called automatically.
But the code in the module.
Code: Select all
DeclareModule foo
Global var
EndDeclareModule
Module foo ; This is running before DLL AttachProcess
; this can crash under Windows 10 as X64-DLL
var = Random(100)
; this work stable
Procedure do()
var = Random(100)
EndProcedure : do()
EndModule
Start Logging: 2017-03-25 17:17:22
[ClassValues.] Begin Initalize Module
[ClassValues.] End Initalize Module
[COM.DLL] AttachProzess
[COM.DLL] GetClassObject: Object ok
[ClassFactory.AddRef] RefCounterer: 1
[ClassFactory.AddRef] RefCounterer: 2
...
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Modules first initialize at the first use
You didn't understand what I wrote:mk-soft wrote:I do not mean that.
Of course, procedure is not called automatically.
But the code in the module.Code: Select all
DeclareModule foo Global var EndDeclareModule Module foo ; This is running before DLL AttachProcess ; this can crash under Windows 10 as X64-DLL var = Random(100) ; this work stable Procedure do() var = Random(100) EndProcedure : do() EndModule
Any code in the module is executed automatically, only if it is outside of a procedure.
That means: Just put all your executable module code inside procedures, and then it will not be executed automatically (except from those 4 special procedures in case of a DLL)..
Re: Modules first initialize at the first use
wait - the compiler doesn't report an error, when executeable programcode if outside procedures, when it create a DLLs?
If yes - this should be changed...
If yes - this should be changed...
Re: Modules first initialize at the first use
I'm aware.That means: Just put all your executable module code inside procedures
However, macros automatically create an initalization procedure, which must also be called.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Modules first initialize at the first use
BTW: PB documentation writes
Obviously this is a general rule, which is not specific for modules.When writing a DLL, all the code is done inside procedures.
I agree.GPI wrote:wait - the compiler doesn't report an error, when executeable programcode if outside procedures, when it create a DLLs?
If yes - this should be changed...
Re: Modules first initialize at the first use
But so it still worksGPI wrote:wait - the compiler doesn't report an error, when executeable programcode if outside procedures, when it create a DLLs?
If yes - this should be changed...
I like this
Code: Select all
ProcedureDLL AttachProcess(Instanz)
; with new command
InitModule MyModule
; with first calling of
UseModule MyModule
EndProcedure
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
-
- Addict
- Posts: 4527
- Joined: Thu Jun 07, 2007 3:25 pm
- Location: Berlin, Germany
Re: Modules first initialize at the first use
You can do this already pretty easily:mk-soft wrote: I like thisCode: Select all
ProcedureDLL AttachProcess(Instanz) ; with new command InitModule MyModule ; with first calling of UseModule MyModule EndProcedure
In your module, create a procedure say named Init() that contains the necessary code.
Then call this procedure for initialising the module.
Re: Modules first initialize at the first use
I know,Little John wrote: You can do this already pretty easily:
In your module, create a procedure say named Init() that contains the necessary code.
Then call this procedure for initialising the module.
but please show my Module BaseClass ClassDispatch. It´s not so easy with macros...
One way is to add all initialize-procedures into a linked list. but use code outside procedures too.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Modules first initialize at the first use
https://en.wikibooks.org/wiki/Pascal_Programming/Units
PB only took some 'easy parts' and could have fixed other parts (keywords to specify visibility instead of duplication, or at least offer IDE help (CTRL+SHIFT+C in Lazarus)). PB: No Initialization and Finalization, no global scope available, no overriding of standard commands possible. As in: Pascal did it almost right way back in 1977...
PB only took some 'easy parts' and could have fixed other parts (keywords to specify visibility instead of duplication, or at least offer IDE help (CTRL+SHIFT+C in Lazarus)). PB: No Initialization and Finalization, no global scope available, no overriding of standard commands possible. As in: Pascal did it almost right way back in 1977...