There are several ways to do this; the method I describe here is just one of them.
Step 1: Export the function from the DLL.
For information on how to do this, create a new Win32 Dynamic Link Library project in VC++. Pick the "DLL that exports some symbols" option.
Let's say that you call it "MyDLL". Then you can look at the "MyDLL.h" and "MyDLL.cpp" files that App Wizard will generate for you. They have some pretty helpful comments.
Step 2: Call the code from another DLL or EXE
This part is really pretty easy. Essentially you just add an include statement for "MyDLL.h" and then call the function just as you would call any function:
int nReturnValue = fnMyDLL( );
But the linker will complain unless you tell it where to find the library file. So you'll need to go to the "Link" tab under Project...Settings and add "MyDLL.lib" to the Object/Library modules list.
At that point it should build. However, note that you may have to set up your include paths (under Tools...Options...Directories) so that VC++ can find "MyDLL.h" and "MyDLL.lib". Alternatively, you can specify relative (EX: "..\MyDLL\MyDLL.h" or absolute paths to the two files.
Finally, when you run your EXE, you might want to put "MyDLL.DLL" into the same folder as the EXE so that Windows can easily find it.
Note that this is just one method, and it's really just scratching the surface. For more info, you could start by going to msdn.microsoft.com and searching on "dllexport". One useful link is given below.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.