I'm making in gtk3 app that behaves like a launcher. I'm developing in linux and windows7 with msys2 and msvc2010. Everyhing is fine except that I can't use TerminateProcess because I get this warning:
implicit declaration of function 'TerminateProcess'
This is part of the code:
#if defined(G_OS_WIN32)
#if defined(__GNUC__)
#include <w32api.h>
#define WINVER WindowsXP
#define _WIN32_WINNT WindowsXP
#define _WIN32_WINDOWS WindowsXP
#define _WIN32_IE IE7
#endif
#include <processthreadsapi.h>
#endif
#include <gtk/gtk.h>
// ...
void kill_process (GPid pid)
{
#if defined(G_OS_WIN32)
TerminateProcess (pid, 0);
#else
kill (pid, SIGTERM);
#endif
g_spawn_close_pid (pid);
}
The above function kill_process works as expected in linux and in windows (msvc 2010), but it doesn't with msys2 mingw64... any ideas?
Related
I want to compile a simple test project for a library that makes use of a ftd2xx driver. I already compiled it successfully on linux and I'm trying to do the same on Windows. The main difference are some minor modification to the library.
The test file I want to compile is this:
//#include "HPX-linux.h"
#include "HPX-Windows.h"
#include <stdlib.h>
#include <stdio.h>
int main(){
int devs;
getSerialNum(&devs);
printf("%d\n\n", devs);
simpleTest("./myTest/");
return 0;
}
And the preprocessing directives of HPX-Windows.h are as follows:
#ifndef HPXLINUX_H
#define HPXLINUX_H
#include <math.h>
#include <stdint.h>
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include "ftd2xx.h"
#include <pthread.h>
// typedefs
//typedef uint16_t DWORD;
#ifndef __cplusplus
typedef uint8_t bool;
#endif
// static const defines
#ifndef __cplusplus
#define TRUE 1
#define FALSE 0
#endif
#define SUCCESS 0
#define FAILURE -1
#define RETRIEDTOOMANY -10
#define LOSTHEADFRAME -11
#define GOTAV 2
#ifdef __unix__
#define PRELIB extern
#elif _WIN32
#ifdef ADD_EXPORTS
#define PRELIB __declspec(dllexport)
#else
#define PRELIB __declspec(dllimport)
#endif
#endif
#ifdef __unix__
#define CALL
#elif _WIN32
#define CALL __cdecl
#endif
About ftd2xx, I have 2 .h headers, a .lib and a .dll.
With the driver properly installed, I could compile the library on linux with:
gcc -o test test.c -Wall -Wextra -lHPX-linux -lftd2xx -lm
I'm using MinGW on Windows. The command I'm using is:
gcc test.c HPX-Windows.c -L -lftd2xx -g
And then I get a list of errors type "undefined reference to _imp__*", being * a function. I expected them to be the functions of ftd2xx.h, but it also happens to function declared in HPX-Windows.h, including getSerialNum and simpleTest. Why does it happen when I'm using a .c source file instead of a library?
The error is caused by symbols exported with __declspec(dllimport) in header files that can't be imported from a shared library (.DLL).
I would recommend creating a libftd2xx.dll.a file from the ftd2xx.dll file and linking with that (e.g. if the files are in the current directory using -L. -lftd2xx.dll).
Or you could probably just link with the .dll file by specifying it in the gcc command, something like this: gcc -o test.exe test.c HPX-Windows.c ftd2xx.dll -g).
If that doesn't work check ftd2xx.h to see where __declspec(dllimport) is imported and see if you can set a define that causes the header to not use __declspec(dllexport)/__declspec(dllimport) and link with your lib file in case it's a static library (something like: gcc --static -o test.exe test.c HPX-Windows.c -L. -lftd2xx -g).
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
In my c++ class, I want use WIN API GetFileSizeEx() function. When I compile my code, the compilator said:
"error: 'GetFileSizeEx' was not declared in this scope".
However, others functions like CreateFile() or WriteFile() work perfectly.
In my class header, I declare this :
#if defined(WINVER) && WINVER==0x0602 /* windows 8 */
#define WINVER 0x0602
#define _WIN32_WINNT 0x0602
#elif defined(WINVER) && WINVER==0x0601 /* windows 7 */
#define WINVER 0x0601
#define _WIN32_WINNT 0x0601
#elif defined(WINVER) && WINVER==0x0600 /* windows vista and server 2008 */
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#elif defined(WINVER) && WINVER==0x0502 /* server 2003 */
#define WINVER 0x0502
#define _WIN32_WINNT 0x0502
#elif defined(WINVER) && WINVER==0x0501 /* windows xp */
#define WINVER 0x0501
#define _WIN32_WINNT 0x0501
#endif
#include <windows.h>
#include <winbase.h>
#include <string>
In my .cpp class:
Test::Test()
{
hFile = CreateFile(TEXT("conf/configure_tool.txt"),
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
canAcces = false;
}else
{
if(GetFileSizeEx(hFile,&sized) != 0)
{
canAcces = true;
}
}
}
Have you an idea to resolve my problem ?
From the documentation:
Minimum supported client Windows XP [desktop apps only]
So you need to ensure that you have defined WINVER to be 0x0501 or greater.
If that doesn't solve the problem then the likely cause is that you are using a deficient SDK. Perhaps from an old version of a non-MS compiler. Make sure that you have an up-to-date SDK.
It must be said that the conditional code in the question that attempts to define _WIN32_WINNT is a little odd. Why don't you define _WIN32_WINNT at the same time as you define WINVER?
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
#include <windows.h>
#include <stdlib.h>
#include <tchar.h>
#ifdef __cplusplus
extern "C"
#endif
void * _ReturnAddress(void);
#pragma intrinsic(_ReturnAddress)
//I inserted the following code inside one of the functions
void func()
{
------------
-------
----
-
HMODULE module_handle;
TCHAR module_name[4096];
DWORD flag = 0x00000004;
GetModuleHandleEx(flag, (LPCTSTR) _ReturnAddress(), &module_handle);
GetModuleFileName(module_handle,module_name,4096);
-----
--
}
When I compile the code as a separate project everything works fine. Please help.
To compile an application that uses
this function, define _WIN32_WINNT as
0x0501 or later. For more information,
see Using the Windows Headers.
Even if you get your code to compile, what you're doing smells of wrongness.
If you're using the return address to make any sort of security-related decision, stop. You can't trust the return address of the calling function. No really, you can't trust the return address of the calling function.