Application Embedded Resource file [training data]

Source: Internet
Author: User

Windows exe/dll Embedded Data

?

How resources are invoked

Exe/dll have corresponding entry function Main/_tmain/winmain/_dllmain etc., through these entry functions can get the exe file path or file Handle[exe through the entry function to get the path after the call LoadLibrary Get the handle ,dll directly from the entry function to get the handle]; Static Library no entry function can not get the handle to the resource embedding;

?

Example calling code:

[Pure data file, if it is a media file {audio and video files} or a database db file, etc. need to be resolved with a special library of files, you can consider writing the contents of the read data pointer to the local temporary file and then call the relevant library to read the contents of the file]

?

Hmodule Hexe = LoadLibrary ((argv[0]));

if (Hexe = = NULL)

{

return-1;

}

?

HRSRC hrc= FindResource (Hexe,makeintresource (idr_mldata1), L "Mldata");

int x = Sizeofresource (HEXE,HRC);

printf ("%d\n", X);

?

Hglobal hresload = LoadResource (Hexe, HRC);

float* ptr = (float*) lockresource (hresload);

if (ptr = = NULL)

{

return-1;

}

?

Here is the PTR as raw data pointer and finish your work

// ...

?

if (! FreeLibrary (Hexe))

{

return-1;

}

?

Use the pointer ptr at the comment to complete the work, corresponding to code that does not use resource embedding:

char* file = "Data.bin"

float* ptr = new float[36*32768];

file* f = fopen (file, "RB");

Fread (PTR, sizeof (float), 36*32768, F);

Fclose (f);

Here is the PTR as raw data pointer and finish your work

// ...

?

When accessing data through resource embedding, the IDR_MLDATA1 in the FindResource parameter is the ID that is automatically generated when the resource is imported into Visual Studio; The third parameter, "Mldata", is the type name that is customized when the type is imported;

?

How to add resources

The first step; right-click to add a resource

?

Step Two: Import custom type resources through the right import portal

?

Step three: Select the data file to add in the browse area after selecting all files in the file type filter in the lower right corner

?

?

Fourth Step: Enter a custom data type string that is used in the FindResource interface

?

?

Embedded Resource files under Linux

?

Write a compilation file BLOB. S

?

. Global BLOB

. Global Blob_size

. section. Rodata

Blob:

. Incbin "Blob.bin"

1:

Blob_size:

. int 1b-blob

?

Declared in the called file

?

extern uint8_t blob[];

extern int blob_size;

?

Use directly by name

?

Compiled instructions:

Gcc-c blob. S-o BLOB.O

?

?

Embed resource files under Mac

?

GCC is available under Mac and works under Linux

?

?

?

Reference

[1] http://blog.csdn.net/bupt073114/article/details/26691183

[2] https://msdn.microsoft.com/en-us/library/ms648008 (v=vs.85). aspx#_win32_updating_resources

[3] Http://stackoverflow.com/questions/1997172/is-there-a-linux-equivalent-of-windows-resource-files

[4] http://stackoverflow.com/questions/5479691/ Is-there-any-standard-way-of-embedding-resources-into-linux-executable-image

[5] Http://stackoverflow.com/questions/4864866/c-c-with-gcc-statically-add-resource-files-to-executable-library

?

?

Application Embedded Resource file [training data]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.