-
February 17th, 2008, 10:26 AM
#1
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???
-
February 17th, 2008, 11:19 AM
#2
Re: LoadBitmap
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 *)
{
}
-
February 17th, 2008, 11:42 AM
#3
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???
-
February 17th, 2008, 12:08 PM
#4
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);
-
February 17th, 2008, 12:11 PM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|