Bundling files with my exe

45 views
Skip to first unread message

Outnull

unread,
May 6, 2022, 9:39:16 AM5/6/22
to The Ring Programming Language
Hello, 

Is there any method available to include external files with my Ring application when I compile it to exe? For example, if I wanted to include an application installer (.MSI file) that my program could run? Rather than distribute this file separate from my application, is there any way to package it in?

Thank you.

Mounir IDRASSI

unread,
May 6, 2022, 1:15:34 PM5/6/22
to The Ring Programming Language
Hi,

On Windows, you can either embed resources directly into the EXE using .rc files (for example, images, icons, string tables...) or distribute your application using an installer (msi or exe) that will copy the exe alongside any needed external files.
It is not clear from your description what you are trying to achieve. In your example, you mention an msi file that you want to run from your program. It looks like you want to embed the msi into your application but in order to run the msi Windows needs it to be in a file in order to install it. So the msi must exist by itself in order to be installed.
There is a way to do what you describe:
  1. embed the msi as a binary resource in the .rc file of your exe
  2. at runtime read this binary resource
  3. create a temporary file
  4. write the binary resource into this temporary file
  5. rename the file as xyz.msi
  6. install this msi from your application by calling msiexe.
This is actually how installers work so it seems that you want to develop an installer application :-)

Outnull

unread,
May 6, 2022, 1:58:01 PM5/6/22
to The Ring Programming Language
Hey Mounir, 

That is exactly the process I was looking for, thanks. I don't have a specific use case yet, I just wanted to learn how to embed files (other EXEs, MSIs, Icons, graphics, anything really...) into my compiled executable. It sounds like using a .RC file is the way to go, so I will research the best way to do this. I noticed in the documentation that the read() function can read Binary files. Do you know if it can read the contents of a .RC file as well?

Thank you!

Mounir IDRASSI

unread,
May 6, 2022, 3:30:05 PM5/6/22
to The Ring Programming Language
Hi,

It seems that there is no function yet in the winapi extension to deal with Windows binary resources. The functions in question are:
  1. FindResourceA
  2. LoadResource
  3. LockResource
  4. SizeofResource
It should not be difficult to add them to Ring winapi extension in a way that makes it easy for developers (e.g a single function ReadBinaryResource(ID) with ID the integer used for the RCDATA binary resource in the .rc file). Thanks to the fact that ring2exe supports .rc files this should answer your need.
I will look into it tonight and let you know.

Mounir IDRASSI

unread,
May 7, 2022, 5:57:44 PM5/7/22
to The Ring Programming Language
Hi,

I have implemented a function that enables to read binary resources embedded into executable files and I developed a sample that shows how it works.
The function name is rwaReadBinaryResource and it is in winapi extension. The code was merged into Ring repository and you can find its documentation at https://github.com/ring-lang/ring/blob/master/extensions/ringwinapi/Documentation.txt#L341

This function is also part of the new MonoRing release that I have just published.

The sample that show how it works is located at https://github.com/ring-lang/ring/tree/master/samples/UsingWINAPI:
  1. testresource.rc defines the resources that will be embedded into the exe.
  2. testresource.ring is the application
  3. The application should be compiled with: ring2exe testresource.ring
Basically, getting embedded binary resource is as simple as : data = rwaReadBinaryResource(NULL, "RESOURCEID", RT_RCDATA)
with RESOURCEID being the ID of the resource in the rc file.

The sample application embeds its own source code in the resources and displays it at runtime using notepad. It also displays the embedded icon using mspaint.
As explained in the documentation, the NULL passed as first parameter to rwaReadBinaryResource indicates that we want to read the resources of the current application. We can also read the resources of external executable files by padding their path instead of NULL.

You will find in the sample usage of other news functions added that allow to deal with temporary files.

Let me know if you encounter any issue.

Mansour Ayouni

unread,
May 7, 2022, 6:44:35 PM5/7/22
to Mounir IDRASSI, The Ring Programming Language
Hello Mounir,

Thank you for this nice addition!

Best,
Mansour

--

---
You received this message because you are subscribed to the Google Groups "The Ring Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-lang+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ring-lang/7de430d9-59ef-4c2a-b6d1-db374f4cf17dn%40googlegroups.com.

Outnull

unread,
May 7, 2022, 11:26:30 PM5/7/22
to The Ring Programming Language
Wow, thanks a lot Mounir! I can't wait to test this out. I'll be brewing a cup of coffee tomorrow morning and having a play with this.

I must say, this community is immensely helpful. It's nice to be able to come here with questions and have people take the time to help out with quality answers and code contributions. Thanks again. :)

Reply all
Reply to author
Forward
0 new messages