Windows header file <Windows.h> with WIN32_LEAN_AND_MEAN - windows

#include <Windows.h>
#define WIN32_LEAN_AND_MEAN
Why the above code statement has mistake? Is the order wrong or others?

In the Windows.h header, if WIN32_LEAN_AND_MEAN is not defined, the preprocessor will includes other headers. So if you want to not include theses headers, you must define WIN32_LEAN_AND_MEAN before #include , else it won't have any effects
#ifndef WIN32_LEAN_AND_MEAN
#include <cderr.h>
#include <dde.h>
#include <ddeml.h>
#include <dlgs.h>
#ifndef _MAC
#include <lzexpand.h>
#include <mmsystem.h>
#include <nb30.h>
#include <rpc.h>
#endif
#include <shellapi.h>
#ifndef _MAC
#include <winperf.h>
#include <winsock.h>
#endif
#ifndef NOCRYPT
#include <wincrypt.h>
#include <winefs.h>
#include <winscard.h>
#endif
#ifndef NOGDI
#ifndef _MAC
#include <winspool.h>
#ifdef INC_OLE1
#include <ole.h>
#else
#include <ole2.h>
#endif /* !INC_OLE1 */
#endif /* !MAC */
#include <commdlg.h>
#endif /* !NOGDI */
#endif /* WIN32_LEAN_AND_MEAN */
Directly from Windows.h

The order is wrong. WIN32_LEAN_AND_MEAN affects what windows.h declares, so it needs to be defined before windows.h is included:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

Related

OpenGL/SDk Can not compile

I am trying to run the make file of some application. The source code is
INCL= -I/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/GLUT.framework/Versions/A/Headers
LIBD= -L/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries
evmovie: evmovie.c
cc evmovie.c -o evmovie $(INCL) $(LIBD) -framework GLUT -lGL -lGLU
When I run it in the terminal, it gives me a lot of warnings. The majority of them are saying a lot of glut function is deprecated since Mac OS 10.9. I just ignore them. However, one of the crucial errors is the following.
directory not found for option '-L/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries'
ld: library not found for -lGL
I do not not know how to fix this. Can anyone help me?
By the way, the source code of evmovie.c is
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#if defined(WIN32) || defined(_WIN32)
#include <GLUT/glut.h>
#include <windows.h>
#include <io.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#define __cdecl
#define _fileno fileno
int _filelength(int fd)
{ struct stat statbuf;
fstat(fd,&statbuf);
return statbuf.st_size;
}
#if defined(__APPLE__)
#include <GLUT/glut.h>
#else
// unix, linux
#include <GL/glut.h>
#endif
#endif

Error 2 files include each other

i have this problems while trying to include 2 files each other:
./include/../include/../src/Socket/../LinuxClass/ThreadingPool.hpp:38:5:
error: ‘Client’ does not name a type
Client client;
I already find a solution about declaring the first class in the second files but the error is still there here is the 2 .h
#ifndef THREADINGPOOL_HPP_
#define THREADINGPOOL_HPP_
#include <functional>
#include <algorithm>
#include <queue>
#include "../Socket/Client.hpp"
#include "../Intefaces/IThread.hpp"
#include "Mutex.hpp"
#include "Thread.hpp"
#include "Condvar.hpp"
#include "Process.hpp"
class ThreadingPool {
public:
ThreadingPool(unsigned int num_thr);
~ThreadingPool();
void Add_fct(std::function<void()> job);
private:
enum States {LIVE, DIE};
std::vector<std::thread> thrdVec;
std::vector<States> states;
std::queue<std::function<void()>> jobs;
Mutex mtex;
Condvar cond;
Process pros;
Client client;
};
#endif /* !THREADINGPOOL_HPP_ */
And the second one
#ifndef CLIENT_HPP_
# define CLIENT_HPP_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <functional>
#include <unistd.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#define PORT 1043
#define METASIZE 1024
#include "check_cmd.hpp"
class ThreadingPool;
class Client {
public:
Client();
~Client();
void ifMessage(ThreadingPool * thrdPool);
private:
int csock;
struct sockaddr_in csin;
};
#endif
I think the problem you have is that you put # define (space between hashtag)
instead of #define (no space between hashtag)
i think the space between it causes the compiler to not
implement the code within client.hpp, because you are not getting a error
saying
client.hpp does not exist, instead a error saying client (the class) does not exist. without define being wrote correctly, the compiler pretty much skips past the code within #ifndef

Cross-platform definition of _byteswap_uint64 and _byteswap_ulong

Visual Studio defines _byteswap_uint64 and _byteswap_ulong in stdlib.h.
Am I right to assume, that this is not standard and won't compile on Linux or Darwin?
Is there a way to define these includes in a cross-platform way?
Google's CityHash source code uses this code:
https://github.com/google/cityhash/blob/8af9b8c2b889d80c22d6bc26ba0df1afb79a30db/src/city.cc#L50
#ifdef _MSC_VER
#include <stdlib.h>
#define bswap_32(x) _byteswap_ulong(x)
#define bswap_64(x) _byteswap_uint64(x)
#elif defined(__APPLE__)
// Mac OS X / Darwin features
#include <libkern/OSByteOrder.h>
#define bswap_32(x) OSSwapInt32(x)
#define bswap_64(x) OSSwapInt64(x)
#elif defined(__sun) || defined(sun)
#include <sys/byteorder.h>
#define bswap_32(x) BSWAP_32(x)
#define bswap_64(x) BSWAP_64(x)
#elif defined(__FreeBSD__)
#include <sys/endian.h>
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)
#elif defined(__OpenBSD__)
#include <sys/types.h>
#define bswap_32(x) swap32(x)
#define bswap_64(x) swap64(x)
#elif defined(__NetBSD__)
#include <sys/types.h>
#include <machine/bswap.h>
#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
#define bswap_32(x) bswap32(x)
#define bswap_64(x) bswap64(x)
#endif
#else
#include <byteswap.h>
#endif
I'm not aware of a cross-platform and efficient way of doing that. If you use GCC you can use the builtin byteswap like:
uint32_t __builtin_bswap32 (uint32_t x)
Those are fast but certainly not portable... unless you wrap the various versions under the appropriate ifdefs
Cheers
Francesco

ffmpeg include error - github project

I am trying to compile (IDE:VS2008) the following project:
https://github.com/arpu/adscanner
As the project needs the ffmpeg libaries, I've downloaded the DEV version from here: http://ffmpeg.zeranoe.com/builds/
I've linked the library directions and added the headers to the include path.
Though I get the error message: ""ffmpeg/avcodec.h": No such file or directory"
Thank you in advance
PS: I've tried both the 64bit and 32bit library, neither worked. But how can I figure it out weather the github project is using the 32bit or 64bit ffmpeg version?
Change this in ffmpeg_movie.h
extern "C" {
#include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h>
#include <ffmpeg/swscale.h>
}
to this
extern "C"{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
and when i last used ffmpeg i had to add this
extern "C"{
#ifdef __cplusplus
#define __STDC_CONSTANT_MACROS
#ifdef _STDINT_H
#undef _STDINT_H
#endif
# include <stdint.h>
#endif
}
# include <stdio.h>
#ifndef INT64_C
#define INT64_C(c) (c ## LL)
#define UINT64_C(c) (c ## ULL)
#endif

unexpected end of file error in ffmpeg libavutils/common.h while compiling

I am compiling following simple code in ffmpeg.
#include "stdafx.h"
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
void main()
{
av_register_all();
}
all the ffmpeg headers i have included in project properties.
but i am getting the following error on compiling.
Error 1 error C1004: unexpected end-of-file found dev\include\libavutil\common.h 87 1
Regards
Mayank
Try define __STDC_CONSTANT_MACROS before including those headers to see if problem can be solved.
#include "stdafx.h"
extern "C" {
#define __STDC_CONSTANT_MACROS
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
};
See http://bigbang.waterlin.org/bang/using-ffmpeg-under-windows-visual-cpp-environment/
Regards zcy

Resources