October 30, 2025, 03:20:31 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Trouble with Resources

Started by myql, September 19, 2009, 10:25:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

myql

September 19, 2009, 10:25:59 PM Last Edit: September 21, 2009, 06:13:53 AM by Larry McCaughn
I'm trying to have a couple of resources that are binary files, exe and dll, so not bitmap or other of the given types. I want to LOADRESOURCE, probably into a MEMORY variable, then create a file with each resource data.

I have tried using both integer and string identifiers for the resource, using Custom as the Type, and various things for Custom Type, such as @RESDATA and CHAR. The build file always appears to be about the right length for the code + resources.

However, no matter what I do, GETRESOURCELENGTH(resourceID, whateverType)
always returns 0, and LOADRESOURCE fails.

What am I missing?

Michael

LarryMc

September 19, 2009, 10:59:35 PM #1 Last Edit: September 21, 2009, 06:14:09 AM by Larry McCaughn
Michael

This is what I use:
In a text editor set up your .rc like this:
myexe.exe DATA "myexe.exe"

In your eba file:

DECLARE IMPORT,LoadResourceA ALIAS LoadResource(hModule as UINT, hResInfo as UINT),UINT
DECLARE IMPORT,LockResource(hResData as UINT),POINTER
DECLARE IMPORT,FindResourceA(hModule as UINT,lpName as POINTER,lpType as POINTER),UINT
DECLARE IMPORT,SizeofResource(hModule as UINT,hResInfo as UINT),UINT
DECLARE IMPORT,RtlMoveMemory(dest as POINTER,src as POINTER,length as INT)

istring destpath[260]="whatever your dest is"

int size
bfile hFile
memory pFile

pFile = LRX("myexe.exe","DATA",size)
if(pFile <> NULL)
  if OpenFile(hfile,destpath+"\\" + "myexe.exe","W") = 0
     __Write(hFile,pFile,size)
     CloseFile(hFile)
  endif
endif


sub LRX(pointer id,pointer typ,int iSize byref),pointer
 pointer pReturn = NULL
 iSize = 0
 UINT hRes = FindResourceA(NULL,id,typ)
 if(hRes)
   UINT dwSize = SizeofResource(NULL,hRes)
   UINT hResource = LoadResourceA(NULL,hRes)
   if(hResource)
     pointer lpBuff = LockResource(hResource)
     pReturn = new(char,dwSize)
     RtlMoveMemory(pReturn,lpBuff,dwSize)
     iSize = dwSize
   endif
 endif
return pReturn
endsub
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

myql

September 19, 2009, 11:36:36 PM #2 Last Edit: September 21, 2009, 06:14:28 AM by Larry McCaughn
Larry

Thanks for your reply, but I'm still very confused. Where does the .rc file fit in? How do I set up the ADD Resource? How does the EBasic LOADRESOURCE relate to the LoadResource you IMPORT? Likewise the relationship of GETRESOURCESIZE and SizeofResource, and in general, why declare the imports at all--aren't the EBasic commands usable? As you can see, I'm floundering here.

Michael

LarryMc

September 20, 2009, 12:31:54 AM #3 Last Edit: September 21, 2009, 06:14:41 AM by Larry McCaughn
Where to start?

QuoteWhere does the .rc file fit in?
When you use the Add Resource option in the IDE what you enter is put into a file with the same name as your project.exe and has the extension of .rc.
When you compile your project the .rc file is compiled by the resource compiler and the result is given a .res extension.
That is linked with all the other .obj files in your project to make the .exe file.
BTW, look at your help menu in the EBasic IDE; there is an entry for Resource Compiler

QuoteHow do I set up the ADD Resource?
1. create a new text file with notepad.
2.type in the following line substituting your file name:
myexe.exe DATA getstartpath+"myexe.exe"
3.save the file as blah.rc where blah is the name of your project exe file.
4.close your project and then reopen it.
5. the rc file will automatically load when the project loads
6. you will be able to look at your entry in the IDE resource window but you won't be able to open the properties and edit it.

QuoteHow does the EBasic LOADRESOURCE relate to the LoadResource you IMPORT? Likewise the relationship of GETRESOURCELENGTH and SizeofResource,
The functions I IMPORTED are windows API functions.
The EBasic LOADRESOURCE is 117 lines of code and contains the same IMPORTs I posted.
It also includes another EBasic function.
The EBasic GETRESOURCELENGTH is 76 lines of code and contains some of the same IMPORTs I posted.

Quotewhy declare the imports at all--aren't the EBasic commands usable?
Obviously the Ebasic commands are usable.  Why, do you think there would be documented commands with examples that weren't usable?
When Paul wrote the language he didn't create code to specifically handle every possible variation.
That's why the generic SENDMESSAGE command was created.  So that the user could use a flag that Paul didn't predefine for a given control.

So here's the bottom line.
You described what you wanted to do.
6 months to a year ago I needed basically the same thing and described it to Paul.
He sent me code to accomplish the task which I use in my Button Designer and Chart Designer libraries and in my latest effort when it is released..
I have posted a slight, yet functional, variation of that code to you.

The way I see it you have two options:
1.  You can use the example I posted and get pass this obstacle in a short period of time, or
2.  Wait until Paul incorporates what I posted for you into the EBasic functions, which may or may not ever happen.

Hope that helps clear your confusion ;)

Larry





LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

myql

September 20, 2009, 04:22:27 PM #4 Last Edit: September 21, 2009, 06:14:57 AM by Larry McCaughn
Larry,

Thank you! Grazie mille. etc. I'm much less confused now.
With some minor changes to fit my code, your solution works great!

Not having a background in Windows programming, I was not aware that resources are a standard feature of .exe files, hence didn't know that there were Windows API functions to deal with them. The EBasic User's Guide does not mention .rc files, nor the Resource Compiler. Your discussion of the Imports, etc. shows that *in this usage*, the standard EBasic commands could not be used. I did not mean to say that the commands were not useful for what they do provide.

Thanks again,
Michael

LarryMc

September 20, 2009, 04:24:14 PM #5 Last Edit: September 21, 2009, 06:15:10 AM by Larry McCaughn
Just glad you got your problem solved.

Larry
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library