Click here to Skip to main content
15,886,016 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more: (untagged)
Hi Gang:

This C++ newbie is getting frustrated.

I've written an instrument driver in native C++ for a client. I need to wrap it in a DLL that can be called by their existing application. One of my deliverables is a simple test application that demonstrates the DLL's functions.

I never anticipated having this much trouble! I haven't found a way to call a simple DLL. The example from a book I have doesn't work and the example in MSDN doesn't work. I'm using VS 2005.

Here's the error I get for calling a very simple DLL with a very simple console application:

Error 1 error LNK2019: unresolved external symbol "public: static double __cdecl MyFuncs::MyMathFuncs::Add(double,double)" (?Add@MyMathFuncs@MyFuncs@@SANNN@Z) referenced in function _wmain ExecDLL.obj

I've set the path to the DLL in the project properties. It seems like it is seeing the code in the header file: "__cedcl MyFuncs...etc.

But I'm stuck. If I had a simple example that worked, I can build from there.

I'll REALLY APPRECIATE any help.

Thanks,

Roger
Posted
Updated 8-Nov-11 5:44am
v2
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 15:34pm    
Please remove redundant tag "CodeProject" and add a tag for you platform and other sensible classifiers if applicable.
--SA
Sergey Alexandrovich Kryukov 7-Nov-11 15:36pm    
Write a simple source code: a declaration of function is DLL, all with its name space and all the details, and the code where you try to use it.
--SA

Google (and MSDN) to the rescue! Walkthrough: Creating and Using a Dynamic Link Library [^] It's even for VS2005!

Next time, try googling first...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 15:37pm    
Right, a 5.
--SA
[no name] 7-Nov-11 17:48pm    
Please read my message...

That's the code that I'm using. It doesn't work. The instructions they give for referencing the DLL doesn't match up to VS 2005.
This is not a DLL but a linker issue; have you added the path to the .lib file to your project?
 
Share this answer
 
Comments
[no name] 7-Nov-11 17:56pm    
Hi Richard,

I certainly agree with you. It's something to do with referencing. The instructions in the MSDN example fail at the references dialog. I can add a path but nothing shows up to select. Which brings we to your question. My guess is if there was a .lib file it would show up, but I'm trying to set a reference to a .dll file. I've looked through the project and I don't see any .lib files.

Roger
Richard MacCutchan 7-Nov-11 19:06pm    
Your DLL project should create the lib file as a normal part of the build process. This then goes forward to all projects that wish to use the DLL and is used by the linker to create the run time linkages. If you do not have a lib file that corresponds to your DLL then you need to modify its build parameters to create one.

The alternative is that you access the DLL via LoadLibrary and GetProcAddress calls.
[no name] 8-Nov-11 11:06am    
Hi Richard,

My research finds that .lib (static libraries) are an alternative to a DLL. My requirements are that the driver be in a DLL. The (good?) news is that I've found others have had the same problem with the MSDN example. They say if you create the DLL and the calling application in the same solution, it works. I'm going to look into that.

Roger
Richard MacCutchan 8-Nov-11 11:49am    
You are correct, but you still need a .lib file for the linker to satisfy all references to the routines that exist in the .DLL. If your dll project does not create one then you will still have this problem. I have not tried the MSDN sample so am not sure how they do it, but if you notice on any normal project you have to include references to the .lib files that correspond to the system DLLs.
Richard MacCutchan 8-Nov-11 12:19pm    
I have now run the MSDN sample and it does indeed create a .LIB file with the DLL which is then used by the linker to create the excutable, even though this is hidden by Visual Studio.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900