c++ - FindResource() fails to find data even though data is in exe -


i have been on one, , plumb stuck. have been building project , want embed text file resource executable. understand basics of how "should" work, reason not. so, let me start have far , maybe problem can pinned down.

there 2 functions here, first, enumresnameproc attempt debug problem self, second, loadfileinresource function trying working. little messy because in middle of building when starting having problems.

the exact issue is, findresourceexa returning null, , lost exact reason. know error, , return code 1813, "resource not found".

i have other resources in project, have version node, mainifest node, (of which, not directly reading) have icon node (that applying window system menu icon) , bitmap (that loading texture.). these have defined types, example, type bitmap 12. now, attempting load text file, 'user defined' type of 10. know data inside executable, because if open in text editor... (yes, tried that) present, so, being included.

the first function attempt walk through file resources in attempt locate data. found types 2, 3, 14, 16 , 24., not 10. have ruled out these other types being above mentioned resources. (bitmap=2), (icon=3), (rt_icon(3)+rt_icon_group(11)=14) (version=16), (manifest=24). user defined should type 10, , didn't find it.

my resources.rc file includes following:

language lang_neutral, sublang_neutral idr_textfile1      textfile       ".\\data\\world.txt" 

this defines file loaded, (again, know works, can see text of code in executable.)

my resources.h file defines following:

#define idr_textfile1                           102 

so, being defined, included, built, , other resources work, , yet, findresourceexa returns null on this. include files lined up, (i'd warnings , errors if not.)

so, question is, calling findresourceexa correctly? defined as:

winbaseapi hrsrc winapi findresourceexa(hinstance,lpcstr,lpcstr,word); 

well, have tried hinstance, null, hinstance passed windows in winmain, getmodulehandlea's results, no dice.

for lpcstr, resource id, have tried see, makeintresource(idr_textfile1), , have tried hard coding id number well, in case, 102. no dice. type, have tired other variations, correct value according microsoft should 10. that's why crated enumresnameproc, trying see other ids exist, 0 500, , got ones listed above, on off chance defined funny. no dice.

i have tried both findresourceexa findresourcea (with , without 'ex') no dice.

i know there, have learned more care function, won't find it, , @ loss @ else try.

as development environment, using mingw+eclipse+cdt, , using winres gcc tools build resource object file. have looked bugs in winres see if doing funny on binary types. (that's undefined considered, though loading text file.) oh, tried re-saving file ansi, utf-8, , unicode in case binary format of text mattered.

i @ loss, don't know else try. know data there, don't why won't access it. windows api call can't either see data, or data encoded in screwey way , doesn't access it.

what else can try?

bool callback enumresnameproc (   hmodule hmodule,   lpctstr lpsztype,   lptstr lpszname,   long_ptr lparam) {     std::cerr << "wtf info begin here! \n";     // std::string info = lpszname;     int = lparam;     std::cerr  << "we found something: " << << std::endl;     messageboxa ( null, lpszname, (lpcstr) "found: ", mb_ok);     std::cerr << "wtf info end here! \n";     return true; }   void loadfileinresource( hinstance hinstance,                          int name,                          int type,                          dword size,                          const char* data) {     //  hmodule handle = getmodulehandlea(null);      (int = 0;a<500;a++) {     enumresourcenamesa(hinstance, makeintresource(a),                       (enumresnameproca) & enumresnameproc, (long_ptr) a);    }     hrsrc rc = findresourceexa(hinstance,                                makeintresource(idr_textfile1),                                makeintresource(10),                                makelangid(lang_neutral,                                sublang_neutral));    if (rc == null) {        dword fup = getlasterror();        messageboxa ( null, (lpcstr) "crap not loaded.", (lpcstr) "error", mb_ok);        std::cerr << "crap not loaded, err: " << fup << std::endl;    }     // messageboxa ( null, (lpcstr) " test ", (lpcstr) "found: ", mb_ok);    hglobal rcdata = loadresource(hinstance, rc);    // data = static_cast<const char*>(lockresource(rcdata));    data = (const char*) lockresource(rcdata);    size = sizeofresource(hinstance, rc);    std::cout << "res size = " << (long) size << std::endl;    std::cout << "data =" << data << :: std::endl;    //    wsprintf(szmsg,"values loaded : %d, %d, %d\nsize = %d",    //    pmem->value1,pmem->value2,pmem->value3);    //   messagebox(hwnd, szmsg,lpszappname,mb_ok); } 

idr_textfile1      textfile       ".\\data\\world.txt" 

you declared resource type "textfile". fine that's string, not number. using makeintresource() resource type isn't going find it, that's why enumresourcenames doesn't find back. fix:

idr_textfile1      rc_data       ".\\data\\world.txt" 

and

hrsrc rc = findresourceex(hinstance,                            makeintresource(rc_data),                            makeintresource(idr_textfile1),                            makelangid(lang_neutral,                            sublang_neutral)); 

or if want use original approach:

hrsrc rc = findresourceex(hinstance,                            l"textfile",                            makeintresource(idr_textfile1),                            makelangid(lang_neutral,                            sublang_neutral)); 

Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -