| | |
calling a function in DLL file ???
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2007
Posts: 51
Reputation:
Solved Threads: 2
I did make my dll file out off those two files
dll.h
and dllmain.cpp
now I want to call welcome() function in this DLL from my test_main.cpp
main.cpp
but I got those errors
I have project.dll in the directory
And when I made the dll file I didn't have anyfile *.lib
I only have a file libProject3.def I tried to include it but it won't work either
any advice please ?
Thanks
dll.h
C++ Syntax (Toggle Plain Text)
#ifndef _DLL_H_ #define _DLL_H_ #if BUILDING_DLL # define DLLIMPORT __declspec (dllexport) #else /* Not BUILDING_DLL */ # define DLLIMPORT __declspec (dllimport) #endif /* Not BUILDING_DLL */ DLLIMPORT void welcome(); class DLLIMPORT DllClass { public: DllClass(); virtual ~DllClass(void); private: }; #endif /* _DLL_H_ */
and dllmain.cpp
C++ Syntax (Toggle Plain Text)
/* Replace "dll.h" with the name of your header */ #include "dll.h" #include <windows.h> #include<iostream> using namespace std; DllClass::DllClass() { } DllClass::~DllClass () { } DLLIMPORT void welcome() { cout << " Welcome home " << endl; } BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ , DWORD reason /* Reason this function is being called. */ , LPVOID reserved /* Not used. */ ) { switch (reason) { case DLL_PROCESS_ATTACH: break; case DLL_PROCESS_DETACH: break; case DLL_THREAD_ATTACH: break; case DLL_THREAD_DETACH: break; } /* Returns TRUE on success, FALSE on failure */ return TRUE; }
now I want to call welcome() function in this DLL from my test_main.cpp
main.cpp
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <iostream> #include<project3.dll> // <<---------- the dll file include using namespace std; int main(int argc, char *argv[]) { welcome(); // <<------ this function in the DLL system("PAUSE"); return EXIT_SUCCESS; }
but I got those errors
C++ Syntax (Toggle Plain Text)
3 \including dll\main.cpp project3.dll: No such file or directory. 9 \including dll\main.cpp `welcome' undeclared (first use this function)
I have project.dll in the directory
And when I made the dll file I didn't have anyfile *.lib
I only have a file libProject3.def I tried to include it but it won't work either
any advice please ?
Thanks
•
•
Join Date: Nov 2007
Posts: 51
Reputation:
Solved Threads: 2
•
•
•
•
include the dll.h header, and not the project3.dll file.
Make an import library - the .lib file, should be an option in your compiler/linker
link the .lib file into your project. The program will know how to access the .dll file from the details stored in the .lib file.
Thanks again
![]() |
Similar Threads
- Calling c++ dll in vb (Visual Basic 4 / 5 / 6)
- Loading the Library with LoadLibrary and GetProcAddress() (C++)
- @@Creating DLL in @@ (C++)
- calling c#.net dll in Vb6.0 (C#)
- Export Obejct from DLL (C++)
- putting the address of a function pointer into a struct (C)
- Calling c function from python (Python)
- Linker Error>Undefined reference error to xyz (C++)
- Writing a Win32 DLL in VC++ (C++)
Other Threads in the C++ Forum
- Previous Thread: User declared object type?
- Next Thread: Code sharing ?
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets





