0

I am trying to port VS2005 code to VS2017. Right now, I am getting a run-time error which says

HINSTANCE hInst = AfxFindResourceHandle(lpszResource, RT_DIALOG);
    HRSRC hResource = ::FindResource(hInst, lpszResource, RT_DIALOG);
    if (hResource == NULL)
    {
        if (DWORD_PTR(lpszResource) > 0xffff)
            TRACE(traceAppMsg, 0, _T("ERROR: Cannot find dialog template named '%Ts'.\n"),
                lpszResource);
        else
            TRACE(traceAppMsg, 0, "ERROR: Cannot find dialog template with IDD 0x%04X.\n",
                LOWORD((DWORD_PTR)lpszResource));
        return FALSE;
    }

here I am getting hResource as NULL. I cross checked which ID is it corresponding to in my resource folder. I could see the dialog with the ID is registered in the .rc file and hence the autogenerated Resource.h does have that ID.

The issue is my .exe is using a static lib which has these resources. I read that I have to link the .res files in configuartion->Resources but the issue is I don't have any .res files in that folder. I have a .rc file which includes all the resources and the rest are .bmp files.

These Resource generated headers are also from 2005 version and I suspect that I need to generate a new resource.h file for the newer version of VS.

Also, everything in the code is getting the right values at run-time. It just can't find the resources. I am not experienced with resources so I am confused where ::FindResources is trying to find the file and what type of file. If it's trying to find some .res file with the corresponding ID then the issue is just that I don't have those .res files.

tenfour
  • 36,141
  • 15
  • 83
  • 142
Skiggz
  • 49
  • 1
  • 4
  • I suspect the issue is that you don't have any res file. The resources are being looking for in your application, in the exe file itself. But because you haven't linked the exe file with the res file they are not found. I guess that VS 2005 was generating the res file for you automatically but VS 2017 does not. – john Oct 16 '20 at 07:36
  • This might be helpful, https://learn.microsoft.com/en-us/windows/win32/menurc/resource-compiler. The resource compiler is the tool that generates the .res file. – john Oct 16 '20 at 07:38
  • The tooling for resources hasn't changed literally in decades. *resource.h* (which contains merely symbolic constants by default) does not need to get updated so long as the corresponding .rc file hasn't been updated to include new symbolic resource IDs. You need to verify whether your resources were linked into the final executable. A simple way to do that is to open the executable in Visual Studio and switch to the Resources view. – IInspectable Oct 16 '20 at 08:14
  • @IInspectable thanks for your reply. I opened the exe in VS and opened the resource view tab. The tab seems to be an empty one – Skiggz Oct 16 '20 at 09:08
  • @IInspectable I can see the res folder under Resource view for the sln but not in the exe. – Skiggz Oct 16 '20 at 09:28
  • The *res* folder is just the conventional location that groups (binary) resources. Neither MSBuild nor the linker attribute any particular meaning to it. You're going to have to make sure to use the resource compiler (rc.exe) to compile your .rc file(s) and link its output into the final executable. A default wizard-generated project does this for you, but you can always manually adjust the relevant settings. – IInspectable Oct 16 '20 at 09:33
  • @IInspectable it seems like when i try to run rc.exe, it does nothing. I am sorry I am not much familiar with this but how should I compile .rc files with rc.exe. I am trying to google it too but they say the IDE takes care of it. Why isn't my VS2017 isn't handling this on its own? – Skiggz Oct 16 '20 at 09:54
  • also, sorry that's not .res folder, that is actually sequenceEditor.rc and it says opened it another editor, so it cannot open. But this is shown only when I opened the resource view tab through the solution file – Skiggz Oct 16 '20 at 09:57
  • The [resource compiler](https://learn.microsoft.com/en-us/windows/win32/menurc/resource-compiler) comes with documentation. – IInspectable Oct 16 '20 at 10:58
  • The static library has some resource that you need to include in the resources for your project. Typically, you can add it by hand editing the .rc2 file in your .vcxproj or your can navigate to the Resource tab on your Solution explorer, expand your project so that it shows the name of the .rc file, and then right click for the context menu and select "Resource Includes...". This assumes you have resources in your project. If you don't, go through the steps to create one. – Joseph Willcoxson Oct 16 '20 at 14:18
  • Please see https://stackoverflow.com/questions/531502/vc-resources-in-a-static-library, specifically: `You can ship the LIB file with a resource script (.RC file) and corresponding header file. You then #include them as relevant. You'll need to reserve a range of resource IDs for the LIB to use, so that they don't collide with those of the main EXE or DLL. This is what MFC does when used as a static library. ` – Vlad Feinstein Oct 16 '20 at 21:10
  • @JosephWillcoxson Thanks for your response. Yes, there's a .rc2 which includes some files. I think for including directories for its dependencies would be done through the project settings of the .sln. Right now I am getting error for the files that have been are used in .rc or .rc2. – Skiggz Oct 19 '20 at 06:08
  • @JosephWillcoxson I am getting CVT1100 and LNK1123 when I linked the newly compiled .res file. – Skiggz Oct 19 '20 at 12:20
  • also, how would I resolve some including error which is being thrown inside .rc2 file or rc files. I have tried to include the directories in addition include directories of the project but no help :( – Skiggz Oct 19 '20 at 12:46
  • According to this, https://stackoverflow.com/questions/21412310/how-to-resolve-cvt1100-typestring-in-visualstudio-2010 , it means you have a duplicate resource ID for some element. Find out what it is and change it. – Joseph Willcoxson Oct 19 '20 at 14:07
  • my error actually deals with ICON type and language = 0x0000, name : 1 when I looked into the .res files it shows and expanded the Icon folder, it shows the Icon ids with Neutral in []. It looks like 141[Neutral]. It seems like there are no icons added the icons with neutral were made but never used. How should I fix this? @JosephWillcoxson – Skiggz Oct 20 '20 at 06:14
  • oh Neutral would mean it can be used by any language. Uhm – Skiggz Oct 20 '20 at 06:24
  • Not enough information to help. If you think it is an icon, then remove all icons and see if it compiles and links. If it does, then add icons one by one or in groups until you find the one you add that causes the problem. – Joseph Willcoxson Oct 21 '20 at 19:56
  • @JosephWillcoxson hey, I solved the error. Thanks for your help :) – Skiggz Oct 22 '20 at 05:42

0 Answers0