2

I am attempting to load a file from a relative file path in win32 via the LoadImage function. The URL I am using definitely exists as I am, for testing purposes, using the same URL as an added bitmap in the resource file.

Image = (HBITMAP)LoadImage(NULL, "..\\..\\Images\\Mage default.bmp",
                           IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);

However, it is returning error code 2, indicating the file can't be found. I have googled the issue at some length, and referred to MSDN, and I can't find anything stating how to use a relative file path with LoadImage.

It seems to work fine with LoadBitmap and a pre-defined bitmap, but doesn't seem to work in this case. Any help would be much appreciated

4

3 回答 3

2

First of all, check that the file exist and current directory is the one you expected.

Also, you can use function like GetFullPathName to convert relative path to absolute.

于 2013-03-30T14:27:53.460 回答
1

The relative path you have is computed based on your process/run time working directory and not on your static files location in compile time.

于 2013-03-30T14:25:07.450 回答
1

This may be an old post, but having stumbled across this problem (in my case, a header file) and found an answer, here it is:

If referencing a relative path, the first directory is not preceeded by a backslash.

In this example, the line would be:

(HBITMAP)LoadImage(NULL,"Images\\Mage default.bmp",...

于 2019-05-07T11:11:46.427 回答