[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1664
  • Last Modified:

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

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
mrpc_cambodia
Asked:
mrpc_cambodia
  • 8
  • 7
1 Solution
 
drichardsCommented:
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
 
mrpc_cambodiaAuthor Commented:
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
 
drichardsCommented:
You need the lib file or it won't work.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
mrpc_cambodiaAuthor Commented:
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
 
drichardsCommented:
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
 
mrpc_cambodiaAuthor Commented:
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
 
drichardsCommented:
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
 
mrpc_cambodiaAuthor Commented:
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
 
drichardsCommented:
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
 
mrpc_cambodiaAuthor Commented:
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
 
drichardsCommented:
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
 
mrpc_cambodiaAuthor Commented:
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
 
drichardsCommented:
It does sound like you are passing a bad parameter (or set of parameters) somewhere.
0
 
mrpc_cambodiaAuthor Commented:
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
 
mrpc_cambodiaAuthor Commented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now