Announcement

Collapse
No announcement yet.

LoadResource Pb Dll in other programming languages

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • LoadResource Pb Dll in other programming languages

    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
    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
    The resource file
    Code:
    #include "resource.h"
    
         EULA_AGGREEMENT          RCDATA DISCARDABLE "TestEula.txt"
    The Text file to embed
    Code:
    Live from NY
    
    Its SATURDAY NIIIIIIIIIiiiiight
    And for simplicity sake the VB code
    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
    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?
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "

  • #2
    I know what exactly is causing your problem, and it has nothing to do with a dialog.

    But rather than tell you in so many words, I just show you the two relevant code lines and let you find your own mistake...

    Code:
    EulaAddr = LoadResource (BYVAL ghInstance, BYVAL FindResource(BYVAL ghInstance, "EULA_AGGREEMENT", BYVAL %RT_RCDATA))
    EulaString = @EulaAddr
    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Ok, broken down, step by step (mostly thinking out loud here)

      LoadResource(

      HMODULE hModule, // resource-module handle
      HRSRC hResInfo // resource handle
      hModule: Identifies the module whose executable file contains the resource.
      Aka...My Dll so use ghInstance

      Notes: If hModule is NULL, Windows loads the resource from the module that was used to create the current process.
      Hence ghInstance because module used is in DLL not the Exe mapping my dll into its space

      hResInfo: Identifies the resource to be loaded. This handle MUST be created by using the FindResource or FindResourceEx function.
      Yep did that.

      Return Values :If the function succeeds, the return value is a handle to the global memory block containing the data associated with the resource.
      If the function fails, the return value is NULL. To get extended error information, call GetLastError.
      I get the handle but Added calls to GetLastError anyways and reply was
      The operation completed successfully.
      and my messagebox shows the correct response in my "EulaString" variable...so what I am doing wrong totally eludes me
      Engineer's Motto: If it aint broke take it apart and fix it

      "If at 1st you don't succeed... call it version 1.0"

      "Half of Programming is coding"....."The other 90% is DEBUGGING"

      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

      Comment


      • #4
        Hint #2:
        LoadResource does NOT return an address.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          What in the world?

          Recompiled, and eliminated anything I could possibly think of, and added as many comments from documentation, and still have the same results. (Hell I even tried a test to see if LoadResource creates a thread that was not properly completed, and nothing came of it) so I am at wits end, there is some KEY point or concept I am missing.

          Showing the dialog fixes things (gawwwwwwd knows why?) but would be pretty silly for me to have to show the dialog and hide it again as a work-around to escape a crash.

          any comments on the below? or do my comments "mis-read" what the docs state? (I think not, because the one way that works as far as data from a res file, is also what crashes some how?)

          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
          
          '-------------------------------------------------------------------------------
          ' 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 EulaHandle AS DWORD
              LOCAL EulaAddr AS ASCIIZ PTR '* %MAX_PATH
              LOCAL EulaString AS STRING
              LOCAL TempFindResource AS DWORD
              LOCAL lResult AS LONG
              LOCAL ErrorBuf AS ASCIIZ * %MAX_PATH
          '*** Win32Api.hlp describes
          'FindResource(
          '    HMODULE hModule,     // resource-module handle
          '    LPCTSTR lpName,      // pointer to resource name
          '    LPCTSTR lpType       // pointer to resource type
          '   )
          '*** However Win32Api.Inc describes
          'FindResource(
          '    BYVAL hInstance AS DWORD,  // resource-module handle        <--- My dll instance
          '    lpName AS ASCIIZ,          // pointer to resource name      <--- Asciiz instead of pointer?
          '    lpType AS ASCIIZ           // pointer to resource type      <--- Asciiz instead of pointer?
          '    ) AS LONG
          
          '    TempFindResource = FindResource(BYVAL ghInstance, "EULA_AGGREEMENT", "RT_RCDATA")              '<--- GetLastError says no error, but no handle returned
              TempFindResource = FindResource(BYVAL ghInstance, "EULA_AGGREEMENT",  BYVAL %RT_RCDATA)         '<--- Handle returned, and GetLastError says no error
          '*** Just to show Error or No Error
              lResult = GetLastError()
              FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, lResult, %NULL, ErrorBuf, SIZEOF(ErrorBuf), BYVAL %NULL
              MSGBOX "TempFindResource = " + STR$(TempFindResource) + $CR + ErrorBuf
          
          '*** Win32Api.hlp describes
          'LoadResource(
          '    HMODULE hModule,     // resource-module handle
          '    HRSRC hResInfo       // resource handle
          '   )
          '*** However Win32Api.Inc describes
          'LoadResource(
          '    BYVAL hInstance AS DWORD, // resource-module handle
          '    BYVAL hResInfo AS DWORD   // resource handle
          '   )
          
          '    EulaAddr = LoadResource (BYVAL ghInstance, BYVAL FindResource(BYVAL ghInstance, "EULA_AGGREEMENT", byval %RT_RCDATA))
              EulaAddr = LoadResource (ghInstance, TempFindResource)
          '*** Just to show Error or No Error
              lResult = GetLastError()
              FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, lResult, %NULL, ErrorBuf, SIZEOF(ErrorBuf), BYVAL %NULL
              MSGBOX "EulaAddr = " + STR$(EulaAddr) + $CR + ErrorBuf
          
              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
          '*** <--- OK so either I REALLLLLLY do not get it, or I did it right the 1st time
          '*** <--- If that is the case then, why a crash unless I show the bleeping dialog????
          
          '*** Put the results in the textbox
              CONTROL SET TEXT HwndDlgEula&, %TxtEula, EulaString
          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
          MCM...if you know what it is, I could use a bigger sledgehammer to the head to see it
          (I only called it address by name only, as far as I know)
          Engineer's Motto: If it aint broke take it apart and fix it

          "If at 1st you don't succeed... call it version 1.0"

          "Half of Programming is coding"....."The other 90% is DEBUGGING"

          "Document my code????" .... "WHYYY??? do you think they call it CODE? "

          Comment


          • #6
            Hint # 3:
            >I only called it address by name only, as far as I know)

            Believe it or not, Master Yoda to the rescue: "That is why you fail."

            (Really!)

            MCM
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              I'll bet everyone else who can see the problem is enjoying this, a lot.
              Michael Mattias
              Tal Systems Inc. (retired)
              Racine WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                well I enjoy your fun at whatever I am missing....

                Must be nice to be in the drivers seat and see what I am missing

                (must be something apparent and basic if I cant see it)
                Engineer's Motto: If it aint broke take it apart and fix it

                "If at 1st you don't succeed... call it version 1.0"

                "Half of Programming is coding"....."The other 90% is DEBUGGING"

                "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                Comment


                • #9
                  Use a bigger hammer. (or at least an orange one)

                  What MCM is hinting at is the LoadResource() api does not return a pointer, it returns a resource handle. Then you have to use something like LockResource() to turn that in to a pointer that you can use to get at the data. Also use SizeofResource() so you will know how much data to collect. Do a search on LockResource to see many examples.

                  PS. There is a "uglyhammer" smiley icon on this forum I was going to use since you said "I could use a bigger sledgehammer to the head to see it" but I did not want you to take it the wrong way.
                  "I haven't lost my mind... its backed up on tape... I think??" :D

                  Comment


                  • #10
                    Cliff,
                    Like William said, LockResource could be use.
                    Also, I did change many littles things to your original code.
                    Added the LockResource in question, removed %WS_CHILD in dialog style,
                    used modal instead of modeless etc.

                    Is this doing what you want?

                    Code:
                    #COMPILE DLL "TestResourceDll.dll" '#Win 8.04#
                    #DIM ALL
                    #INCLUDE "Win32API.inc" '#2005-01-27#
                    #RESOURCE "TestResourceDll.pbr"
                     
                    %USEMACROS = 1
                     
                    GLOBAL ghInstance  AS DWORD
                    GLOBAL HwndDlgEula AS DWORD
                     
                    %TxtEula = 101
                    '______________________________________________________________________________
                     
                    FUNCTION LIBMAIN (BYVAL hInstance   AS LONG, _
                                      BYVAL fwdReason   AS LONG, _
                                      BYVAL lpvReserved AS LONG) AS LONG
                     
                     SELECT CASE fwdReason
                     
                       CASE %DLL_PROCESS_ATTACH
                           ghInstance = hInstance
                           FUNCTION = 1
                     
                       CASE %DLL_PROCESS_DETACH
                           FUNCTION = 1
                     
                       CASE %DLL_THREAD_ATTACH
                           FUNCTION = 1
                     
                       CASE %DLL_THREAD_DETACH
                           FUNCTION = 1
                     
                     END SELECT
                     
                    END FUNCTION
                    '______________________________________________________________________________
                     
                    FUNCTION LoadEula ALIAS "LoadEula"(BYVAL hParent AS DWORD) AS LONG
                     LOCAL ErrorBuf   AS ASCIIZ * %MAX_PATH
                     LOCAL lResult    AS LONG
                     LOCAL EulaSize   AS LONG
                     LOCAL EulaAddr   AS DWORD
                     LOCAL hResource  AS DWORD
                     LOCAL hGlobal    AS DWORD
                     LOCAL Style      AS DWORD
                     LOCAL ExStyle    AS DWORD
                     LOCAL EulaString AS STRING
                      
                     hResource = FindResource(BYVAL ghInstance, "EULA_AGGREEMENT", BYVAL %RT_RCDATA)
                     IF hResource THEN
                       hGlobal = LoadResource(ghInstance, hResource)
                       EulaSize = SizeofResource(ghInstance, hResource)
                       IF hGlobal THEN
                         EulaAddr = LockResource(hGlobal)
                         IF EulaAddr THEN
                           EulaString = PEEK$(EulaAddr, EulaSize)
                         END IF
                       END IF
                     END IF
                     
                     MSGBOX FUNCNAME$                                                        & $CRLF & _
                            "HwndDlgEula& = " & STR$(HwndDlgEula)                            & $CRLF & _
                            "Parent = "       & STR$(GetModuleHandle(BYVAL %NULL))           & $CRLF & _
                            "Dll = "          & STR$(GetModuleHandle("TestResourceDll.dll")) & $CRLF & _
                            "Hinst = "        & STR$(ghInstance)                             & $CRLF & _
                            "EulaString = "   & EulaString
                     
                     Style = %WS_SYSMENU OR %WS_MINIMIZEBOX OR %WS_MAXIMIZEBOX OR %DS_MODALFRAME OR %WS_CAPTION OR %WS_CLIPSIBLINGS
                     ExStyle = 0
                     DIALOG NEW hParent, "Eula", , , 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
                     
                     CONTROL SET TEXT HwndDlgEula, %TxtEula, EulaString
                     
                     DIALOG SHOW MODAL HwndDlgEula
                     
                    END FUNCTION
                    '______________________________________________________________________________
                     
                    FUNCTION ShowEula ALIAS "ShowEula"(BYVAL hParent AS DWORD) EXPORT AS LONG
                     
                     LoadEula BYVAL hParent
                     
                    END FUNCTION
                    '______________________________________________________________________________

                    Comment


                    • #11
                      Thank You Pierre,
                      Your code shows me that just because my code works, does not mean I was doing it right. (and key points I was missing, just because I wasn't informed)

                      Unfortunately your code does the same as mine (crashes unless I show the dialog before ending the program), but does give me avenues to investigate and see if its some memory location or something that is not freed when the program ends and causing a crash?

                      One thought I had:
                      Remarks

                      Both Windows 95 and Windows NT automatically free resources. You do not need to call the FreeResource function to free a resource loaded by using the LoadResource function.
                      ??? Just when does Windows decide the resource is not needed anymore ???
                      Engineer's Motto: If it aint broke take it apart and fix it

                      "If at 1st you don't succeed... call it version 1.0"

                      "Half of Programming is coding"....."The other 90% is DEBUGGING"

                      "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                      Comment


                      • #12
                        ... the LoadResource() api does not return a pointer, it returns a resource handle
                        Give that gentleman one of the big stuffed teddy bears for his little lady friend!

                        >(VB and .Net in particular) that there are only 2 ways to keep the development IDE >from crashing when the program ends.

                        Just for the record here, if the actual real problem is your third-party development IDE is crashing (whatever 'crash' means), you might get better help in a peer support venue for that product.

                        Getting rid of your own error first, however, would be a requirement anyway: third-party products should be not expected to handle the data/stack corruption caused by your use of invalid pointers.

                        FWIW specifically for Microsoft Visual Basic... unless I'm mistaken, VB does not execute programs the same from its IDE as they would execute from a compiled EXE (specifically with regard to the handling of externals - functions in DLLs). Maybe this 'mixed development product' application is better tested by always compiling to EXEs and executing OUTSIDE any IDE in use.



                        MCM
                        Last edited by Michael Mattias; 11 Oct 2007, 09:54 AM.
                        Michael Mattias
                        Tal Systems Inc. (retired)
                        Racine WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          Cliff,
                          I have no crash using PpWin8.04 on XPsp2 with following code calling the DLL.
                          May I ask how your VB and .Net "function declaration" are written...

                          Code:
                          #COMPILE EXE '#Win 8.04#
                          #REGISTER NONE
                          #DIM ALL
                          #INCLUDE "Win32Api.inc" '#2005-01-27#
                           
                          GLOBAL hDlg AS DWORD
                           
                          %Button1  = 101
                           
                          DECLARE FUNCTION ShowEula LIB "TestResourceDll.dll" ALIAS "ShowEula"(BYVAL hParent AS DWORD) AS LONG
                           
                          '______________________________________________________________________________
                           
                          CALLBACK FUNCTION DlgProc
                           
                           SELECT CASE CBMSG
                           
                             CASE %WM_COMMAND
                               SELECT CASE LOWRD(CBWPARAM)
                                 CASE %Button1
                                   IF CBCTLMSG = %BN_CLICKED OR CBCTLMSG = 1 THEN
                                     ShowEula(CBHNDL)
                                   END IF
                               END SELECT
                           
                            END SELECT
                           
                          END FUNCTION
                          '______________________________________________________________________________
                           
                          FUNCTION PBMAIN()
                           
                           DIALOG NEW %HWND_DESKTOP ,"PB ver. " & Hex$(%PB_REVISION), , , 200, 100, %WS_CAPTION OR %WS_MINIMIZEBOX OR %WS_SYSMENU, 0 TO hDlg
                           
                           SetClassLong hDlg, %GCL_HICON, LoadIcon(BYVAL %NULL, BYVAL %IDI_INFORMATION)
                           
                           CONTROL ADD BUTTON, hDlg, %Button1, "Call DLL", 75, 42, 50, 15
                           
                           DIALOG SHOW MODAL hDlg CALL DlgProc
                           
                          END FUNCTION
                          '______________________________________________________________________________

                          Comment


                          • #14
                            William, thanks for the lead on "LockResource"

                            Pierre, my sincere apologize. Your code is fine, it does what it was meant to do. (Run in an Executable).

                            When MCM mentioned:
                            VB does not execute programs the same from its IDE as they would execute from a compiled EXE (specifically with regard to the handling of externals - functions in DLLs).
                            It hit me, that I brain-cramped and forgot about that, and obviously the code would work perfect tested under PB because PB is compiled, not interpreted.

                            When MCM mentioned:
                            application is better tested by always compiling to EXEs and executing OUTSIDE any IDE in use
                            I FULLY agree, however in this case the dll will be for use for others to develop their code around the dll. So I HAVE to make it work under an IDE environment. In VB (and some others) I can get around this by insisting that you compile then test with the exe, however the one I can not get around is what I call "My own personal Anti-Christ" (otherwise known as Labview) which unless you are developing actual applications, most people buy the normal version which is ALLLLLL IDE and no building an Exe.

                            So I am stuck....Right?......Wrong!!!!
                            I started thinking about it, and realized from the snippet code that the one thing I did not do is a "Dialog End", so I added it, and the problems went away in the IDE running programs. So best guess is that IDE I have to be extra careful of if I created it, I destroy it, and not rely on what a compiled Exe does for me automatically.

                            Anyways, thanks for the help. I am off to apply the same technique to the actual code and see how it goes.
                            Engineer's Motto: If it aint broke take it apart and fix it

                            "If at 1st you don't succeed... call it version 1.0"

                            "Half of Programming is coding"....."The other 90% is DEBUGGING"

                            "Document my code????" .... "WHYYY??? do you think they call it CODE? "

                            Comment


                            • #15
                              I have to be extra careful of if I created it, I destroy it, and not rely on what a compiled Exe does for me automatically.
                              That is an excellent rule for all developers to follow, regardless of what they are creating.

                              MCM
                              Michael Mattias
                              Tal Systems Inc. (retired)
                              Racine WI USA
                              [email protected]
                              http://www.talsystems.com

                              Comment


                              • #16
                                >and realized from the snippet code that the one thing I did not do is a "Dialog End"

                                Perhaps we should have guessed that from the posted code:

                                Code:
                                        CASE %WM_COMMAND
                                            SELECT CASE CBCTL
                                '*** Dialog Controls routines here
                                            END SELECT
                                Michael Mattias
                                Tal Systems Inc. (retired)
                                Racine WI USA
                                [email protected]
                                http://www.talsystems.com

                                Comment

                                Working...
                                X