Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Error E2285 could not find a match for LoadResource( -- What is wrong?


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Apr 6, 2016 6:53 PM Last Post By: John Hobbie
John Hobbie

Posts: 17
Registered: 7/15/07
Error E2285 could not find a match for LoadResource( -- What is wrong?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 5, 2016 7:17 PM
I am converting a dill written in BC++ 2005 to Seattle 10. The dll consists of a number for functions for plotting data, including the ability to plot maps in different projections. The problem is in loading the binary map data to the dll.

When I compile I get: "[bcc32 Error] qltnet32.cpp(504): E2285 Could not find a match for 'LoadResource(HINSTANCE__ *,void *)' "

The full code of this section:
++++++++++++++++++++++++++++++++++++++++++++++++++++
HMODULE hmod = GetModuleHandle("Qltnet32.dll");
HGLOBAL hres = FindResource( hmod, "mapdat","BINARY");
if(!hres)
{
wchar_t error_string[254];
wcscpy(error_string,L"Error: Map file is missing.\n");
wcscat(error_string,L" I can not open:\n");
wcscat(error_string,L" hipowo.bin");
wcscat(error_string,L"\n");
Application->MessageBox(error_string,L"Missing File Error",MB_OK);
return;
}
HGLOBAL WINAPI hmem = LoadResource(hmod, hres); //This line is the one the compiler balks on.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The file map.rc contains: "mapdat BINARY hipowo.bin" (without the quotes) and the file map.res is the resource compiled version of hipowo.bin.

I have not clicked. added or altered anything to do with the resource or resource compiler in the project options window. What is it I am missing?

Any help would be appreciated. Thanks, Hobbie

Edited by: John Hobbie on Apr 5, 2016 7:17 PM
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Error E2285 could not find a match for LoadResource( -- What is wrong? [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 5, 2016 11:23 PM   in response to: John Hobbie in response to: John Hobbie
El 06/04/2016 a las 4:18, John Hobbie escribió:
I am converting a dill written in BC++ 2005 to Seattle 10. The dll consists of a number for functions for plotting data, including the ability to plot maps in different projections. The problem is in loading the binary map data to the dll.

When I compile I get: "[bcc32 Error] qltnet32.cpp(504): E2285 Could not find a match for 'LoadResource(HINSTANCE__ *,void *)' "

The full code of this section:
++++++++++++++++++++++++++++++++++++++++++++++++++++
HMODULE hmod = GetModuleHandle("Qltnet32.dll");
HGLOBAL hres = FindResource( hmod, "mapdat","BINARY");
if(!hres)
{
wchar_t error_string[254];
wcscpy(error_string,L"Error: Map file is missing.\n");
wcscat(error_string,L" I can not open:\n");
wcscat(error_string,L" hipowo.bin");
wcscat(error_string,L"\n");
Application->MessageBox(error_string,L"Missing File Error",MB_OK);
return;
}
HGLOBAL WINAPI hmem = LoadResource(hmod, hres); //This line is the one the compiler balks on.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

The file map.rc contains: "mapdat BINARY hipowo.bin" (without the quotes) and the file map.res is the resource compiled version of hipowo.bin.

I have not clicked. added or altered anything to do with the resource or resource compiler in the project options window. What is it I am missing?

Any help would be appreciated. Thanks, Hobbie

Edited by: John Hobbie on Apr 5, 2016 7:17 PM

Try this:

    HINSTANCE hmod = GetModuleHandle(L"Qltnet32.dll");
    HRSRC hres = FindResource( hmod, L"mapdat", L"BINARY");
    if(!hres)
    {
       const wchar_t *error_string = L"Error: Map file is missing.\r\n"
                                     L"       I can not open:\r\n"
                                     L"       hipowo.bin";
       Application->MessageBox(error_string,L"Missing File Error",MB_OK);
       return;
    }
    HGLOBAL hmem = LoadResource(hmod, hres);
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Error E2285 could not find a match for LoadResource( -- What is wrong?[Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 6, 2016 9:39 AM   in response to: John Hobbie in response to: John Hobbie
John wrote:

HGLOBAL hres = FindResource( hmod, "mapdat","BINARY");

FindResource() returns an HRSRC, not an HGLOBAL. LoadResource() expects
an HRSRC as input, not an HGLOBAL:

HRSRC hres = FindResource(...);
HGLOBAL hmem = LoadResource(hmod, hres);


This is an important distinction to make, because the fact that the compiler
error mentions HINSTANCE__* in the first parameter means you are compiling
with STRICT defined:

C++ Applications Use STRICT Type Checking
http://docwiki.embarcadero.com/RADStudio/Seattle/en/C%2B%2B_Applications_Use_STRICT_Type_Checking

As such, you MUST use correct data types. When STRICT is enabled, HGLOBAL
and HRSRC are separate and distinct data types (HGLOBAL is an alias for void*,
HRSRC is an alias for HRSRC__*). When STRICT is not enabled, HGLOBAL and
HRSRC are the same data type (they are aliases for void*). Mismatching data
types can cause run-time errors. It is exactly this type of coding mistake
that STRICT was designed to catch at compile-time before it can cause problems
at run-time.

HGLOBAL is always a void* regardless of STRICT, which is why you were able
to assign an HRSRC from FindResource() to an HGLOBAL variable without a compile-time
error. However, when STRICT is enabled, you cannot assign an HGLOBAL to
an HRSRC, hence the compiler error you are seeing.

The file map.rc contains: "mapdat BINARY hipowo.bin" (without the quotes)

Raw binary data should be using the predefined RCDATA resource type. Don't
create a custom resource type for it, unless you absolutely need to (which
in this case, you don't):

mapdat RCDATA hipowo.bin


HRSRC hres = FindResource( hmod, TEXT("mapdat"), RT_RCDATA);


--
Remy Lebeau (TeamB)
John Hobbie

Posts: 17
Registered: 7/15/07
Re: Error E2285 could not find a match for LoadResource( -- What is wrong?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 6, 2016 6:53 PM   in response to: John Hobbie in response to: John Hobbie
Thank you both -- Remy and Antonio. It compiled without a hitch after making the corrections you suggested. Thank you especially, Remy, on the wiki reference on STRICT and the comment to use RCDATA instead of BINARY. The STRICT reference explains a problem in an other program I was converting -- had to use a work around for that one.

Hobbie
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02