Reputation: 1305
I have a C++ project which uses an API that comes with DLL and LIB files, as well as a header file. I want to create a win32 forms project.
My question is how do I link the project with the dll and lib files.
But the main question is, how do I subscribe to events? In the API I can call functions, which come back as on event response, which in a MFC project I would generally subscribe in the message loop. But in the Win32 there is no message loop.
Maybe I am complicating the situation myself and it is easier than I imagine. Please clarify this situation for me.
Thank you.
Upvotes: 0
Views: 610
Reputation: 738
You cannot link the project with dll files, you could link your project with lib files, you could add lib file names in your project settings dialog (linker)
Or, you add this to your code
#pragma comment(lib,"xxxx.lib")
Dll files will be loaded at run-time.
For message loop, see http://msdn.microsoft.com/en-us/library/windows/desktop/ms644928(v=vs.85).aspx
Or this: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644996(v=vs.85).aspx#modeless_box
Upvotes: 1
Reputation: 63481
It's always hard to answer when someone asks more than one question... In the case of your "main question", please show the relevant API call for subscribing to events. You are wrong about there being no message loop in Win32... It's just that there's no MFC message loop.
I'm answering the easy question for now... "how do you link the DLL". I am kinda assuming you are using Visual Studio. Is that correct? The way I do this, when I'm in a hurry is like so:
#include "mylib.h"
#pragma comment(lib, "mylib.lib")
That's all there is to it. Of course I want the header, but while I'm at it I tell the compiler to link the library too.
I seem to recall other times where I simply dragged the library file into the project's solution view, effectively adding it as a source. That also works.
The long way is to edit your project settings, go to the Linker section, and under the Input subsection, you add your library to the Additional Dependencies list. You need to do that for all configurations. There are ways to maintain this properly but I won't go into it here.
If you are not using Visual Studio, please disregard my answer.
Upvotes: 2