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

## 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 on other sites
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 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 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 on other sites

i'm sorry. i can't follow... i'm totaly new with resources

##### 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 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 on other sites

I doubt that :)

The 'file' command knows such things, see http://linux.die.net/man/1/file

That command uses a 'magic' file, described in http://linux.die.net/man/5/magic

That file is processed with libmagic, described in http://linux.die.net/man/3/libmagic

Obviously, this file contains many more things than just image recognition.

##### 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);

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:


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 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.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 23
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631766
• Total Posts
3002226
×