locked
Opening resource files / Object not found error RRS feed

  • Question

  • I am using C++ 2005 for an applications GUI that requires the use of multiple graphics images. Rather than place them in a separate subdirectory, I would like to place them in a resource file.  As a test case, I am attempting to retreive an image from a system compiled .resx file. The atached code compiles but I receive an exception when executing. I have opened the resource file and verified that the image is there. No matter what combination I have tried, I cannot seem to get the GetObject to point to the correct image.

     

    System::Resources::ResourceManager^ resource1;

    resource1 = System::Resources::ResourceManager::CreateFileBasedResourceManager("MyResources","",nullptr);

    Knob1->Image = (System:Big Smilerawing::Image^) resource1->GetObject(L"Knob1.Image");

    Sunday, June 3, 2007 3:12 PM

Answers

All replies

  • Hi DB-9_Connector,

      What kind of exception you received?

      Please post your exception in detail, include the exception message, stack trace.

    Thanks!

    Thursday, June 7, 2007 5:36 AM
  • What tool did you use to compile the .resx to a .resources file?  Is the .resources file present in the same folder as the .exe?  Did you rename it to the current culture (e.g: MyResources.en-US.resources)?
    Thursday, June 7, 2007 11:07 AM
  • Thanks for the reply. Attached is the text from the exception box.  

     

     

     

    ************** Exception Text **************
    System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture (or the neutral culture) on disk.
    baseName: MyResource  locationInfo: <null>  fileName: MyResource.resources
       at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
       at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
       at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
       at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
       at System.Resources.ResourceManager.GetObject(String name)
       at Panels101.InputMix.button1_Click(Object sender, EventArgs e) in c:\1dbprocessor\software\panels101\panels101\inputmix.h:line 2294
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)


    ************** Loaded Assemblies **************
    mscorlib
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.42 (RTM.050727-4200)
        CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
    ----------------------------------------
    Panels101
        Assembly Version: 1.0.2714.13371
        Win32 Version:
        CodeBase: file:///c:/1DbProcessor/Software/Panels101/release/Panels101.exe
    ----------------------------------------
    msvcm80
        Assembly Version: 8.0.50727.762
        Win32 Version: 8.00.50727.762
        CodeBase: file:///C:/WINDOWS/WinSxS/x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700/msvcm80.dll
    ----------------------------------------
    System.Windows.Forms
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.42 (RTM.050727-4200)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
    ----------------------------------------
    System
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.42 (RTM.050727-4200)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
    ----------------------------------------
    System.Drawing
        Assembly Version: 2.0.0.0
        Win32 Version: 2.0.50727.42 (RTM.050727-4200)
        CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
    ----------------------------------------
    Panels101.resources
        Assembly Version: 1.0.2714.13371
        Win32 Version: 1.0.2714.13371
        CodeBase: file:///c:/1DbProcessor/Software/Panels101/release/en-US/Panels101.resources.DLL
    ----------------------------------------

    ************** JIT Debugging **************
    To enable just-in-time (JIT) debugging, the .config file for this
    application or computer (machine.config) must have the
    jitDebugging value set in the system.windows.forms section.
    The application must also be compiled with debugging
    enabled.

    For example:

    <configuration>
        <system.windows.forms jitDebugging="true" />
    </configuration>

    When JIT debugging is enabled, any unhandled exception
    will be sent to the JIT debugger registered on the computer
    rather than be handled by this dialog box.


     

    Thursday, June 7, 2007 1:51 PM
  •  

    Thanks for the reply. I have learned a bit more about "cultures" since this post, but have not resolved the original problem.

     

    In answer to your query:

     

    The proceedure I used to creat the resource file   Using Studio         Project-> Add New Item  -> Resource->Assembly Resource File.(resx)  I entered  "MyResource" as the file name.

     

    To add content to "MyResource"     From the Solutions Explorer  I opened MyResource.resx   From the Add Resource Tab   -> Add Existing File    and opened a directory with my .jpg files. I selected the 60 or so .jpg files.

     

     

     

    I have tried renaming my MyResource.resx to MyResource.en-US.resx  after reading more on "culture"  but have met with no success. I will have to face the "culture" issue next as this project requires multinational language support.

     

    Thanks

     

     

    Thursday, June 7, 2007 2:11 PM
  • Okay, it is still murky to me what you're doing.  If you compile your project with the added .resx file, it will create a projectname.MyResources.resources file in the projectname\Debug folder.  Do you then rename the file by hand and copy it into the solution's Debug folder?
    Thursday, June 7, 2007 2:31 PM
  • I had a similar situation... the error message maybe be misleading because it may not have anything to do with cultures. Basically it just states that the resource by that name cannot be found. I've never used the CreateFileBasedResourceManager method, but here's a C# sample of how I do it.

     

    Code Snippet
    pictureBox.Image = (
    Image)(new System.Resources.ResourceManager(this.GetType())).GetObject("ImageName");

     

    I created a ResourceManager by passing in a class type to the constructor. For example if I have a class called MainForm.cs and place the code above in the initialize() method, it will then create a ResourceManager that searches through MainForm.resx. ResourceManagers normally will look for a .resources "file" named Namespace.Type.[culture].resources in the assembly (exe/dll file).

     

    Sometimes when I change the Namespace of certain classes their corresponding .resx files will not be found and I get the same runtime error as you.

     

    Thursday, June 7, 2007 4:36 PM
  • There's an article on the CodeProject dealing with using resource files that are not embedded in the assembly manifest. See part B

    http://www.codeproject.com/dotnet/Localization.asp

    Thursday, June 7, 2007 4:55 PM
  • Thanks to the group for the assistance on this issue.

     

    I had missed the requirement for running Resgen from the command prompt.   I followed the section B in the

    http://www.codeproject.com/dotnet/Localization.asp link. I have resolved both the primary problem of finding the artwork images and the multiple resource files for my multi-langugae requirements.

     

    The process that works is as  follows:

     

    Create the .resx file using the Project->Add New Item->Resource  Click on Assembly Resource File. Enter the file name( My Resource)  and click Add.

     

    Click on the New resource file.resx from the Solution Explorer .  Click on the drop down on the Add Resource. Select Add Existing File. I then open the directory with my .jpg files and select the desired files.

     

    From the windows start button -> All Programs-> Microsoft .NET Framework SDK v2.0 -> SDK Command Prompt

     

    At the command prompt I did a CD C:\PathToProjectDirectory

     

    At the command prompt       Resgen MyResource.resx

     

    I repeated the last steps for the other language resource files required for this project.

     

     

     

    In the C++ code I have the following to access the resource files:

     

    System::Resources::ResourceManager^ Resource1;

    Resource1 = System::Resources::ResourceManager::CreateFileBasedResourceManager( "MyResource","",nullptr);

     

    // This is where I assign a new image "red.jpg" to a button.    "red.jpg" was one of the files stored in the .resx file

     

    Button1->Image = (System:Big Smilerawing::Bitmap^)  Resource1->("red");

     

     

     

    Thanks to the group for your assistance. This resolves many many frustrating hours.

     

     

     

     

     

    Friday, June 8, 2007 4:43 AM
  • Thank you Darwyn and DB-9_Connector for active participation and sharing your valuable experience with us here!

    I do appreciate your time and effort!Smile

    Friday, June 8, 2007 6:00 AM