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:
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"
Resource after the DLL is compiled
ResourceFiles.rc
Testing program:
DemoProblem.bas
can someone spot what I am obviously missing???
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.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

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
ResourceFiles.rc
Code:
#include "resource.h" //include can NOT be UpperCase MemoryDll RCDATA DISCARDABLE "DllToTest.dll"
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
Comment