Solved

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

Posted on 2008-10-31
15
1,644 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
15 Comments
 
LVL 19

Accepted Solution

by:
drichards earned 70 total points
ID: 22855875
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
ID: 22855944
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
ID: 22855957
You need the lib file or it won't work.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:mrpc_cambodia
ID: 22860234
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
ID: 22860249
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
ID: 22860372
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
ID: 22862135
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
 

Author Comment

by:mrpc_cambodia
ID: 22864698
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
ID: 22864884
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
ID: 22865082
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
ID: 22868014
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
ID: 22873211
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
ID: 22873331
It does sound like you are passing a bad parameter (or set of parameters) somewhere.
0
 

Author Comment

by:mrpc_cambodia
ID: 22873533
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
ID: 31512261
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

615 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