Embedded resource in C++

后端 未结 2 1457
轻奢々
轻奢々 2020-12-15 12:36

How do I create an embedded resource and then access it from C++?

Any example on how to read the resource would be great.

I am using Visual Studio 2005.

相关标签:
2条回答
  • 2020-12-15 13:27

    Add a resource (.rc) file to the project, put the resource description there. When building the project the resource compiler will compile the resource file and the linker will link the compiled resource file into the resulting executable module.

    In runtime call FindResource(), then LoadResource() WinAPI functions.

    0 讨论(0)
  • 2020-12-15 13:39

    I'm doing @Sharptooth explained before and use the following code to get the resource

    HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(resourceId), type);
    HGLOBAL hRes = LoadResource(hInstance, hResInfo);
    LPVOID memRes = LockResource(hRes);
    DWORD sizeRes = SizeofResource(hInstance, hResInfo);
    

    Here you have to change resourceId and type.

    For example for a .png file I use FindResource(hInstance, MAKEINTRESOURCE(bitmapId), _T("PNG")); (the "PNG" string is the type you used when adding a custom resource).

    0 讨论(0)
提交回复
热议问题