Jump to content
  • Advertisement
Sign in to follow this  
cambalinho

About resouce files

This topic is 854 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

see these line:

songoku images "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\SJ4.gif"

'songoku' - it's the resource name;

'images' - it's a user defined type;

on aspes it's the file name.

using the 'songoku', can i get the file name?

my objective is getting the file format(gif, in these case)

Edited by cambalinho

Share this post


Link to post
Share on other sites
Advertisement
You could start at the end of the string and iterate towards the beginning searching for the period. When the period is found the extension is represented by everything between the period and end of the string.

If your language has a string class/type you can do the same with searching and using a substring. Hope that helps :)

Share this post


Link to post
Share on other sites

maybe you don't understood what i said: that string it's the file name for resource name. the resource name recives the file data. but not that string(i think)

Share this post


Link to post
Share on other sites
I misread and didn't see the line above getting the file format. Sorry! Just woke up :|

If you store the path defined in images along with the resource (you have a resource class, the image name is just a string member variable) then resources contain the file path and their own name. From there you can always find a resources image name.

If the resource only receives file data you could also find the extension (since you need the string to open the file) then pass the extension along with the file data.

Share this post


Link to post
Share on other sites

if the code you're using to load a resource does not include the format or filename (from which you can figure out the format), then you'll have to store that information separately, your self, somehow.

Share this post


Link to post
Share on other sites

unless i have acess to file data. and i belive that the 1st bytes are the format, right? or not all image files follow the rule?

Share this post


Link to post
Share on other sites

heres my actual function:

void FromResource(string strResource, string strType)
    {
        //inicializate the GDIPLUS:
        if(isGDIPLUSIniciated==false)
        {
            Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
            isGDIPLUSIniciated=true;
        }

        //incializate variables:
        intSelectFrame=0;
        if(framecount>1)
            delete []framedelay;
        framecount=0;
        tmrAnimation.Stop();
        if (isimgused==true)
        {
            delete img;
        }

        strfilename=strResource;
        isimgused=false;

        HRSRC hResource = ::FindResource(GetModuleHandle(NULL), strResource.c_str(), strType.c_str());
        if(hResource==NULL)
            DebugText("resource null: " + to_string(GetLastError()));
        DWORD imageSize = ::SizeofResource(GetModuleHandle(NULL), hResource);

        const void* pResourceData = ::LockResource(::LoadResource(GetModuleHandle(NULL),
                                              hResource));
        if(pResourceData==NULL)
            DebugText("resource null: " + to_string(GetLastError()));

        HGLOBAL m_hBuffer  = ::GlobalAlloc(GMEM_MOVEABLE, imageSize);
        if (m_hBuffer)
        {
            void* pBuffer = ::GlobalLock(m_hBuffer);
            if (pBuffer)
            {
                CopyMemory(pBuffer, pResourceData, imageSize);

                IStream* pStream=NULL;
                //from msdn: the pStream can't be NULL
                if (::CreateStreamOnHGlobal(m_hBuffer, FALSE, &pStream) == S_OK)
                {
                    if(img->FromStream(pStream)==NULL);
                        DebugText("img->FromStream null: " + to_string(GetLastError()));
                    pStream->Release();

                    ::GlobalUnlock(m_hBuffer);
                }
                 
                 ::GlobalUnlock(m_hBuffer);
            }
            ::GlobalFree(m_hBuffer);
            m_hBuffer = NULL;
 //******************************************
//on resource file:
songoku GIF "C:\\Users\\Cambalinho\\Documents\\CodeBlocks\\classcontrols\\bin\\Release\\SJ4.gif"


//on test:
mnuExitSys.imgMenu.FromResource("songoku", "GIF");

i get these debug output: "img->FromStream null: 0".

ok.. these code is totally new for me. but can anyone tell me something?

using IStream isn't my strong

Share this post


Link to post
Share on other sites

Look up Image on MSDN, you'll see a list of functions that you can use from it.  In particular, you should be able to use GetRawFormat to get the GUID of the image format that was loaded.

 

GetRawFormat: https://msdn.microsoft.com/en-us/library/windows/desktop/ms535393(v=vs.85).aspx

Image formats: https://msdn.microsoft.com/en-us/library/windows/desktop/ms534410(v=vs.85).aspx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!