I'm trying to create a combo box in Win32 by following this msdn tutorial.
When I implement step 2 and try to compile, I get the following error:
error: 'wcscpy_s' was not declared in this scope
wcscpy_s(A, sizeof(A) / sizeof(TCHAR), (TCHAR*)Planets[k]);
I've included the following header files, hoping to solve this issue:
#include <string.h>
#include <wchar.h>
#include <windows.h>
#include <CommCtrl.h>
#include <math.h>
#include <objbase.h>
Can someone help me understand why I'm getting this error? Thanks in advance.
From cpp-reference
As with all bounds-checked functions, wcscpy_s is only guaranteed to be available if STDC_LIB_EXT1 is defined by the implementation and if the user defines STDC_WANT_LIB_EXT1 to the integer constant 1 before including wchar.h.
Related
MSVC keeps telling me that ParseNetworkString is undefined.
But I've done:
#include <Winsock2.h>
#include <Ws2tcpip.h>
#include <iphlpapi.h>
as expressed in the remark part of the docs
Thank you.
I've had a look inside "iphlapi.h" and it states (line 1287)
// app must include winsock2.h, ws2ipdef.h, and windns.h to use this API
So when I use
#include <WinSock2.h>
#include <ws2ipdef.h>
#include <WinDNS.h>
#include <iphlpapi.h>
ParseNetworkString becomes available.
So it seems you were on the right track, just missing the include of <WinDNS.h>
I'm having a strange linking issue after I included inotify in my program to monitor changes to a filesystem. The project includes <fcntl.h> in many other source files. However, when I include <sys/inotify.h> in the source file which is doing the directory monitoring, I get this error:
/usr/include/fcntl.h:30:1: error: expected initializer before ‘extern’
__BEGIN_DECLS
My project uses CMake, although that doesn't seem to be relevant for finding inotify. It IS finding the inotify declarations to my knowledge, since when I included , it threw an error that inotify_init() and the other functions I used were not defined. Inotify includes fcntl and is partially built on top of some of the functionality there, so my first thought was that it's importing a different version of fcntl than the rest of my program.
In ObjectManager.h:
#ifndef MANAGE_OBJECT_H
#define MANAGE_OBJECT_H
#include "config.h"
//includes all lua headers under extern 'C'
#include <lua.hpp>
#include <list>
#include <unordered_map>
#include <pthread.h>
class ObjectManager //...
The only thing that changed was ObjectManager.cc, with the addition of sys/notify and the implementation of the watcher (not included because this is a linking issue):
#include "config.h"
#include "ObjectManager.h"
#include "Control.h"
#ifdef OBJECT_MANAGER_ENABLED
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <vector>
#include <unistd.h>
#include <fstream>
#include <sys/inotify.h>
//... inotify implementation
Where Control.h declares #include <fcntl.h>.
This is the closest issue I found, related to some problems in the implementation of different fcntl headers for userspace usage. https://lkml.org/lkml/2008/9/16/98
The same problem occurs on Linux 2.6 running on Centos 6 and Linux 4.0 running on Centos 7.
Any ideas on what is causing this error and how to successfully include inotify?
Resolution: A function definition lacked a semicolon at the END of ObjectManager.h right before a #endif, and the resulting GCC error that propagated through the next includes in a complicated manner, resulting in a strange preprocessor error in fcntl.h.
Visual Studio 2015. I am reading the "Windows via C\C++" book and try to use its code samples. Author writes that the "safe" functions of string have the _s suffix and are declared in the StrSafe.h header. This header are to be the last in the list of includes. In my code I included such headers:
#include <iostream>
#include <exception>
#include <string>
#include <Windows.h>
#include <strsafe.h>
But I have a problem:
// IDE doesn't see the _tcscpy_s function
errno_t result = _tcscpy_s(szBuffer, _countof(szBuffer), TEXT("0123456789"));
I looked for info about the _tcscpy_s function, but I didn't see info about its header file (I expected that it is strsafe.h).
How can I fix it?
Just like any other "Generic Text" string function version, the _tcscpy_s() function is declared in TCHAR.H (as mentioned in the documentation).
Add #include <tchar.h> to your code.
I am not able to compile my program SHGetSpecialFolderPath() not being declared in the scope of the program, while the correct header is being included (according to MSDN)
http://msdn.microsoft.com/en-us/library/bb762204(v=vs.85).aspx
Here are the headers for my project:
#include <iostream>
#include <iostream>
#include <windows.h>
#include <algorithm>
#include <vector>
#include <fstream>
#include <direct.h>
#include <shlobj.h>
With error:
C:\Users\user\Documents\getAppData\main.cpp|31|error: `SHGetSpecialFolderPath' was not declared in this scope
with shlobj.h being the header with the declaration in it.
Any ideas why the compiler is throwing the error? Here is how I am calling the function:
char appData[MAX_PATH];
SHGetSpecialFolderPath( NULL
,appData
,CSIDL_LOCAL_APPDATA
,1 );
cout << appData << endl;
Thanks!
From the MSDN page:
The Microsoft Internet Explorer 4.0
Desktop Update must be installed for
this function to be available.
With Windows 2000, this function is
superseded by ShGetFolderPath. You can
use this function on earlier systems
by including the redistributable DLL,
ShFolder.dll.
Perhaps this is your problem?
I'm trying without any luck to include strings in my C++ Win32 API beginner project. The code won't compile if I define a string. What's going on?
Details:
I was working in Dev C++, but now have switched to Code::Blocks using the (default?) "Gnu GCC Compiler".
Here are the code cases I have tried, all similar, with their results:
Compiles successfully:
#include <windows.h>
#include <string.h> //<string> throws "no such file or directory"
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
//...the rest works perfectly, omitted in following examples
Fails:
#include <windows.h>
#include <string.h>
// Error: "string" does not name a type
string myString;
// ...WndProc
Compiles successfully:
#include <windows.h>
#include <string.h>
using namespace std;
// ...WndProc
Fails:
#include <windows.h>
#include <string.h>
using namespace std;
// Error: "string" does not name a type
string myString;
// ...WndProc
Fails:
#include <windows.h>
#include <string.h>
// Error: expected constructor, destructor, or type conversion before "myString"
// Error: expected ',' or ';' before "myString"
std::string myString;
// ...WndProc
I asked this question a few days ago but deleted it because it seemed like a dumb question. However, it wasn't solved and now has come back to haunt me. Thanks in advance.
Does the source file have a .cpp extension? If it's .c, it will compile as C code, which probably excludes the directories containing the standard C++ headers.
#include <string.h> //<string> throws "no such file or directory"
Something is seriously broken with either your compiler installation or your use of it. Whatever comes after this, not being able to include the header for std::string is going to make it very difficult to use one.
You can install the GCC suite without C++ support, maybe that's your problem.
<string.h> contains ANSI C string macros and function declarations (see here) , not the C++ string. To use std::string, you need to do
#include <string>
(no .h)
#include <windows.h>
#include <string>
std::string myString;
string.h has only methods to handle the string. For example, strcpy, strlen etc... (http://opengroup.org/onlinepubs/007908799/xsh/string.h.html)
If you want to use std::string, you should use .
If there is no file, check that file.
Good luck :)