[NO BUG]6.10 Name Space problem

Windows specific forum
User avatar
tft
User
User
Posts: 99
Joined: Mon Dec 29, 2008 9:34 am

[NO BUG]6.10 Name Space problem

Post by tft »

Hallo,

After two nights of hard work, I have identified an issue. It concerns the naming of objects for the following functions.

Nach 2 Nächten harter Arbeit. Habe ich ein Problem festhalten können. Es geht um die Namensgebung für die Objekte folgender Funktionen.

IPname.s = "Grundprogramm"
CreateMutex_(0, 1, IPname.s)
ID= CreateFileMapping_(-1, #Null, #PAGE_READWRITE, 0, 256, IPname.s)


Basically, both functions cannot share the same object name. I have attached a test program for reference.

This issue can be avoided if one is aware of it. However, since these are two different function calls, I suspect it to be a namespace bug. Both functions operate globally.

Grob gesagt, beide Funktionen können nicht den gleichen IPname haben. Ich habe mal ein Testprogramm Rangehängt.

Das Problem lässt sich vermeiden, wenn man weis, das dies so ist. Aber da es sich um 2 unterschiedliche Funktionsaufrufe handelt. Gehe ich von einem NameSpaceBug aus. Beide Funktionen arbeiten Global.

;{ ©Header / Grundprogramm für alle Processe
;
; Programmpaket : Driving Scool Evergarden
; Progrmiersprache : PureBasic 6.10
; Programmart : Process
; Programmteil : Grundprogramm / Main Loop
;
; By | TFT | Temuçin SourceMagic | Schweiz | 2018
; © Turgut Frank Temuçin 2018. Alle Rechte vorbehalten.
; turgut.frank.temucin@sourcemagic.ch
;
; Last Update 25.5.2024
;
;}

;EnableExplicit ; Varriablen müssen declariert werden

#SY_ProgrammName = "Grundprogramm" ; muss dem FileNamen des Code entsprechen
#SY_EventWindow = 0

Define SY_Event ; Enthält den Rückgabe Wert von WindowEvent(), Um in der Eventabfrage das Event zu ermittlen.
Define SY_Quit ; Wenn Quit 1 ist, wird das Programm beändet.

Define SY_PPV1.s = ProgramParameter(0) ; FensterName vom Aufrufenden Programm

Procedure.a SY_ProgramExists(_PN.s)

Protected er.a

; Arbeits Code

CreateMutex_(0, 1, _PN.s)

If (GetLastError_() = #ERROR_ALREADY_EXISTS)
er = #True
Else
er = #False
EndIf

ProcedureReturn er
EndProcedure

If SY_ProgramExists(#SY_ProgrammName) : End : EndIf

SharedMemoryName.s = #SY_ProgrammName
SharedMemorySize = 256
SharedMemoryID = CreateFileMapping_(-1, #Null, #PAGE_READWRITE, 0, SharedMemorySize, SharedMemoryName)

If SharedMemoryID = 0
Define dwError.i = GetLastError_()
If dwError = #ERROR_ALREADY_EXISTS
MessageRequester("Error", "File mapping already exists")
Else
MessageRequester("Error", "Could not create file mapping")
EndIf

End
Else
MessageRequester("Success", "File mapping created successfully")
CloseHandle_(SharedMemoryID)
EndIf

Define SY_HWND = OpenWindow(#SY_EventWindow,0,0,400,30,#SY_ProgrammName, #PB_Window_SystemMenu);

If SY_HWND ; Wurde das Fenster erstellt. Gibt es auch Events die Abgefragt werden müssen

;{ Event Schleife
Repeat

SY_Event = WindowEvent()

If SY_Event <> 0
Repeat
Select SY_Event
Case #PB_Event_CloseWindow ; Programm beenden bei betätigen des CloseBotton (X) am Fenster
SY_Quit = 1
Case #WM_KEYDOWN
Select EventwParam()
Case #ESC ; Programm beenden bei drücken der ESC Taste
SY_Quit = 1
EndSelect
EndSelect
SY_Event = WindowEvent()
Until SY_Event = 0
EndIf
Delay(10) ;

Until SY_Quit <> 0

;}

CloseWindow(#SY_EventWindow)

EndIf

End

I would appreciate hearing whether this is simply my misunderstanding or if it is indeed a bug.

Würde mich freuen zu hören, ob ich nur dumm bin, oder es wirklich ein Bug ist.

Gruss TFT
Last edited by tft on Sun May 26, 2024 1:32 pm, edited 2 times in total.
TFT seid 1989
Aktuelles Projekte : Driving School Evergarden
YouTube : Pure Basic to go
FaceBook : Temuçin SourceMagic Games
DISCORD : SourceMagic
W10 , i9 9900K ,32 GB Ram , GTX Titan , 3 Monitore FHD
ARDUINO Freak :-)
r-i-v-e-r
User
User
Posts: 20
Joined: Thu May 09, 2024 5:18 pm

Re: 6.10 Name Space problem

Post by r-i-v-e-r »

This is by (Microsoft's) design, not necessarily a PB Windows bug.

From the CreateMutexW documentation on MSDN:
If lpName matches the name of an existing event, semaphore, waitable timer, job, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same namespace.

The name can have a "Global" or "Local" prefix to explicitly create the object in the global or session namespace. The remainder of the name can contain any character except the backslash character (\). For more information, see Kernel Object Namespaces. Fast user switching is implemented using Terminal Services sessions. Kernel object names must follow the guidelines outlined for Terminal Services so that applications can support multiple users.

The object can be created in a private namespace. For more information, see Object Namespaces.
Therefore, according to Win32 rules, care must be taken to name the object accordingly to avoid collisions.
Fred
Administrator
Administrator
Posts: 18199
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: 6.10 Name Space problem

Post by Fred »

When using straight API, you need to comply to the API doc, it's not a PB issue
User avatar
tft
User
User
Posts: 99
Joined: Mon Dec 29, 2008 9:34 am

Re: 6.10 Name Space problem

Post by tft »

@r-i-v-e-r

Thanks for the links. They were very insightful.

Danke für die Links. Sie waren sehr aufschlussreich.

@Fred

After looking at the links. I think I understand why that is. Because the functions are so easy in PureBasic
let use. A hobby programmer like this can sometimes get into trouble.

Nachdem ich mir die Links angeschaut habe. Glaube ich zu verstehen, warum das so ist. Da sich die Funktionen so leicht in PureBasic
benutzen lassen. Kann so ein Hobby Programmierer schonmal ins Schleudern geraten.

Thank you for your hard work.
Danke für eure harte arbeit.

TFT
TFT seid 1989
Aktuelles Projekte : Driving School Evergarden
YouTube : Pure Basic to go
FaceBook : Temuçin SourceMagic Games
DISCORD : SourceMagic
W10 , i9 9900K ,32 GB Ram , GTX Titan , 3 Monitore FHD
ARDUINO Freak :-)
Post Reply