Solved

Win32 API Noobie - Custom resource not found, error 1812

Posted on 2004-08-01
9
1,533 Views
Last Modified: 2013-12-03
I'm a beginning Win32 API programmer trying to get to grips with some of Petzold's examples.

The example here is the PoePoem program that illustrates use of Custom Resources.  The custom resource is an external text file, PoePoem.txt, in ASCII.

The .RC Script has the following entry...

    ////////////////////////
    //
    // TEXT
    //
    ANNABELLEE TEXT DISCARDABLE "PoePoem.txt"

The RESOURCE.H header file has this entry...

    #define ANNABELLEE 102

When I load the compiled exe into a hex editor I can see the text is included in the file, so I know the resource is 'on board'.

However, when I try to load the resource...

    hResource = LoadResource (hInst, FindResource (hInst, TEXT("ANNABELLEE"),TEXT ("TEXT"))) ;

...I get Error 1812 "The Specified Image File did not contain a resource section".  Having isolated the FindResource statement I am sure that it is returning a null pointer, so it either doesn't like the ANNABELLEE reference, or it doesn't like the custom TEXT reference.

If I try to get cute with it and force it to use 102...

    hResource = LoadResource (hInst, FindResource (hInst, TEXT("#102"),TEXT ("TEXT"))) ;

... I get Error 183, "Cannot create a file when that file already exists", which is odd if I'm trying to get a handle to a resource.

I'm using Visual Studio 6, on Windows 2000.

Your help would be appreciated.
0
Comment
Question by:Hiblet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11688763
I feel your hInst is not correct. Please specify how have you obtained.
0
 

Author Comment

by:Hiblet
ID: 11688899
The hInst variable is declared at Global scope, and it *seems* to come back filled from a child scroll bar creation...

         hScroll = CreateWindow (TEXT ("scrollbar"), NULL,
                                  WS_CHILD | WS_VISIBLE | SBS_VERT,
                                  0, 0, 0, 0,
                                  hwnd, (HMENU) 1, hInst, NULL) ;
 
However, when I debug this, I can see hInst has a null value, which probably means this is Win95 code???

I'm thinking that the FindResource call needs the handle to the parent window to get to the resource, and instead it's currently using a handle to the child control that returns null in Win2k.  How do I get the right handle?
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11689052
FindResource  don't need the parent to a window (HWND). It need a parent to your application (HINSTANCE).

0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Author Comment

by:Hiblet
ID: 11689161
OK, so I set up a global variable hInst, and set it to the value of hInstance in WinMain.  In this way, it should be in scope, and should hold a value for when I'm in the call back Windows procedure.

Debugging shows that the value is held, to the Callback procedure.  So far so good, I have a valid hInst value now, not null, and it's the value of hInstance from the WinMain routine.

I have also set up an HRSRC hRes variable to hold the resource handle before attempting to loadResource it.

As such I can now get the error from FindResource, even when it has (what I believe to be is a) valid handle to the current instance.  

Now I get error 1814: The specified resource name cannot be found in the image file, which at least is a bit more sensible than previous errors...
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11689236
try with

hResource = LoadResource (hInst, FindResource (hInst, MAKEINTRESOURCE(102),TEXT ("TEXT"))) ;


0
 

Author Comment

by:Hiblet
ID: 11689385
With this, I get Error 183 "Cannot create a file when that file already exists".
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 250 total points
ID: 11689429
Who is the error from? LoadResource or FindResource?
0
 

Author Comment

by:Hiblet
ID: 11689459
This is from FindResource, now that I've separated it from the composite LoadResource statement.

*Here, our Noobie programmer figures it out*

I have left the error trap in the path, so no matter what happens, I get an error.  I have just take the error trap out, and the programme now works.

I think the correction occurred when you pointed the finger at hInst, so I couldn't have got it working without this help.  Petzold's code does not set hInst to the hInstance value, so that was where it was going wrong, hInst was NULL, hence the FindResource returned NULL also.

Job done.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11689472
Ok, glad to help you. See you on the next Noobie question. ;-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question