I have created a DLL and I want to use it. What do I do to calla certain function in the .dll?
I have created a DLL and I want to use it. What do I do to calla certain function in the .dll?
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
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; }
Last edited by no-one; 02-04-2002 at 05:36 PM.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
I want to get the function from the actual .dll file.
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
you mean call it or ?
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
Yes, I mean call the function. For example, the function make a message box.
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK
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.
Last edited by no-one; 02-04-2002 at 05:37 PM.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
That worked!
Website(s): http://www16.brinkster.com/trifaze/
E-mail: [email protected]
---------------------------------
C++ Environment: MSVC++ 6.0; Dev-C++ 4.0/4.1
DirectX Version: 9.0b
DX SDK: DirectX 8.1 SDK