Error C2894

Hello. I am writing simple pakcet sniffer and i am using WinPcap. And when i try to compile my project occurs error C2894 "Error 1 error C2894: templates cannot be declared to have 'C' linkage C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\include\wspiapi.h 44
". Here is the definiton of the template:

#ifndef _WSPIAPI_H_

#define _WSPIAPI_H_

#include <stdio.h> // sprintf()

#include <stdlib.h> // calloc(), strtoul()

#include <malloc.h> // calloc()

#include <string.h> // strlen(), strcmp(), strstr()

#if defined(__GOT_SECURE_LIB__) && __GOT_SECURE_LIB__ >= 200402L

#define _WSPIAPI_STRCPY_S strcpy_s

#define _WSPIAPI_STRCAT_S strcat_s

#define _WSPIAPI_STRNCPY_S strncpy_s

#define _WSPIAPI_SPRINTF_S_1 sprintf_s

#else

#define _WSPIAPI_STRCPY_S(_Dst, _Size, _Src) strcpy((_Dst), (_Src))

#define _WSPIAPI_STRCAT_S(_Dst, _Size, _Src) strcat((_Dst), (_Src))

#define _WSPIAPI_STRNCPY_S(_Dst, _Size, _Src, _Count) strncpy((_Dst), (_Src), (_Count)); (_Dst)[(_Size) - 1] = 0

#define _WSPIAPI_SPRINTF_S_1(_Dst, _Size, _Format, _Arg1) sprintf((_Dst), (_Format), (_Arg1))

#endif // defined(__GOT_SECURE_LIB__) && __GOT_SECURE_LIB__ >= 200402L

#if !defined(_WSPIAPI_COUNTOF)

#if !defined(__cplusplus)

#define _WSPIAPI_COUNTOF(_Array) (sizeof(_Array) / sizeof(_Array[0]))

#else

template <typename __CountofType, size_t _N>

char (&__wspiapi_countof_helper(__CountofType (&_Array)[_N]))[_N];

#define _WSPIAPI_COUNTOF(_Array) sizeof(__wspiapi_countof_helper(_Array))

#endif

#endif

How can i fix that error

Thank you



Answer this question

Error C2894

  • Sherif Allam

    Thanks the /p helped with the preprocessor.

    and as some one above said the wspiapi.h is included in the ws2tcpip.h etc.

    but the file inclusion looks clean.

    THe guy who included the wspiapi.h outside of the extern "C".

    Still the problem exists, which means more investigation.

    Cheers


  • CLM10270

    Hello, I am running into the exact same issue that the initial poster had. I am inexperienced with C, so solving this problem hasn't been a simple task for me. I have located where IPV6STRICT is mentioned in wsipv6ok.h, but I don't know what to do with it. I don't know how I should devine IPV6STRICT (if I should even by trying to define it).

  • Vedat ARAL

    It is included by WS2tcpip.h and wsipv6ok.h. The comment on the latter header file is interesting:

    This module contains defines used to flag usage of IPv6 incompatible
    defines, stuctures and functions. They cause *cryptic* compile time
    error messages to be generated. Currently, this header is only
    included from winsock2.h.

    NOTE: The compile time flag, IPV6STRICT, must be defined

    Hmm, *cryptic* good enough for you Hunt down "IPV6STRICT"...



  • niceguysfinishlast

    Put this in front of your #includes, probably in stdafx.h:

    #define IPV6STRICT


  • Peter Kranenburg

    It sounds like you are trying to include a header file in an extern "C" block - something like:

    extern "C" {
    #include "myheader.h"
    }

    This won't work if "myheader.h" directly (or indirectly) includes the definition of a template.



  • Amir Steta

    But i don't know where wspiapi.h is included. I've searched for #include <wspiapi.h> but i didn't found it... :(
  • JEEA

    HI BD,

    Did you figure out why you were getting this error.

    I am running into the same error.

    Regards,

    foobar-12


  • Oran Dennison

    You can generate preprocessor output with the /P flag. Look for .i files.


  • Qsac

    You can use the compiler option /showIncludes to show the list of all the files included by the program - this will show you how a specific header file is included.

  • _Damir_

    Jonathan

    Your reply is similar to the one you get when we search on the help.

    Is there a way we can run the compiler to generate preprocessor out put, and you could look at it and give a better response.

    If so do you have a canned workspace i can use to generate the preprocesor out put which propably i can look at and figure out myself


  • Error C2894