Error loading type library/DLL - c++

When I use the following code I get an compilation error
#import <dwmapi.lib>
#include <dwmapi.h>
I get the following error:
fatal error C1083: Cannot open type
library file: 'c:\program
files\microsoft
sdks\windows\v7.0a\lib\dwmapi.lib':
Error loading type library/DLL.
Intellisense says:
2 IntelliSense: cannot open source
file "c:/users/####/documents/visual
studio
2010/Projects/modlauch/modlauch/Debug/dwmapi.tlh":
Bad file
descriptor c:\users\####\documents\visual
studio
2010\projects\modlauch\modlauch\modlauchdlg.cpp 7 1 modlauch
Does anyone know how to solve it? I'm sure that my 'dwmapi' library is fine and there is nothing wrong with it. I'm using MFC with VS2010 , but I don't think that is related to the problem. (Platform - Win32)
If I get rid of "#import" then I get "unresolved external symbol __imp__DwmExtendFrameIntoClientArea#8" error.

This isn't the answer to your problem, but for others who arrive here with that error message - if you accidentally type #import "Header.h" rather than #include "Header.h" when including from a .lib then you will get that error.

dwmapi .lib is a type library? YOu sure its not just a plain old dll. A com lib is either .DLL or .tlb.
I think its a plain old dll. So you dont #import it you need instead
#pragma comment(lib,"dwmapi.lib")

A type library is not a normal object library.
Type libraries are typically found in DLL's, OCX files and TLB files.
The few times I #import'ed a type library it always one of those, never a .LIB file.
Use the REGTLB or REGTLIB command (you may have to look this up in Google) to register a type library in your system. It's similar to REGSVR32, but registers a type library rather than a COM component.
You can also use OLEVIEW to view the contents of a type library.

Related

linking error: ambiguous libboost*.lib vs boost*.lib

I'm using boost in my project. I've downloaded pre-compiled binaries from here http://boost.teeks99.com/
When linking I receive such error:
Error 18 error LNK2005: "public: void __cdecl boost::thread::join(void)" (?join#thread#boost##QEAAXXZ) already defined in boost_thread-vc110-mt-1_52.lib(boost_thread-vc110-mt-1_52.dll) C:\Oleg\projects\MBClient\FastNativeAdapter\libboost_thread-vc110-mt-1_52.lib(thread.obj) FastNativeAdapter
Why boost contains two lib with so similar name, what is the difference between them?
libboost_thread-vc110-mt-1_52.lib
boost_thread-vc110-mt-1_52.lib
How to fix linking error?
upd I've compiled boost myself. I've added boost_1_53_0\stage\lib directory to linker. This directory actually contains 3 "copies" of "each" file, for example:
boost_atomic-vc110-mt-1_53.dll
boost_atomic-vc110-mt-1_53.lib
libboost_atomic-vc110-mt-1_53.lib
So It's clear what compiler claims about. Somehow it can't understand which version of lib file to use. It's likely connected with static/dinamic linking, but I still can not find the solution. I'm sure my problems is pretty common so I hope someone can suggest me what to do.
I've tried to delete all "libboost*" files from folder but then I receive such error:
Error 15 error LNK1104: cannot open file 'libboost_date_time-vc110-mt-1_53.lib'
I've tried to delete all "boost*lib" files from folder but then I receive such error:
Error 15 error LNK1104: cannot open file 'boost_thread-vc110-mt-1_53.lib'
Then I copied boost_thread-vc110-mt-1_53.lib back and I receive a lot of errors like that:
Error 16 error LNK2005: "public: virtual __cdecl boost::detail::thread_data_base::~thread_data_base(void)" (??1thread_data_base#detail#boost##UEAA#XZ) already defined in boost_thread-vc110-mt-1_53.lib(boost_thread-vc110-mt-1_53.dll)
So when there are no boost_thread-vc110-mt-1_53.lib compiler claims that it's missing, when there is boost_thread-vc110-mt-1_53.lib compiler claims that "function is already defined". Probaly somehow I do use dinamic and static linking at the same time or something like that?
upd2 i've uncommented #define BOOST_ALL_DYN_LINK as suggested here and now code compiles! i'm investigating if everything else is fine. however i didn't understand why I should uncomment #define BOOST_ALL_DYN_LINK so comments are welcome.
Edit: Initial statement removed since an edit to the post changed the situation.
Based on http://www.boost.org/doc/libs/1_53_0/more/getting_started/unix-variants.html#library-naming (as provided by Igor R.):
libboost_thread-vc110-mt-1_52.lib is a static lib (no need for the DLL)
boost_thread-vc110-mt-1_52.lib is the import lib for the DLL
You only need to use one of these.
Another idea/solution to try if you hit the error LNK1104: cannot open file 'libboost_date_time-*.lib' error:
In our project, we include the boost/date_time.hpp file. We define the constant BOOST_ALL_NO_LIB instead of BOOST_ALL_DYN_LINK in our project settings to tell boost not to automatically select which libraries to link against.
See the Boost documentation for more information about this option.
So you could add BOOST_ALL_NO_LIB in Project Properties -> C/C++ -> Preprocessor -> Preprocessor Definitions and check whether this linker error goes away.
I think first of all you need to correct your question. Do you mean (I guess you already know the difference between DLL and LIB )
libboost_thread-vc110-mt-1_52.lib
boost_thread-vc110-mt-1_52.dll
or
libboost_thread-vc110-mt-1_52.lib
boost_thread-vc110-mt-1_52.lib
Anyway, it seems the issue is you're mixing static(libboost_thread-vc110-mt-1_52.lib) and shared (boost_thread-vc110-mt-1_52.lib) boost libraries. But without the working environment and platform details I cannot purpose an exact solution. If you work in Visual Studio ,then you can go to right click on project file > properties > linker > input > ignore specific library and add libboost_thread-vc110-mt-1_52.lib there and try.
asking myquestion myself.
need to uncomment #define BOOST_ALL_DYN_LINK (refer to description)

Link mysql_library_end()

I've been trying to resolve a serious memory leak in my C++ application. I've narrowed it down to the creation of MySQL connections and the mysqlpp doc (plus lots of googling) indicates that I need to call mysql_library_end() to tell the C API to clean up after itself.
When I try to use this function, Visual Studio throws a Link error for "mysql_library_end()". Fair enough, I didn't tell it where to look.
When I include the header file mysql.h and rebuild, Visual Studio then throws a Link error for "mysql_server_end()" instead. I checked mysql.h (in my build environment) and the only reference to the function I want to use ( mysql_library_end() ) is:
#define mysql_library_end mysql_server_end
There is a function declaration for mysql_server_end() in the file but Visual Studio can't seem to see it. I'm just stuck with this Linker error and I have no idea why it is happening.
Can anyone help?
Cheers,
Adam.
EDIT
I'm using Visual Studio 2005.Error message from the IDE is:
Error 6 error LNK2019: unresolved external symbol _mysql_server_end#0 referenced in function "public: __thiscall CConnectionParams::~CConnectionParams(void)" (??1CConnectionParams##QAE#XZ) CConnectionParams.obj
Where CConnectionParams is the .cpp file of the call to mysql_library_end().
Found the solution. The header file on it's own isn't enough, the whole library needs to be linked in. There are two libraries that can be used to interface the MySQL C API: libmysql.lib and mysqlclient.lib. One is static, one is dynamic. The one that worked for me was libmysql.lib. Note that I therefore didn't need to #include mysql.h as a result.
To link this library in Visual studio you just need to include it as part of your project dependencies. I dragged it into the solution tree from it's directory, the mysql install, but this is not a very elegant method because it only works for VS and not other build environments.

Cant import dll in C++ application

I have a dll called hecom32.dll. I want to use this in my application. I acll the following:
#import "hecom32.dll"
And I get the following error:
enter Error 1 error C1083: Cannot open type library file: 'c:\users\dvargo\documents\visual studio 2010\projects\johnny\johnny\hecom32.dll': Error loading type library/DLL. c:\users\dvargo\documents\visual studio 2010\projects\johnny\johnny\johnny.cpp 6 1 Johnny
Obviously it cant add it. I am not sure however to determine what is wrong with it. Is there some way that I can analyze the file to see why it cant be imported. Is there a different way to use the functions in the dll?
I am using Visual Studio 2010
This will only work properly if hecom32.dll implements a COM server and has the type library embedded as a resource. You can check that with File + Open + File, select the dll. You'll see the resources listed, there should be one labeled "TYPELIB" with a resource ID of 1 if you open the node.
Surely that's missing, the error message says as much. Embedding a type library is a convention, it isn't required. Just keeping it separate as a .tlb file is possible as well. And of course, it might not be a COM server at all. You can see that by running Dumpbin.exe /exports on the dll. A COM server has at least an export named "DllGetClassObject".
If none of this pans out then you'd better contact the owner of the DLL and ask for help on how to use it properly. Which typically requires having a .h file with the declarations of the exported functions and a .lib file so you can link it.

Can't get by "DllMain already defined" error

I'm trying to write a .dll library for .dll injection purposes. And because of this fact, it must have a routine called DllMain, since this is what will be used as the entry point. I think my problem may be stemming from the fact that I'm linking in a static library that I've wrote which utilizes a threads and mutexes from afxmt.h. Because somewhere down the line, the inclusion of this is causing the linker to link from mfcs100ud.lib which apparently contains its own version of DllMain.
Here is the file that is giving me trouble:
dllmain.cpp
#include "stdafx.h"
#include <stdio.h>
#include "NamedPipeLogger.h"
static CNamedPipeLogger m_PipeLogger("Log.txt");
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved)
{
}
Here is the stdafx.h file that dllmain.cpp is including.
stdafx.h
#pragma once
#define _AFXDLL
#include <Afx.h>
#include "targetver.h"
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
Here is my Error message:
Error 32 error LNK2005: _DllMain#12 already defined in
dllmain.obj D:\xxxxx\xxxxx\xxxxxx\mfcs100ud.lib(dllmodul.obj)
Am I just screwed here because I cannot change the name of my Dll entry point to something other than DllMain?
In many cases this is caused by having _USRDLL in the preprocessor settings, where it should be _LIB. This has to do with 'MFC extension dlls' which I don't think anyone still makes today, yet the VS wizard seems to assume you do want to use this when you check 'Use MFC' in the wizard.
Recently, I experienced the same or a similar issue, and found a solution.
Background
I have an MFC project in Visual Studio 2013 Pro, which generates a DLL. I have several .c modules in the project, which I'm able to do by conditionally specifying the 'extern "C"' construct, disabling precompiled headers for those C files, and - in my case - disabling inherited forced includes, which was pulling-in stdafx.h from the project defaults.
Problem
One day, after having used this method successfully on several C files, when I'd try to add just one more, I'd get the following error.
1>Link:
1> All outputs are up-to-date.
1>mfcs120d.lib(dllmodul.obj) : error LNK2005: _DllMain#12 already defined in MSVCRTD.lib(dllmain.obj)
1> Creating library C:\path\to\project\build_dir\myproj.lib and object C:\path\to\project\build_dir\myproj.exp
1>C:\path\to\project\build_dir\myproj.dll : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
Solution
I resolved this by implementing "Solution One" from Microsoft Knowledge Base article Q148652, "A LNK2005 error occurs when the CRT library and MFC libraries are linked in the wrong order in Visual C++". This forces the linker to link the libraries in the correct order.
Steps:
Right-click the project, choose Properties.
Ensure you're making changes for All Configurations, and All Platforms.
In the left pane, browse to Linker → Input.
In the right pane, pull down Additional Dependencies, choose <Edit...>.
Add mfcs120d.lib.
Based on the Code Project article Solve error LNK2005: _DllMain#12 already defined in msvcrtd.lib(dllmain.obj) in MFC Projects", I figure I might have to add another library to that list someday, but this much works for me for now.
Well, I guess I threw in the towel on this one (sort of). I was able to at least get by all my problems. I just had to stop using some of the Microsoft classes.
I touched on this in the problem description, but I recall starting to have difficulty with compiling as soon as I started including:
#include <afxmt.h>
#include <afxwin.h>
So I went through and figured out what exactly I was using that required these includes. I was using the AfxBeginThread() method, and the classes CMutex and CCriticalSection. So I figured maybe if I could just get away from any of the proprietary windows stuff that maybe my problems would go away. That means removing all includes of , , and and then address the compilation errors with more standard c++ code. Here is what I did:
Instead of using AfxBeginThread() I used CreateThread().
Instead of using CMutex and CCriticalSection I used the CRITICAL_SECTION structure with its accompanying routines.
After this I was able to compile the .dll and it worked fine.
I got the error when I have moved #include afxdllx.h from dllmain.cpp to StdAfx.h. My project works without this include also

visual studio building error: unresolved external symbol _IID_IWICImagingFactory (MFC static lib)

I wrote a porgram with a few standard dialogs in an SDI (Doc/View enabled) project.
Now that I want to send it to some friends i did set the Use of MFC Use MFC in a static library.
But when i try to build the solution i get the following error:
error LNK2001: unresolved external symbol _IID_IWICImagingFactory
My problem is, that i don´t know what exactly this interface id is, because i did not write any code for COM manually or using any image factory things or equal...
Im a bit lost atm...
May anyone tell me how to solve this and make it work with the static MFC usage?
Thanks in advance!
There is also a .lib file:
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib\ windowscodecs.lib
IWICImagingFactory is defined in wincodec.idl
Locate and add wincodec.idl to your MFC project
Rebuild and MIDL compiler will generate wincodec_i.c and wincodec_i.h
wincodec_i.* files contain the declaration and definition of _IID_IWICImagingFactory
This wasn't my exact problem (different .idl), but same linker error. Google found your question anyway. I copied the .idl file out to a new directory, launched a VS command line, and ran this:
midl thefile.idl
After it made my .c file, I just copied the const for the IID that I needed, and threw away the rest.