Hi folks,
Im having problems with a simple (for now) powerbasic control
im trying to write, to be used in a VB application. For some
reason ive so far been unable to determine, it crashes "sometimes"
after being run, stopped and re-run (sometimes not crashing
until after the 5th+ re-run... sometimes only after the 1st re-run))
Here's the PB control DLL code
Now here's the VB code. The VB program consists of just a
form with a picture box on it.
The DLL compiles fine. The VB code compiles fine. When i run
the VB code, it runs fine >50% of the time. The first
run of the program always works, but when i shut down the VB
app and re-run it, it sometimes crashes. If it doesnt crash
on the first re-run, i only need to re-run the app
over and over and sooner or later it will crash.
This is the first time ive tried to write a DLL that contains
a window to be used in a VB app. Is there something
fundamentally wrong im doing with trying to
draw a window created in PB onto a VB picturebox?
Thanks for any help.
-Mike
Im having problems with a simple (for now) powerbasic control
im trying to write, to be used in a VB application. For some
reason ive so far been unable to determine, it crashes "sometimes"
after being run, stopped and re-run (sometimes not crashing
until after the 5th+ re-run... sometimes only after the 1st re-run))
Here's the PB control DLL code
Code:
#COMPILE DLL "simple.dll" #DIM ALL #REGISTER NONE #INCLUDE "win32api.inc" 'Exported Functions DECLARE FUNCTION CreateControl (BYVAL hWnd AS LONG, BYVAL hInst AS LONG, BYVAL hFont AS LONG, BYVAL fCallBack AS LONG) AS LONG DECLARE FUNCTION TerminateControl (BYVAL hWnd AS LONG) AS LONG ' Private functions DECLARE FUNCTION InitWindow (BYVAL hInstance AS LONG, BYVAL hParent AS LONG) AS LONG FUNCTION CreateControl (BYVAL hWnd AS LONG, BYVAL hInst AS LONG, BYVAL hFont AS LONG, BYVAL fCallBack AS LONG) EXPORT AS LONG DIM hWindow AS LONG ' create the window hWindow = InitWindow (hInst, hWnd) ' pass the handle FUNCTION = hWindow END FUNCTION FUNCTION TerminateControl (BYVAL hWnd AS LONG) EXPORT AS LONG DestroyWindow hWnd FUNCTION = %TRUE END FUNCTION FUNCTION InitWindow (BYVAL hInstance AS LONG, BYVAL hParent AS LONG) AS LONG LOCAL wndclass AS WndClassEx LOCAL szClassName AS ASCIIZ * 80 LOCAL hWnd AS LONG szClassName = "SIMPLE" wndclass.cbSize = SIZEOF(WndClass) wndclass.style = %CS_HREDRAW OR %CS_VREDRAW OR %CS_DBLCLKS wndclass.lpfnWndProc = CODEPTR( WndProc ) wndclass.hInstance = hInstance wndclass.hCursor = LoadCursor( %NULL, BYVAL %IDC_ARROW ) wndclass.hbrBackground = %COLOR_APPWORKSPACE wndclass.lpszMenuName = %NULL wndclass.lpszClassName = VARPTR( szClassName ) IF ISFALSE(RegisterClassEx(wndclass)) THEN RegisterClass BYVAL (VARPTR(wndclass) + 4) END IF ' create the control window hWnd = CreateWindowEx( %WS_EX_LEFT OR %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, _ "SIMPLE", _ BYVAL %NULL, _ %WS_VISIBLE OR %WS_CHILD OR %WS_CLIPCHILDREN OR _ %WS_CLIPSIBLINGS, _ %CW_USEDEFAULT, %CW_USEDEFAULT, %CW_USEDEFAULT, %CW_USEDEFAULT, _ hParent, _ %ID, _ hInstance, _ BYVAL 0 ) ShowWindow hWnd, %SW_MAXIMIZE '1' %SHOW_OPENWINDOW FUNCTION = hWnd END FUNCTION FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _ BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam) END FUNCTION
form with a picture box on it.
Code:
Private Declare Function CREATECONTROL Lib "F:\visualb\projects\gvd\Current\simple.dll" (ByVal hWnd As Long, ByVal hInst As Long, ByVal hFont As Long, ByVal fCallBack As Long) As Long Private Declare Function TERMINATECONTROL Lib "F:\visualb\projects\gvd\Current\simple.dll" (ByVal hWnd As Long) As Long Dim lCtl As Long Private Sub Form_Load() Dim l As Long lCtl = CREATECONTROL(Picture1.hWnd, App.hInstance, 0, 0) End Sub Private Sub Form_Unload(Cancel As Integer) Dim l As Long l = TERMINATECONTROL(lCtl) End Sub
the VB code, it runs fine >50% of the time. The first
run of the program always works, but when i shut down the VB
app and re-run it, it sometimes crashes. If it doesnt crash
on the first re-run, i only need to re-run the app
over and over and sooner or later it will crash.
This is the first time ive tried to write a DLL that contains
a window to be used in a VB app. Is there something
fundamentally wrong im doing with trying to
draw a window created in PB onto a VB picturebox?
Thanks for any help.
-Mike
Comment