I am having a problem with a Dll written in PB being used in other programming languages (VB and .Net in particular) that there are only 2 ways to keep the development IDE from crashing when the program ends.
I have FINALLLLlllly narrowed it down to functions in my dll that get something from the resource file (at first I thought it had something to do with a memory location but fairly sure thats not it)
Below is example code for a dll with one of these functions, just to show what is happening. But what REALLY concerns me, is why by showing the dialog at any time while the program is running, then when you end there is no crash?
But if you don't show the dialog, then there is a crash?
The Dll
The resource file
The Text file to embed
And for simplicity sake the VB code
I just don't get why showing the dialog would prevent a crash, so I wonder if there is something to the "LoadResource" that I am doing wrong?
I have FINALLLLlllly narrowed it down to functions in my dll that get something from the resource file (at first I thought it had something to do with a memory location but fairly sure thats not it)
Below is example code for a dll with one of these functions, just to show what is happening. But what REALLY concerns me, is why by showing the dialog at any time while the program is running, then when you end there is no crash?
But if you don't show the dialog, then there is a crash?
The Dll
Code:
#COMPILE DLL #DIM ALL %USEMACROS = 1 #INCLUDE "Win32API.inc" '*** Load the resource file #RESOURCE "TestResourceDll.pbr" GLOBAL ghInstance AS DWORD GLOBAL HwndDlgEula& %TxtEula = %WM_USER + 100 CALLBACK FUNCTION EulaCallback SELECT CASE CBMSG 'Determine what the event is CASE %WM_INITDIALOG 'If initializing (opening the TerminalSimple) CASE %WM_MDIACTIVATE CASE %WM_MOVE CASE %WM_SETREDRAW CASE %WM_MOUSEWHEEL CASE %WM_COMMAND SELECT CASE CBCTL '*** Dialog Controls routines here END SELECT CASE %WM_SYSCOMMAND CASE %WM_DESTROY CASE ELSE END SELECT END FUNCTION '------------------------------------------------------------------------------- ' Main DLL entry point called by Windows... ' FUNCTION LIBMAIN (BYVAL hInstance AS LONG, _ BYVAL fwdReason AS LONG, _ BYVAL lpvReserved AS LONG) AS LONG SELECT CASE fwdReason CASE %DLL_PROCESS_ATTACH 'Indicates that the DLL is being loaded by another process (a DLL 'or EXE is loading the DLL). DLLs can use this opportunity to 'initialize any instance or global data, such as arrays. ghInstance = hInstance FUNCTION = 1 'success! 'FUNCTION = 0 'failure! This will prevent the EXE from running. CASE %DLL_PROCESS_DETACH 'Indicates that the DLL is being unloaded or detached from the 'calling application. DLLs can take this opportunity to clean 'up all resources for all threads attached and known to the DLL. FUNCTION = 1 'success! 'FUNCTION = 0 'failure! CASE %DLL_THREAD_ATTACH 'Indicates that the DLL is being loaded by a new thread in the 'calling application. DLLs can use this opportunity to 'initialize any thread local storage (TLS). FUNCTION = 1 'success! 'FUNCTION = 0 'failure! CASE %DLL_THREAD_DETACH 'Indicates that the thread is exiting cleanly. If the DLL has 'allocated any thread local storage, it should be released. FUNCTION = 1 'success! 'FUNCTION = 0 'failure! END SELECT END FUNCTION '------------------------------------------------------------------------------------ FUNCTION LoadEula ALIAS "LoadEula"(BYVAL hParent&) EXPORT AS LONG 'Load main program LOCAL Style&, ExStyle& Style& = %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %WS_CHILD OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_CLIPSIBLINGS 'OR %WS_SYSMENU ExStyle& = 0 DIALOG NEW hParent&, "Eula", %CW_USEDEFAULT, %CW_USEDEFAULT, 330, 145, Style&, ExStyle& TO HwndDlgEula& CONTROL ADD TEXTBOX, HwndDlgEula&, %TxtEula, "", 5, 5, 320, 110, _ %WS_CHILD OR %WS_VISIBLE OR %ES_MULTILINE OR %ES_NOHIDESEL OR %ES_WANTRETURN OR %ES_LEFT _ OR %ES_AUTOVSCROLL OR %ES_READONLY OR %WS_VSCROLL OR %WS_TABSTOP 'OR %ES_AUTOHSCROLL OR %WS_HSCROLL OR %WS_EX_ACCEPTFILES'Cant use acceptfiles because code is same as lowercase only DIM EulaSize AS LONG LOCAL EulaAddr AS ASCIIZ PTR '* %MAX_PATH LOCAL EulaString AS STRING EulaSize = SizeOfResource(BYVAL ghInstance, BYVAL FindResource(BYVAL ghInstance, "EULA_AGGREEMENT", BYVAL %RT_RCDATA)) EulaAddr = LoadResource (BYVAL ghInstance, BYVAL FindResource(BYVAL ghInstance, "EULA_AGGREEMENT", BYVAL %RT_RCDATA)) EulaString = @EulaAddr MSGBOX FUNCNAME$ _ + $CR + "HwndDlgEula& = " + STR$(HwndDlgEula&) _ + $CR + "Parent = " + STR$(GetModuleHandle(BYVAL %NULL)) _ + $CR + "Dll = " + STR$(GetModuleHandle("TestResourceDll.dll")) _ + $CR + "Hinst = " + STR$(ghInstance) _ + $CR + "EulaString = " + EulaString REPLACE CHR$(1) WITH "" IN EulaString CONTROL SET TEXT HwndDlgEula&, %TxtEula, EulaString ' '*** Message handler loop 'local Msg as TagMsg ' WHILE GetMessage(Msg, BYVAL %NULL, 0, 0) ' TranslateMessage Msg ' DispatchMessage Msg ' WEND FUNCTION=%True END FUNCTION '------------------------------------------------------------------------------------ FUNCTION ShowEula ALIAS "ShowEula"(BYVAL hParent&) EXPORT AS LONG SELECT CASE HwndDlgEula& 'If handle for Eula doesnt exist then Eula doesnt exist CASE 0 LoadEula BYVAL hParent& 'Reload Eula if it doesnt exist CASE ELSE END SELECT DIALOG SHOW MODELESS HwndDlgEula& END FUNCTION
Code:
#include "resource.h" EULA_AGGREEMENT RCDATA DISCARDABLE "TestEula.txt"
Code:
Live from NY Its SATURDAY NIIIIIIIIIiiiiight
Code:
Private Declare Function LoadEula Lib "TestResourceDll.dll" (ByVal hParent&) As Long 'Load main program Private Declare Function ShowEula Lib "TestResourceDll.dll" (ByVal hParent&) As Long Private Sub Command1_Click() LoadEula 0 End Sub Private Sub Command2_Click() ShowEula 0 End Sub
Comment