I have created a DLL and I want to use it. What do I do to calla certain function in the .dll?
Printable View
I have created a DLL and I want to use it. What do I do to calla certain function in the .dll?
ok heres a quick program...
The DLL shoud look as follows:
dll.h
dll.cppCode:
#ifndef _IMPORTING_MY_DLL_
#define FUNCTION __declspec(dllexport)
#else
#define FUNCTION __declspec(dllimport)
FUNCTION void myfunc(void);
ok now make sure to link to the lib that you created with the DLL, and to move the dll.h to a place the program can find it.Code:
#include <stdio.h>
#include "dll.h"
void myfunc(void)
{
printf("Using function inside a dll.");
}
the program should do as follows
main.cpp
Code:
#define _IMPORTING_MY_DLL_
#include "dll.h"
/*edit*/
// Replace Mydire with the lib directory, and mylib with the lib name
#pragma comment(lib,"mydir\mylib.lib");
/*edit*/
int main(void)
{
myfunc();
return 0;
}
I want to get the function from the actual .dll file.
you mean call it or ?
Yes, I mean call the function. For example, the function make a message box.
well as long as you have __declspec(dllexport) before the function declaration in the dll, heres is all you have to do,
Link to the lib,
and redeclare the function with __declspec(dllimport) in the calling program before you use it and it should work perfectly,
like this
__declspec(dllimport) int myfunc(char* t,char* s);
int main(void)
{
myfunc("BOOYA!","Grandma!...BOOYA!!");
}
see the example i gave above if its not clear(its a fully functional program).
also use a define in the dll header to do the switching form import to export for ease of use..
::edit:: you can use comment(lib,"C:\libs\mylib.lib") to link to the library.
That worked!