Announcement

Collapse
No announcement yet.

FindResource problems

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

  • FindResource problems

    I have block of code MUCH larger that boil down to this example that I hope someone can point out what I am doing wrong??

    According to Docs, FindResource results should be as follows:
    If the function succeeds, the return value is a handle to the specified resource's info block. To obtain a handle to the resource, pass this handle to the LoadResource function.
    If the function fails, the return value is NULL. To get extended error information, call GetLastError.
    So following that note, I tried to track down info on what I am passing wrong but either completely or not informed on something.

    I think it has something to do with my resource file (which compiles fine), but I get no handle, and GetLastError all give me 0 for a handle, so I am at a loss???

    Sample Dll: "DllToTest.dll"
    Code:
    #COMPILE DLL
    #DIM ALL
    
    %USEMACROS = 1
    #INCLUDE "Win32API.inc"
    
    GLOBAL ghInstance AS DWORD
    DECLARE FUNCTION DllExampleMsg ALIAS "DllExampleMsg"(TestNumber AS LONG) AS LONG
    
    '-------------------------------------------------------------------------------
    ' 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 DllExampleMsg ALIAS "DllExampleMsg"(TestNumber AS LONG) EXPORT AS LONG
         MSGBOX "Success Calling " + FUNCNAME$ + " with passed value of " + TRIM$(STR$(TestNumber))
    END FUNCTION
    Resource after the DLL is compiled
    ResourceFiles.rc
    Code:
    #include "resource.h"         //include can NOT be UpperCase
    
    MemoryDll RCDATA DISCARDABLE "DllToTest.dll"
    Testing program:
    DemoProblem.bas
    Code:
    #COMPILE EXE
    #DIM ALL
    #INCLUDE "Win32Api.inc"
    '#Resource "ResourceFiles.pbr"                     '<--- Does NOT seem to matter if included or not??
    FUNCTION PBMAIN () AS LONG
         LOCAL hRes AS LONG
         LOCAL zDllName AS ASCIIZ * %MAX_PATH
    LOCAL lResult AS LONG
    LOCAL ErrorBuff AS ASCIIZ * %MAX_PATH
         zDllName = "DllToTest.dll"
    '     hRes = FINDRESOURCE(BYVAL 0&, zDllName, BYVAL %RT_RCDATA)
         hRes = FINDRESOURCE(BYVAL 0&, BYCOPY zDllName, BYVAL %RT_RCDATA)
         lResult = GetLastError()           'Check for the error
         FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, lResult, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL  'Format the message
    MSGBOX STR$(lResult) + $CR + ErrorBuff + $CR + STR$(hRes) + $CR + zDllName + $CR + $CR + "OK no error, but no handle to the info block?"
    
         hRes = FINDRESOURCE(BYVAL 0&, BYREF zDllName, BYVAL %RT_RCDATA)
         lResult = GetLastError()           'Check for the error
         FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, lResult, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL  'Format the message
    MSGBOX STR$(lResult) + $CR + ErrorBuff + $CR + STR$(hRes)
    
         hRes = FINDRESOURCE(BYVAL 0&, zDllName, BYVAL %RT_RCDATA)
         lResult = GetLastError()           'Check for the error
         FormatMessage %FORMAT_MESSAGE_FROM_SYSTEM, BYVAL %NULL, lResult, %NULL, ErrorBuff, SIZEOF(ErrorBuff), BYVAL %NULL  'Format the message
    MSGBOX STR$(lResult) + $CR + ErrorBuff + $CR + STR$(hRes)
    END FUNCTION
    can someone spot what I am obviously missing???
    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
    Code:
     
    hRes = FINDRESOURCE(BYVAL 0&, "MemoryDll", BYVAL %RT_RCDATA)
    ??
    Rgds, Dave

    Comment


    • #3

      I KNEWWWwwww I had to have been doing something stupid.

      Thanks Dave, it did turn out to be the name of the resource, and NOT the name of the actual resource file.

      aka
      hRes = FINDRESOURCE(BYVAL 0&, "MemoryDll", BYVAL %RT_RCDATA)

      NOT
      hRes = FINDRESOURCE(BYVAL 0&, "DllToTest.dll", BYVAL %RT_RCDATA)




      Thanks again
      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
        Also, using NULL (0&) for instance handle in those calls, you are assuming the resource is in the "EXE" module, not the DLL (even if you move these functions to the DLL)

        hModule
        [in] Handle to the module whose executable file contains the resource. A value of NULL specifies the module handle associated with the image file that the operating system used to create the current process.
        If you plan to store your resource in your DLL module (your test program code shown is a single EXE) you will have to make this change.
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X