Solved

How to import a DLL into my unmanaged C++ application?

Posted on 2008-10-31
15
1,630 Views
Last Modified: 2013-12-14
Hello,

I am new to C++ programming. I started to develop application using Visual Studio C++ 2008. in my application, i need to use some function in a DLL file provided by a third party software vendor.

I dont know how to import that dll into my application? can you show me how? actually i only have one file with DLL as file extension. is it enough to import and use it? how about *.lib file? can you tell me the difference between this two type of file?

i received the below error when i build my applicaiton, hope it gives you further awareness of my problem:

Error      1      error LNK2019: unresolved external symbol "public: virtual __thiscall ImqStr::~ImqStr(void)" (??1ImqStr@@UAE@XZ) referenced in function _msgTrigger      MsgExits.obj


Thanks in advance,

mrpc_cambodia
0
Comment
Question by:mrpc_cambodia
  • 8
  • 7
15 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 70 total points
Comment Utility
Assuming a shared library (dll), the dll is the runtime component and the lib file is the compile time component of the third party software.  You need to go into the project properties and add a few things:

1) Under Linker->General, add a the folder where the lib is found in "Additional Library Directories"
2) Under Linker->Input, add the lib file name (e.g. mycomponent.lib)

That will resolve your link problems.

Then copy the dll into the folder with your executable, and it should run.
0
 

Author Comment

by:mrpc_cambodia
Comment Utility
thanks for your response,

i only the dll file, not the lib file. can my program just work with the dll alone? or is it possible to generate lib file from the dll file?


Thank you,

mrpc_cambodia
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
You need the lib file or it won't work.
0
 

Author Comment

by:mrpc_cambodia
Comment Utility
thanks drichards,

now i can compile my program. but to compile i need to specify 4 lib files instead of 1. and with me i only have one dll file with the same name as one of my lib file.

so can you clarify me do i need to have 4 dll files that correspond to the 4 lib files in order for my application to execute sucessfully? because now it can compile.


Thanks so much,

mrpc_cambodia
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
What 4 lib files do you need?  If they are ones from Microsoft, then the dlls will be available in the system.  Otherwies, you need dlls to go with the lib files or you will have loader errors when you try to run the program.
0
 

Author Comment

by:mrpc_cambodia
Comment Utility
These are the libs file that i need to specify to the linker input, sorry it's not 4 files, but 5. only the first 2 files and the last one, i can find it's corresponding dll file:

imqb23vn.lib
imqs23vn.lib
libdiapi.lib
libwdisys.lib
WSock32.Lib

I have included my code file and header in the attachment as well. Actually this code is a template from an application. once i successfully compiled it, and deployed the dll to the target application, it can't be opened for execution. the original dll is 20kb, but my version is only 7kb.

In addition, when i compile dll project, it produces one dll file and one lib file. but for this project, the lib file is not produced at all.

I need your advice.


Thanks so much, you have given me alot of help.

mrpc_cambodia
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
WSock32 is a standard windows library and the Winsock dlls are on the machine (they are not named the same, and that's OK).  The first two apear to be IBM MQ Series libraries, and I don't konw what the dlls are for those.  Try runnign the code and it wil tell you if you are missing dlls.

If you have runtime issues, look in the system folders (<windows root> and <windows root>\System32) and in the folder where you program is installed (or the Visual Studio output folder).  If the dlls are not there, you need to move them to one of these locations.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:mrpc_cambodia
Comment Utility
I am thinking of one thing that could cause the problem. i compile my application with visual studio 2008. and the final dll is to be used by a third party application which was build with visual studio 6. So could there be compatibility problem?

i am going to try to recompile my application with Visual C++ 6 compiler.


Thanks so much.

mrpc_cambodia
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
There can be issues if you use different versions of compilers because they use different runtime libraries.  It is always best to use libraries compiled with the same tool chain.
0
 

Author Comment

by:mrpc_cambodia
Comment Utility
I receive error message below in Event Viewer:

----------- error ---------
Faulting application WDITrigger.exe, version 0.0.0.0, faulting module imqs23vn.dll, version 6.0.0.5138, fault address 0x0000672f.
----------- error ---------


Thanks so much,

mrpc_cambodia
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
Is this with mismatched compiler versions between your main app and the dll?  This is typical of the type of error you get when it doesn't work.  Otherwise, it may just be that you have passed bad parameters to the dll routine.  You are now into runtime debugging, which is more involved than figuring out build problems.
0
 

Author Comment

by:mrpc_cambodia
Comment Utility
with the application that i'm refering to so far. it has a sample dll and a sample C++ code which i can modify to compile into dll to work with the application.

the strange thing is: i have tried both dlls, and the same error message is produced in the event viewer.

Other than this error, the application works fine on my platform.


I do really appreciate your help,

mrpc_cambodia
0
 
LVL 19

Expert Comment

by:drichards
Comment Utility
It does sound like you are passing a bad parameter (or set of parameters) somewhere.
0
 

Author Comment

by:mrpc_cambodia
Comment Utility
I don't think it does involve any bad paramater passing. i just copy and paste the dll in a designated folder and as in the product documentation, it said so.

it leads me to think it could be a platform problem. I'll investigate more and let you know any further clue i could found.


Thank you,

mrpc_cambodia
0
 

Author Closing Comment

by:mrpc_cambodia
Comment Utility
Thanks so much for your effort.

Your contribution is really amazing. With your clear instruction, my problem could have been solved since the beginning.

Now my problem is solved. it's not an error on my side, it's the documentation from the vendor that is the source of the error.


Thank you,

Have a nice day.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now