Page 1 of 1

#PB_ProcessPureBasicEvents;

Posted: Wed Oct 28, 2015 5:06 pm
by HanPBF
Hello!

When I use a COM control on a PB window with callback like
SetWindowCallback(@onCallback_Sheet(), R)

I got an invalid memory error in
ProcedureReturn #PB_ProcessPureBasicEvents
when mouse moves over OCX control.

Seems like the signature of the callback is not the same for OCX-controls?


How can I use COM controls (OCX) on PB window and using callback?

Any hints for that?

Thanks a lot!
Regards

Re: #PB_ProcessPureBasicEvents;

Posted: Wed Oct 28, 2015 6:00 pm
by ElementE
Hello HanPBF.

I found this report written by Timo that might be of use.

"COM in PureBasic, Part 1 - The Basics"
http://www.rsbasic.de/backupprogramme/COMTutorial.pdf

I do not know if "Part 2" was ever written or made available.

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 7:57 am
by HanPBF
Hi!

Thanks a lot for the hint.

I have another chm help available.

I just dropped the SetWindowCallback and replaced it by BindEvent.

Now, I have the problem that I got an "invalid memory access" error in the window repeat loop at:

Code: Select all

NrEvent = WaitWindowEvent()
Unfortunately, there is no hint given why this appears.

If a mouse over is send for the COM control, the WaitWindowEvent()-call errors...

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 8:22 am
by HanPBF
O.k. I did put a OCX control on the window which is embedded in a ContainerGadget.

When window callback returns #PB_ProcessPureBasicEvents IMA crash.
When dropped setWindowCallback crash in WaitWindowEvent()-loop.

What can I do?
Could a global onError handler help in this case?

Code: Select all

Can a valid memory access be checked before returning #PB_ProcessPureBasicEvents or doing WaitwindowEvent()????
I think the OCX shall have an error in its implementation without being able to crash the whole application...

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 8:37 am
by Bisonte
I think, without code, that reproduce this error, it's difficult.
IMHO not WaitWindowEvent create the error, it's another piece of your code.

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 10:13 am
by HanPBF
Hello Bisonte,

thanks for the hint.

The problem is, that the waitwindowevent-loop crashes after mouseover of OCX-control.
I think that this component produces the error.


When I use the SetWindowCallback and immediately return

Code: Select all

ProcedureReturn #PB_ProcessPureBasicEvents
it crashes at exactly that point ("Invalid memory access. (read error at address 4)").

I did a debug output for (hWnd, uMsg, WParam, LParam); but there is nothing special to see.

Very often when PB crashes at return statement, then the signature of a procedure did not match the needed one.

As PB is not a typed language, any pointer can be given as structure or prototype/callback.
I had often the problem when the signature/count of parameters did not match PB crashed (reasonable of course).

I will try to reproduce the error with another OCX and then send some code.

Thanks a lot!
Regards

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 10:23 am
by HanPBF
O.k. I made some tests.

It's definitely an error in the OCX component.

It has some styling and by switching the style, the program crashes or does not crash.

So, as the OCX has an error, how can I prevent PB from crashing with IMA?

If I use SetWindowCallback ProcedureReturn crashes; if I drop this, WaitWindowevent() crashes.

The correct answer is of course to handle and build up the OCX correctly.
But as I have no source any other error could lead to a total program failure.

Very annoying...

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 10:53 am
by ts-soft
Crash the OCX on exit the window?

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 10:55 am
by HanPBF
Hello Thomas,

no, when using SetWindowCallback in callback procedure at

Code: Select all

ProcedureReturn #PB_ProcessPureBasicEvents
When I don't use SetWindowCallback it crashes in

Code: Select all

repeat
  protected NrEvent = WaitWindowEvent() ; --> crash
forever
It crashes depending on the settings in the OCX component.

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 3:59 pm
by Bisonte
I think I know your problem now.

Is the window or the control target of your callback ?

If your control is the target, don't use SetWindowCallback() function of PB. It's designed for windows only!
You have to use the complete API variant ...

I mean something like this :

Code: Select all

; Set the CallBack
OldProc = SetWindowLongPtr_(hWnd of the control, #GWLP_WNDPROC, @MyWindowCallBack())
SetProp_(Hwnd of the control, "OLDPROC", OldProc)

; and the Callback Procedure like 
Procedure MyWindowCallBack(hWnd, uMsg, wParam, lParam)
  
  Protected OldProc = GetProp_(hWnd, "OLDPROC") ; We need the address
  
  If Not OldProc : ProcedureReturn #Null : EndIf
  
  Select uMsg
    Case #WM_DESTROY
      RemoveProp_(hWnd, "OLDPROC")
    Case Your_Event_to_Check
      ; Your code
  EndSelect
  
  If OldProc
    ProcedureReturn CallWindowProc_(OldProc, hWnd, uMsg, wParam, lParam)
  Else
    ProcedureReturn #Null
  EndIf
  
EndProcedure

Re: #PB_ProcessPureBasicEvents;

Posted: Thu Oct 29, 2015 4:45 pm
by HanPBF
Hello Bisonte,

thanks for Your help!

No, I do a SetWindowCallback only for the window opened.
I tried to debug Hwnd and uwnd, lparam, wparam to find a difference.
But nothing.

But, if I store the window no. in a global variable and compare it:
if Win<>Global_NrWindow_GUI
ProcedureReturn #NULL
endif
...it crashes here in COMatePLUS:

Code: Select all

 id = ContainerGadget(#PB_Any, x, y, width, 	height)
 CloseGadgetList()
with error like "closegadget can only be called after ContainerGadget and Co..."

That seems to show, that somehow the window callback is called also for that ContainerGadget.

And where You are definitive right is that there must be two signatures calling the windows callback.
That's why it IMA errors.

Is it possible to read the call stack/arguments to see if enough arguments are given to callback?
And if signature doesn't match to return #NULL?

So, maybe a vice versa from Your problem suggestion. callback for windows but called by a gadget?

Sayin' it like Ned:
Thanks a lot, indeedeedeediatley!!!

Re: #PB_ProcessPureBasicEvents;

Posted: Fri Oct 30, 2015 9:30 am
by HanPBF
I did this:

Code: Select all

Procedure onCallback_Sheet_GUI(hWnd, uMsg, WParam, LParam)
	static Count 		
	Count + 1		

	if count < 1000
		debug count
		ProcedureReturn #PB_ProcessPureBasicEvents	
	else
		ProcedureReturn #Null
	endif
endProcedure
As I saw hWnd umsg wparam lparam don't change mouse-overing over OCX control, I wanted to force a #Null after some callbacks.

Nothing else -> crash;

Any idea else???

__________________________________________________
Code-Tags added
30.10.2015
RSBasic

Re: #PB_ProcessPureBasicEvents;

Posted: Fri Oct 30, 2015 10:18 am
by Bisonte
I said this before : You don't have use SetWindowCallback() or #PB_ProcessPureBasicEvents if your target is not a window created by PureBasic !

Re: #PB_ProcessPureBasicEvents;

Posted: Fri Oct 30, 2015 10:25 am
by HanPBF
Hello Bisonte!

I use it for OpenWindow()-window...

When I not set it, program crashes at WaitWindowEvent() in the event-loop.

Unfortunately, OCX-component is guilty; when styled in another way it crashes.

Problem is: crash seems not be possible to be try-catched.

Thanks so far...
I consider it as a very risk to use COM/OCX with PB no matter where the problem is.