Retreive data from compiled-in recources

You can actually add text files to the ‘Libraries, Objects and Resource Files’ section in the Solution Explorer and those files are then embedded as an IMAGE resource.
That makes it easy to use Clarion to retrieve the scripts from either an EXE or a DLL using just the API calls below…

 MODULE('WINAPI')
     FindResource(UNSIGNED,LONG,LONG),UNSIGNED,PASCAL,RAW,NAME('FindResourceA')
     LoadResource(UNSIGNED,UNSIGNED),UNSIGNED,PASCAL, RAW
     SizeOfResource(UNSIGNED,UNSIGNED),LONG,PASCAL
     GetModuleHandle(*cstring lpModuleName),UNSIGNED,pascal,raw,name('GetModuleHandleA')
 END

The Variables…

RES_TYPE CSTRING(‘IMAGE’)
RES_HANDLE UNSIGNED
SCRIPT_NAME CSTRING(128)
SCRIPT_SIZE UNSIGNED
HGLOBALMEM UNSIGNED

theScript &cstring
moduleName cstring(81)
moduleHandle UNSIGNED

Retrieval of script from EXE

        !*** load script from EXE ***
        SCRIPT_NAME = 'TESTSCRIPT_TXT'
        RES_HANDLE = FindResource(system{PROP:AppInstance},address(SCRIPT_NAME),address(RES_TYPE))
        theScript &= LoadResource(system{PROP:AppInstance},RES_HANDLE)
        SCRIPT_SIZE = SizeOfResource(system{PROP:AppInstance},RES_HANDLE)
        if LEN(theScript) <> SCRIPT_SIZE
            message('Ooops something went wrong')
        else                
            !message('TheScript||' & theScript)
            ?TEXT1{PROP:Text} = theScript
        end

Retrieval of script from resource DLL

       !*** load script from DLL ***
        MainSQLResources()
        SCRIPT_NAME = 'JOBCANDIDATE_SQL'
        moduleName = 'SQLRESOURCES.DLL'
        moduleHandle = GetModuleHandle(moduleName)
        RES_HANDLE = FindResource(moduleHandle,address(SCRIPT_NAME),address(RES_TYPE))
        theScript &= LoadResource(moduleHandle,RES_HANDLE)
        SCRIPT_SIZE = SizeOfResource(moduleHandle,RES_HANDLE)
        if LEN(theScript) <> SCRIPT_SIZE
            message('Ooops something went wrong')
        else                
            !message('TheScript||' & theScript)
            ?TEXT1{PROP:Text} = theScript
        end    

NB MainSQLResources is just an empty exported procedure - necessary to ensure Clarion’s smart linker actually links in the resource DLL

Advantage of doing it this way is that the scripts will be embedded as an IMAGE resource - so anyone hacking your EXE or DLL with a resource editor won’t be able to see the scripts.

SQLResources.zip (14.1 KB)

2 Likes