I'm a student trying to teach myself C. I know the basics of it and now I would like to write a simple DLL using the WinAPI so I can use it in another BASIC-like language.

I'm using CodeBlocks with the compiler it comes with (since I can't afford to invest in any other compilers/IDEs at this point)

Basically, what I'm trying to do is kind of wrap the PlgBlt Function (here is what I have so far):

#include <windows.h>

BOOL WINAPI __declspec(dllexport) LibMain (HINSTANCE hInst, DWORD Reason, LPVOID Reserved)
{
  if(Reason==DLL_PROCESS_ATTACH)
	{
  	return   TRUE;
  	}

  if(Reason==DLL_PROCESS_DETACH)
  	{
  	return   TRUE;
  	}

  return   FALSE;
}

BOOL __declspec(dllexport) __stdcall Blit (HDC dest, HDC image, HBITMAP mask, int width, int height, int pointA, int pointB, int pointC)
{
    POINT points[] = {pointA, pointB, pointC};

    BOOL blitResult = PlgBlt(dest, points, image, 0, 0, width, height, mask, 0, 0);

    return blitResult;
}

But it says that I'm trying to reference an undefined reference to PlgBlt. From what I read at MSDN (here) the PlgBlt function should be available to me since I've included windows.h.

I'm still quite new to all of this, so if there are any other errors in there throwing it off, please let me know!

Any help would be much appreciated!

Did you link with Gdi32.lib, or just include windows.h? All headers do is declare names so that the code will compile. Compilation and linking are two different steps in the build process. If you declare a name and do not define it, the code will compile but fail to link because there is no actual thing attached to the name. That is what an undefined reference means. You are referencing something in your code that does not exist.

Thank you very much for responding, Tom!

That must be it. I don't know how to link a library in. Do you have any tips? I'm searching all through codeblocks, but I'm still new to compiling/debugging the C way.

I do not use Code::Blocks, so I will leave that answer to someone else. But there should be a setting somewhere where you can add .lib files for linking. Worst case you probably have a place where you can type gcc command line switches. Adding -lGdi32.lib should link with the right library.

Here is a link to the gcc manual for linking options:
http://gcc.gnu.org/onlinedocs/gcc-4.3.3/gcc/Link-Options.html#Link-Options

Well thank you very much sir! That did the trick. With a few changes, everything compiles fine!

Found the library and the settings right where they should be. :icon_mrgreen:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.