CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: LoadBitmap

  1. #1
    Join Date
    Oct 2007
    Location
    Scotland
    Posts
    137

    LoadBitmap

    hi, I've created a function that loads a bitmap but for some reason visual c++ won't let me call it "LoadBitmap", I know there's already a function called LoadBitmap in windows.h, but I've tried using namespaces, changing the amount of parameters (even though the parameter types are completely different). here's the error message i get:

    error LNK2019: unresolved external symbol "void __cdecl LoadBitmapA(struct _iobuf *,struct BMP *,int)" (?LoadBitmapA@@YAXPAU_iobuf@@PAUBMP@@H@Z) referenced in function _WinMain@16


    the function I use looks something like:
    LoadBitmap(FILE * f, BMP * bmp);

    I declare this in "BMP.h" and then include it in "BMP.cpp". then I include "BMP.h" into another source an, if I include <windows.h> also it gives this error, it works find if I change the name though???

  2. #2
    Join Date
    May 2002
    Posts
    1,435

    Re: LoadBitmap

    Quote Originally Posted by staticVoid
    the function I use looks something like:
    LoadBitmap(FILE * f, BMP * bmp);
    That's not a function - it's a function prototype. The error reported indicates that you declared the prototype but did not define the function anywhere.

    Since the error message shows that the compiler was expecting to find a LoadBitmap() function that returns a void - and your prototype lacks a return type so int will be assumed - it is possible that you have confused the complier with inaccurate syntax.


    Here's a program that will compile without error to show that it can be done:
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    class BMP { };
    
    void LoadBitmap(FILE *, BMP *);
    
    int main(int argc, char* argv[])
    {
    	LoadBitmap((FILE *)0, (BMP *)0);
    	return 0;
    }
    
    void LoadBitmap(FILE *, BMP *)
    {
    }

  3. #3
    Join Date
    Oct 2007
    Location
    Scotland
    Posts
    137

    Re: LoadBitmap

    I put the function prototype in BMP.h then i implemented it in BMP.cpp which included the BMP.h file?
    Code:
    BMP.h
    #include <cstdio>
    
    typedef struct {
    .......
    } BMP;
    
    void LoadBitmap(FILE * file, BMP * bmp);
    Code:
    BMP.cpp
    
    #include "BMP.h"
    
    void LoadBitmap(FILE * file, BMP * bmp) {
    ...
    }
    and then it suddenly works if i change the name???

  4. #4
    Join Date
    May 2002
    Posts
    1,435

    Re: LoadBitmap

    OK, now I see what you are getting at. LoadBitmap is actually a preprocessor define statement that resolves to either LoadBitmapA or LoadBitmapW. The preprocessor is probably replacing your prototype with LoadBitmapA before any files are compiled. That's why the linker is looking for a LoadBitmapA with your parameter specifications.

    What I don't understand is why the actual function name in BMP.CPP isn't changed also - and why my sample code works. Maybe someone else could answer.

    A quick way of fixing the problem would be to undefine LoadBitmap in BMP.H so that your prototype does not get changed to LoadBitmapA:

    BMP.H
    #undef LoadBitmap
    void LoadBitmap(FILE * file, BMP * bmp);

  5. #5
    Join Date
    Oct 2007
    Location
    Scotland
    Posts
    137

    Re: LoadBitmap

    thanx it worked.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured