The following code generates an "Invalid Memory Access" error on the "End" statement. However, if I comment-out the "CloseLibrary( lib )" statement, then the error does not occur. Strangely, if I leave the "CloseLibrary( lib )" statement uncommented, but comment-out the "mainEditor = CreateWindowEx_( ... )" statement, then the IMA also disappears. It feels as if there is some sort of clash with the built-in Edit control and my instance of a rich edit control when the "msftedit" library is closed. But please let me know what I'm doing wrong
I initially thought it may be something related to the following posts:
http://www.purebasic.fr/english/viewtop ... oselibrary
http://www.purebasic.fr/english/viewtop ... oselibrary
I believe that "CloseLibrary" should not cause any issues, especially as I'm checking that "lib" is an open library. Maybe the instance of my rich edit control is not being released in time for the "CloseLibrary" statement to execute, hence the error...but I'm guessing in the dark
Any comments / suggestions are much appreciated.
Code: Select all
; Windows XP SP3 x86 32-bit
; Purebasic 5.11 (x86)
; Create unicode executable, Create threadsafe executable, Enable debugger
EnableExplicit
Procedure main()
Protected lib.i
Protected hInstance.i
Protected mainWindow.i
Protected mainEditor.i
Protected appQuit.i
Protected eventId.i
hInstance = GetModuleHandle_( 0 )
mainWindow = OpenWindow( #PB_Any, 0, 0, 650, 650, "Editor", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
If ( IsWindow( mainWindow ) )
lib = OpenLibrary( #PB_Any, "msftedit.dll" )
If ( IsLibrary( lib ) )
; Comment-out the next line and the IMA disappears
mainEditor = CreateWindowEx_( #WS_EX_STATICEDGE, "RichEdit50W", "", #WS_VISIBLE | #WS_CHILDWINDOW | #ES_AUTOHSCROLL | #WS_VSCROLL | #ES_MULTILINE | #ES_WANTRETURN | #ES_NOHIDESEL, 16, 64, 580, 540, WindowID( mainWindow ), 200, hInstance, 0 )
EndIf
appQuit = #False
Repeat
eventId = WaitWindowEvent()
Select ( eventId )
Case #PB_Event_CloseWindow
appQuit = #True
EndSelect
Until ( appQuit )
If ( mainEditor )
; Next statement added just in case the rich editor control instance is not being released before CloseLibrary...
SendMessage_( mainEditor, #WM_DESTROY, 0, 0 )
EndIf
If ( IsLibrary( lib ) )
; Comment-out the next line and the IMA disappears
CloseLibrary( lib )
EndIf
EndIf
EndProcedure
main()
End

