DLL link error 2001, when accessing function from main module
Hi, ALL,
Here is my problem.
I have an application with the CMainFrame class and the function Foo() in it, that described as follows:
Code:
class CMainFrame : public CMDIFrameWnd
{
public:
.................................
void Foo();
}
I also have a DLL that have another class with the function that calls the Foo() function. During DLL linking I am receiving the LNK2001 error.
I looked at MSDN and Codeguru. Here I found the following link <a href=http://www.codeguru.com/dll/ExportingFromExe.html> Calling an exported function in an EXE from within DLL</a>. But I don't think this is my solution, since the article is talking about external exported function.
Hi, JohnCz,
Thank you for the responce.
What kind of .LIB file could be generated with .EXE file?
Once again, I am trying to call function from the main .EXE module inside .DLL.
Thank you.
P.S.: Maybe all I need to do is somehow export the CMainFrm::Foo() function from the main .EXE module, so it will be visible for DLL?
Last edited by OneEyeMan; January 23rd, 2004 at 12:25 AM.
You are calling function in a dll therefore there is nothing you have to expose from EXE module. It is rather the other way around.
I do not know what kind of DLL you are using, but compiling DLL there is import library with DLL name and .LIB extension. That is what you need to include in your project dependencies.
There are only 10 types of people in the world: Those who understand binary and those who do not.
Hi, JohnCz,
One more time: I am receiving the LNK2001 when compiling and linking the .DLL project not the main .EXE one, which means that I should put the .LIB file that will be generated from .EXE to the .DLL. But I don't know is it possible to generate the .LIB file out of main .EXE module.
Thank you.
P.S.:
I do not know what kind of DLL you are using, but compiling DLL there is import library with DLL name and .LIB extension
I couldn't compile the .DLL project. You solution is for other way around.
Last edited by OneEyeMan; January 23rd, 2004 at 04:26 PM.
Originally posted by Elron
I think you need to export the whole class (to prevent problems with the default constructor etc.)
Code:
__declspec(dllexport) class CMainFrame : public CMDIFrameWnd ...
Btw, why do you need to import functions from .exe to .dll? That sounds weird...
yea missed the class part even though it's in his intitial post that's what you get for jumping right to the bottom of the thread...anyways, if they are non-static member functions, then export the class.
Thank you, guys!
I understand that this is the safest way: just export the whole class.
Now, one last thing:
Macros AFX_EXT_CLASS design for extension DLL only, right? Which means I couldn't use it in my case.
Originally posted by OneEyeMan
Thank you, guys!
I understand that this is the safest way: just export the whole class.
Now, one last thing:
Macros AFX_EXT_CLASS design for extension DLL only, right? Which means I couldn't use it in my case.
Hi, guys,
Thank you for the fast reply, but.....
Neither class export, nor function export does not solve the problem. When I compile my .DLL with the .LIB file generated it gives me following:
LNK2001: Unresolved external symbol 'public: static struct CRuntimeClass const CMainFrame::classCMainFrame"
which actually means that I have only one option left: add the CMainFrame class in the .DLL project. I guess the 'static' stuff comes from CMDIFrame, which is parent class.
I tried both methods, which are:
Code:
class __declspec(dllexport) CMainFrame : public CMDIFrame
{
public:
void Foo();
};
class CMainFrame : public CMDIFrame
{
public:
void __declspec(dllexport) Foo();
};
I guess, because of this error, I couldn't create the external exported function, which will call CMainFrame::Foo();
You have to export and import.
See attached sample.
See ExpImp.h included in StdAxf in both projects.
In VS use menu: Project Settings. In Dialog select C++ tab.
For ExeExport project:
Check Preprocessor Definitions, it has EXP_EXE_ defined.
For Dll see that it does not contain EXP_EXE_.
Change to Link tab
See Output filename is changed to create dll in the same directory as exe module.
Select Input for category Object/Library modules contain ExeExport.lib and Additional library path contains ..\
See exported function and variable that holds pointer to a current instance of CMainFrame object.
Compile both and rum exe. Use Load menu and select dll to load dll. It will call exported function. Message box is indication that function was called.
There are only 10 types of people in the world: Those who understand binary and those who do not.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.