# Retreive data from compiled-in recources

**URL:** <https://clarionhub.com/t/retreive-data-from-compiled-in-recources/3330>\
**Category:** code\
**Tags:** api\
**Created:** [May 22, 2020, 3:51pm UTC](https://clarionhub.com/t/retreive-data-from-compiled-in-recources/3330 "2020-05-22T15:51:45Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Graham\_Dawson](https://clarionhub.com/user_avatar/clarionhub.com/graham_dawson/32/1331_2.png) [@Graham\_Dawson](https://clarionhub.com/u/Graham_Dawson)\
**Post date:** [May 24, 2020, 5:16pm UTC](https://clarionhub.com/t/retreive-data-from-compiled-in-recources/3330/4 "2020-05-24T17:16:18Z")

</div>

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](https://clarionhub.com/uploads/short-url/fqSmyyprkVD5FwuIhCddkiq4sI6.zip) (14.1 KB)

---

_[View the full topic](https://clarionhub.com/t/retreive-data-from-compiled-in-recources/3330)._
