Can you help me fix error about Bluetooth Low Energy (C++)? - c++

I use VS2013 on Win 8.1.
I have a solution with some projects. One of them is a project contain code connect Bluetooth Low Energy. I build it success.
Another project what reference to above project. But when I build, show error "error C2061: syntax error: identifier 'BLUETOOTH_ADDRESS ' ".
I find out why have this error. In "BluetoothApis.h" , condition "#if (NTDDI_VERSION >= NTDDI_WINXPSP2)" don't happen. Detail :
#if (NTDDI_VERSION >= NTDDI_WINXPSP2)
typedef ULONGLONG BTH_ADDR;
typedef struct _BLUETOOTH_ADDRESS {
union {
BTH_ADDR ullLong; // easier to compare again BLUETOOTH_NULL_ADDRESS
BYTE rgBytes[ 6 ]; // easier to format when broken out
};} BLUETOOTH_ADDRESS_STRUCT;
#define BLUETOOTH_ADDRESS BLUETOOTH_ADDRESS_STRUCT
Help me!

In your Visual project(s), you have to #define (in compiler's preprocessor options) which version of the SDK you're using (or want to use). So, typically, you would add compiler's preprocessor terms like :
NTDDI_VERSION=NTDDI_WIN7
_WIN32_WINNT=WIN32_WINNT_WIN7 (if Win7 is your target)
Use appropriate constants for Win8...

Related

strncasecmp and strcasecmp has not been declared

I'm trying to compile Assimp with MinGW in Code::Blocks, but I get the following errors.
\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h||In function 'int Assimp::ASSIMP_stricmp(const char*, const char*)':|
\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h|144|error: '::strcasecmp' has not been declared|
\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h||In function 'int Assimp::ASSIMP_strincmp(const char*, const char*, unsigned int)':|
\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h|193|error: '::strncasecmp' has not been declared|
While searching I've found out that the two functions in question (strcasecmp and strncasecmp) are in fact declared in string.h which is included in the header of StringComparison.h. I've also managed to get strings.h, the file which they originally belong to, but including that didn't solved the issue either.
While searching this site I've found out that I'm not the only one struggling with this issue. Another solution I've found suggested to use define statements, because the functions might have a slightly different name, but that didn't helped either.
I just encountered this exact same problem, and this question came up during a Google search for the solution, so I'll document my dodgy solution here:
In the end I got it going just by making multiple small edits to the Assimp source code. Solving the string problem isn't enough to get it to work because it just fails later in the build. I'll list the edits I made below. I recommend making them one at a time and then rebuilding, just in case for whatever reason with your setup some of them aren't required. Note that you can't do model exporting with this solution because of the last edit (to Exporter.cpp) if you really need that you'll have to figure out another way to fix the link errors.
It's not a clean solution and it will probably be superceded by a future version of Assimp, at which point I will just delete it. This is for assimp-3.3.1, built with MinGW:
In StringComparison.h, edit the ASSIMP_stricmp function, commenting out everything except the else clause of the #ifdef:
/*#if (defined _MSC_VER)
return ::_stricmp(s1,s2);
#elif defined( __GNUC__ )
return ::strcasecmp(s1,s2);
#else*/
char c1, c2;
do {
c1 = tolower(*s1++);
c2 = tolower(*s2++);
}
while ( c1 && (c1 == c2) );
return c1 - c2;
//#endif
Do a similar thing in ASSIMP_strincmp.
Next, it throws up an error about ::_fullpath in DefaultIOSystem.cpp. My "fix" for this was just to use comment out everything other the fallback option in this function:
ai_assert(in && _out);
// char* ret;
//#if defined( _MSC_VER ) || defined( __MINGW32__ )
// ret = ::_fullpath( _out, in, PATHLIMIT );
//#else
// use realpath
// ret = realpath(in, _out);
//#endif
// if(!ret) {
// preserve the input path, maybe someone else is able to fix
// the path before it is accessed (e.g. our file system filter)
// DefaultLogger::get()->warn("Invalid path: "+std::string(in));
strcpy(_out,in);
// }
It also complains about snprintf being undefined. Edit StringUtils.h to change the following #define to add an underscore before snprintf:
# define ai_snprintf _snprintf
There's also an error about ::atof not being defined. You can fix this by adding
#include <cstdlib>
to StringUtils.h
This should get it building but there will be a link error in Exporter.cpp (this might be due to my specific CMake setttings because I disabled almost all model formats). I fixed it by commenting out the definition of gExporters and replacing it with this:
Exporter::ExportFormatEntry* gExporters = 0;
After this it built and ran fine. The library files are placed in the code folder. Place libassimp.dll.a in your lib build path and libassimp.dll in the path of your executable.
Of course, you can also get it going by using VisualStudio instead (I didn't because I couldn't be bothered installing it) or by building on Linux (I did this previously and it built fine first go, but I needed to do a Windows port).
I had some problems too but hopefully I was able to solve them. I know this is probably too late to help in particular but I hope someone on the Internet will find this useful. I compile using Code::Blocks 16.01 using gcc 5.3.0.
::strncasecmp not declared in this scope:
You have to include and remove the "::"
::_fullpath not declared in this scope:
I never had to perform the operation of finding a full path, so this one is the one I am the least sure of. But anyway, since I couldn't simply remove everything, I had to find the alternative. That is, using "GetFullPathName".
So, as suggested by MSDN, I included , , , .
I also replace the line :
ret = _fullpath( _out, in, PATHLIMIT );
by
ret = (char*)GetFullPathName(in, PATHLIMIT, _out, NULL);
Should work fine, full path is obtained and error checking is kept too.
vsnprintf not declared in this scope
Just add an underscore _ in front of the function name.
to_string is not a member of std::
I would have that this is the usual bug from using MinGW, but actually, Assimp contains a built-in alternative to std::to_string. You just have to remove the std:: part and it should roll.
Make sure to include in the files in which just removing std:: doesn't work.
test\CMakeFiles\gtest.dir\build.make|109|recipe for target 'test/gtest/src/gtest-stamp/gtest-build' failed| ?
It doesn't matter, you already have your working .dll in the "code" folder ;)
I was using Cygwin and encounter the same error, using strncmp and strcmp worked, guessing it is something to do with the libraries (ANSI C++) currently implemented for Cygwin or being used by your project. Not sure though, just wanted it to work for the moment...

Convert C++ log source snippet to Windows Phone C++/CX

I just started developing for Windows Phone and I'm stuck with one piece of exisiting code I need to maintain. It's a macro from a logging lib that is used in many places of existing code.
This is the macro:
#define LOG_FORMAT_FUNCTION(fmtarg, firstvararg) __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
And this is a method definition that fails to use the above macro with error "{ expected" (In German "Error: Es wurde ein '{' erwartet."):
void LogTrace_s(const char* category, const char* format, ...) LOG_FORMAT_FUNCTION(2, 3);
Can you help me get rid of the error? I'd also like to know what actually the macro does exactly.
Edit: After rading this here I now understand that this macro is good for error checking formatted strings. Now that I know, I need it even more. But I still have no clue how to translate this to MS C++.
Yes you CAN just omit it. Use
#if _MSVC_VER
#define LOG_FORMAT_FUNCTION(fmtarg, firstvararg)
#endif
It is annotating the function with extra information to help gcc give you better warnings. It does not change the behavior of the code in any way.

Eclipse Invalid arguments error when using gstreamer

Ok, so I want to use gstreamer library.
1. Situation
I have some code:
#include <gst/gstpipeline.h>
#include <gst/gst.h>
...
GstElement* pipe = gst_pipeline_new("PipeName");
Where gst_pipeline_new is declared in gstpipeline.h:
GstElement* gst_pipeline_new (const gchar* name) G_GNUC_MALLOC;
where non obvious "things" :) are defined somewhere in the system:
typedef struct _GstElement GstElement; // gstelement.h
typedef char gchar; // gtypes.h
#define G_GNUC_MALLOC __attribute__((__malloc__)) // gmacros.h
2. Problem
Since I use make for building I have no errors during compilation and linking. Program itself runs OK as well. However...
In Eclipse IDE I have the following error:
Description Resource Path Location Type
Invalid arguments '
Candidates are:
_GstElement * gst_pipeline_new(const ? *)
' file.cc /path/to/file line 106 Semantic Error
I added all include directories which are specified in Makefile to eclipse project configuration (Project->Properties->C/C++ General->Paths and Symbols->Includes->C++). Of course it's a C++ project.
3. Question
How to get rid of that Eclipse error? I have no clue how to do this... And it drives me mad since now I use some legacy code and I have around 100 errors like this one.
So far I've tried:
casting either by reinterpret_cast<>() or C-like casting to const gchar*
adding typedef char gchar at the beginning of the file - before any other include!
including gtypes.h (gchar is defined there) - also before any other include
redeclaring `_GstElement gst_pipeline_new(const gchar* name)'
Nither of those helped...
To me it looks like Eclipse does not see the gchar type since it says that the candidate is _GstElement * gst_pipeline_new(const ? *) Where ? substitutes the real type. But I have no idea how to make (or event force :)) Eclipse to see it...
Most probably eclipse just doesn't know about your include paths (for this specific library) and complains about the unindexed types and declarations.
You can add them under 'Project->Properties->C++ General->Paths and Symbols'
If this doesn't help, you can also switch off semantic error checking (see Code Analysis), either in whole or for particular error types.
As g-maulik suggested, It seems that it was really an indexer problem. After increasing the indexer cache limits everything works fine.
Go to Window->Preferences->C/C++->Indexer tab cache limits and increase (might be machine dependent):
Index Database cache:
Limit relative to the maximum heap size: 15%
Absolute limit: 128 MB
Header file cache:
Absolute Limit: 128 MB

Strange Error C2065: 'ERROR' : undeclared identifier

As part of a bigger project ( the ff activex plugin for Mozilla Firefox) there is this code snippet:
if (CombineRgn(hrgnClip, hrgnClip, hRGN, RGN_AND) != ERROR)
{
::InvalidateRgn(m_hWndParent, hrgnClip, fErase);
}
When I build in VS2012 I get "Error C2065: 'ERROR' : undeclared identifier"
ERROR is defined in wingdi.h like this:
...
/* Region Flags */
#define ERROR 0 // it wont build when this macro is used
#define NULLREGION 1 // it builds when this macro is used
#define SIMPLEREGION 2
#define COMPLEXREGION 3
#define RGN_ERROR ERROR
...
The strange thing is that if I replace ERROR (just to see if it builds OK) with NULLREGION or SIMPLEREGION (which are macros in the same file, just two lines below the offending one) in the if statement above, the code builds OK. When I use ERROR, the code wont build.
Is it possible that the ERROR macro defined above gets masked by some keyword or another macro or some such by Visual Studio?
The problem here is that ERROR actually appears in the compile error message. That should not happen, the preprocessor should have substituted it with 0.
So somewhere in a .h file you #included after windows.h, some programmer took the 10 second shortcut to a macro name collision problem and wrote this:
#undef ERROR
You'd need to find that line and remove it. That's likely to be difficult and liable to give you a maintenance headache since that's a file you don't own and might well be updated in the future, forcing you to make that change over and over again. The alternative is to redefine it yourself:
#define MYGDIERROR 0
...
if (CombineRgn(hrgnClip, hrgnClip, hRGN, RGN_AND) != MYGDIERROR)
//etc...
Which still gives you a maintenance problem and requires you taking a bet that the return value definition of CombineRgn() is never going to change. That's a very safe bet, GDI is cast in stone.

When does #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) in dxvahd.h Microsoft header file become true

Hi I am having 2 VC++ solutions "A" & "B" (VS2008) both are having the same codebase (with just few lines of code different). Using DXVAHD.h in both.
dxvahd.h is a standard Microsoft header file. If we open this header file, we see there is a conditional if
"#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)"
I see that in VC++ solution "A", the above conditional #if statement
is false, hence the whole dxvahd header file gets greyed out & is not
even compiled!!
Whereas in another solution "B", this conditional #if is true,hence no issues & its working fine.
Can anyone kindly let me know how do I resolve this issue in solution "A", wherein the above #if is getting greyed out / not compiling. PLz help me.
Thanks in advance.
Looking at winapifamily.h, you can see that these macros are used to determine what platform you have and what API's are suitable for your platform.
/*
* Windows APIs can be placed in a partition represented by one of the below bits. The
* WINAPI_FAMILY value determines which partitions are available to the client code.
*/
#define WINAPI_PARTITION_DESKTOP 0x00000001
#define WINAPI_PARTITION_APP 0x00000002
/*
* A family may be defined as the union of multiple families. WINAPI_FAMILY should be set
* to one of these values.
*/
#define WINAPI_FAMILY_APP WINAPI_PARTITION_APP
#define WINAPI_FAMILY_DESKTOP_APP (WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_APP)
/*
* A constant that specifies which code is available to the program's target runtime platform.
* By default we use the 'desktop app' family which places no restrictions on the API surface.
* To restrict the API surface to just the App API surface, define WINAPI_FAMILY to WINAPI_FAMILY_APP.
*/
#ifndef WINAPI_FAMILY
#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
#endif
/* Macro to determine if a partition is enabled */
#define WINAPI_FAMILY_PARTITION(Partition) ((WINAPI_FAMILY & Partition) == Partition)
/* Macro to determine if only one partition is enabled from a set */
#define WINAPI_FAMILY_ONE_PARTITION(PartitionSet, Partition) ((WINAPI_FAMILY & PartitionSet) == Partition)
So your WINAPI_PARTITION_DESKTOP would only be set if you are running on a Desktop family of the the system.
WINAPI_FAMILY is also set depending on the targeted Windows version.
See this discussion and the linked blog post series.
In particular, if you're not writing an "App" (for >= Win 8) then:
Prefer use of the standard _WIN32_WINNT Windows Defines for selecting
the correct Win32 API (i.e. many Win32 APIs required for use in
Windows Store apps are the Vista (0x0600), Windows 7 (0x0601), or
Windows 8 (0x0602) version.
You can use WINVER or _WIN32_WINNT.