Linking to winmm.dll in Visual Studio 2013 Express for mciSendString - visual-studio

I am trying to use mciSendString in visual studio express 2013 (Visual C++) but I keep getting an error
Error 1 error C3861: 'mciSendStringA': identifier not found
I assume this i because I have not linked to the correct dll, but I cannot find any details online or on msdn about how to link to the dll. It seems quite strange that there wouldn't be more obvious documentation about this. Can someone tell me how to link to the dll?
EDIT:
Here is the code I am trying to run:
#include <Windows.h>
#include <iostream>
#include <mmsystem.h>
extern char command1[] = "open C:\\boing.mp3 type MPEGVideo alias 0";
extern char command2[] = "play 0 from 0";
int main()
{
mciSendStringA(command1, NULL, 0, 0);
mciSendStringA(command2, NULL, 0, 0);
}

To make mciSendString() to work, you need to link to winmm.lib.
Just adding winmm.lib to Project Properties > Linker > Input > Additional Dependencies will be fine.

Looking at mmsystem.h (admittedly from the V7.1A Windows SDK, which is the most recent I have installed), I can see that there's a #ifdef _WIN32 block in there. If _WIN32 is not defined, then mciSendStringA is not declared. Instead mciSendString is declared.
Check your project options and ensure that both WIN32 and _WIN32 are defined. I'm guessing that you started from a console project, rather than a Windows Application project, and that at least one of those isn't defined.

Related

error RC2247: Symbol name too long (winnt.h)

I'm getting an RC2247 error (Symbol name too long) when attempting to display the dialogs in a Win32 app. The error is occurring in this file:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\winnt.h
This worked fine under VS2015. The error started when I upgraded to VS2017.
I have seen the following posts, they don't appear to be relevant because they pertain to prsht.h:
RC2247 : Cannot open Rc file : Resource explorer cannot load resource ; Load failed
http://social.msdn.microsoft.com/Forums/en-US/vcprerelease/thread/4a648d6a-ea81-44d3-89c2-57fa5caa6fd6
The error disappears if I comment out the entire resource.rc file. The error occurs if the RC contains the single line:
#include <winnt.h>
When I click on "Edit code"", nothing happens.
I am grateful for any suggestions.
We must not include windows.h or winnt.h to .rc file - this headers - for are for c/c++ compilers and not designed for RC (resource compiler which process .rc file). as result if we include such files we may get errors.
We need include #include <winres.h> to .rc files. this file specially designed for the RC compiler. Internally it included:
#include <winuser.rh>
#include <commctrl.rh>
#include <dde.rh>
#include <winnt.rh>
#include <dlgs.h>
#include <winver.h>
and define some macros.
All standard windows definitions, which we need/use in rc file - exist in winres.h (and it subincludes). From another side in it no extra symbols/definitions wich exist in windows.h - it's not needed for rc and some time can cause errors.
So simply #include <winres.h> at the beginning of resource files and all will be OK.
I have run into this complaint rc2247 when trying to edit the rc file in a project compiled in vs2010. This had been upgraded from vs2050. I found that if I chose to open the .sin file via 'version selector' instead of going straight to vs2010, then it still opens in vs2010 but there is no problem in editing the rc. I don't pretend to understand !
CalendarMan

C++/CLI & Inconsistent layout information in duplicated types (std._Tree_unchecked_const_iterator)

I have got an issue after using the Platform Toolset v141 in Visual Studio 2017 for Debug 64 bit compilation.
typedef std::map<int, msclr::gcroot<cli::array<short>^>> MapIntToManaged;
int main(array<System::String ^> ^args)
{
MapIntToManaged testMap;
for (auto &it : testMap) {}
return 0;
}
This results in the linker error
error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (std._Tree_unchecked_const_iterator< ?? :: ?? >): (0x02000048).
1>LINK : fatal error LNK1255: link failed because of metadata errors
I found a couple of workarounds to get rid of this error:
changing the Platform Toolset back to v140
using this syntax instead of the auto iterator:
for (MapIntToManaged::iterator it = testMap.begin(); it != testMap.end(); ++it) {}
changing the Runtime Library from Multi-threaded Debug DLL (/MDd) to Multi-threaed DLL (/MD) and use NDEBUG instead of _DEBUG as preprocessor define
using 32 bit instead of 64 bit
I'd like to understand this issue.
And I want to use the newest toolset, the new iterator syntax and the Debug runtime DLL.

Including <Eigen/Dense> when using /openmp

I am pretty new user of Eigen and have run into a weird problem. I am adding to a C++ project that uses OpenMP (Visual Studio 2012 compiler, /openmp set). I get a compilation error:
include\eigen\src/Core/products/Parallelizer.h(34): error C3861:
'omp_get_max_threads': identifier not found
I have tried to google around for an answer, but have failed to find a solution. We have another project, not using openmp, where Eigen has been used successfully for a while. Adding /openmp to that project did not trigger the problem. I also tried to disable openmp in Eigen, using the EIGEN_DONT_PARALLELIZE preprocessor directive. The problem persists. All suggestions to solve the problem are more than welcome.
Long comment, not really an answer: Something appears to be broken in your project. I'm using Eigen 3.2.9 as a reference, as you haven't specified which version you're using. In Eigen/Core (133) we have
#if (defined _OPENMP) && (!defined EIGEN_DONT_PARALLELIZE)
#define EIGEN_HAS_OPENMP
#endif
#ifdef EIGEN_HAS_OPENMP
#include <omp.h>
#endif
So, if you properly defined EIGEN_DONT_PARALLELIZE in your project, EIGEN_HAS_OPENMP shouldn't be defined and omp.h shouldn't be included. Additionally, in Parallelizer.h(30):
#ifdef EIGEN_HAS_OPENMP
if(m_maxThreads>0)
*v = m_maxThreads;
else
*v = omp_get_max_threads();
#else
*v = 1;
#endif
So if you had properly defined EIGEN_DONT_PARALLELIZE, you would not be getting the error you are getting.
Regarding the C3861 error, it means that the compiler is not able to find a declaration for omp_get_max_threads (called in Parallelizer.h). As that code is called within a #ifdef EIGEN_HAS_OPENMP as is the line #include <omp.h> in Core, and omp_get_num_threads is only wrapped in an #if defined( __cplusplus) you could add a check in Core or omp.h to make sure that the code is active
// This is in Eigen/Core
#ifdef EIGEN_HAS_OPENMP
static_assert(0, "OMP FILE IS INCLUDED IN CORE...");
#include <omp.h>
#endif
and
// This is in omp.h
static_assert(0, "OMP FILE IS PROPERLY INCLUDED...");
_OMPIMP int _OMPAPI
omp_get_num_threads(
void
);
You should get both as errors if omp is loaded correctly.

`Ole2.h` include causing an error

I'm using Microsoft Visual C++ Express 2012. I have the following as part of my header setup:
#include <windows.h>
#include <Ole2.h>
When I include windows.h on it's own there's no build errors, but when I include Ole2.h either with windows.h or without windows.h I get the following compiler error:
Error 1 error C2628: '_RPC_ASYNC_NOTIFICATION_INFO::$UnnamedClass$0x1c06c483$29$' followed by 'int' is illegal (did you forget a ';'?) C:\Program Files (x86)\Windows Kits\8.0\Include\shared\rpcasync.h 127 1 Test`
Any ideas what might be going wrong? Ultimately I'm trying to write some simple code to interface with Kinect, but even without any Kinect includes present the above error is still generated.
When I double click the error I am taken to rpcasync.h and the following code:
#if !defined(RPC_NO_WINDOWS_H)
//
// Notification by window message
//
struct {
HWND hWnd;
UINT Msg;
} HWND; //<<<-------- the error points here (HWND is underlined in red)
#endif // RPC_NO_WINDOWS_H
PS The reason I'm including Ole2.h at all is because I'm following this tutorial.

Error 3 error LNK1104: cannot open file 'gtk-3.lib'

I have been trying to get GTK 3.0 to work, and have followed all the steps here
How to configure gtk on Visual studio 2010
And changing to 3.0 where needed to get GTK to work, and it seems to have loaded everything it needs in order to compile, but it gives me the error
Error 3 error LNK1104: cannot open file 'gtk-3.lib'
Whenever I try to run the program.
I am using visual studios 2012, but this was the only place i found anything about getting GTK to run on any visual studios.
Here is the code I am using:
#include <gtk-3.0\gtk\gtk.h>
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//gtk_widget_get_preferred_size(window, 300, 200);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_title(GTK_WINDOW(window), "GTK+ with VS2010");
gtk_widget_show(window);
gtk_main();
return 0;
}
I commented out the gtk_widget_get_prefered_size call because it is irrelevant to the problem
any suggestions? I've looked in several places but none came up with clear answers.
The library gtk-3.lib does not exist. In fact, the library reference is not required to build your GTK 3 application. The pkg-config helper doesn't seem to generate the correct linker flags needed to link your application.
Just add in your Additional Options area all the existing libraries found in your GTK package (\gtk3\lib). The lib files for my bundle (gtk+-bundle_3.6.4-20130921) were as follows:
atk-1.0.lib cairo.lib fontconfig.lib gailutil.lib gdk-win32-3.0.lib gdk_pixbuf-2.0.lib gio-2.0.lib glib-2.0.lib gmodule-2.0.lib gobject-2.0.lib gthread-2.0.lib gtk-win32-3.0.lib pango-1.0.lib pangocairo-1.0.lib pangoft2-1.0.lib pangowin32-1.0.lib
(or you can go to your library path via a command prompt and enter dir *.lib /B)
Don't forget to include the /ENTRY:mainCRTStartup flag mention in the initial answer you started with.
you may have to edit your project settings or use a pragma comment to link with your gtk library:
#pragma comment(lib, "gtk-3")//if the libray is on your project's path
#define PATH "C:\\example\\"
#pragma comment(lib, PATH"gtk-3")//if the library is on PATH

Resources