chikvision

Syntax error before string constant in large header file c++


I want to extract vía SDK a video in format .hik (Hikvision) to MP4. My code is the next:

#include <stdio.h>
#include <stdlib.h>
#include "../SDK/incEn/HCNetSDK.h"
#include "Windows.h"

using namespace std;


int saveRecordFile(int userId, char * srcfile, char * destfile) {
    HINSTANCE hGetProcIDDLL = LoadLibrary("D:\\ExtraccionYConversionArchivos\\c++\\Fuente\\SDK\\HCNetSDK.dll");
    int bRes = 1;
    int hPlayBack = 0;
    if ( (hPlayBack = NET_DVR_GetFileByName(userId, srcfile, destfile)) < 0)
    {
       printf("Error en GetFileByName. Error[$d]\n",NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }

    if (!NET_DVR_PlayBackControl(hPlayBack, NET_DVR_PLAYSTART,0,NULL))
    {
       printf("Control de play back fallido [%d]\n", NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }
    int nPos = 0;
    for (nPos = 0; nPos < 100 && nPos >= 0; nPos = NET_DVR_GetDownloadPos(hPlayBack))
    {
        Sleep(5000);
    }
    printf("Se obtuvo %d\n", nPos);

    if (!NET_DVR_StopGetFile(hPlayBack))
    {
       printf("Error al detener descarga de archivo [%d]\n",NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }
    printf("%s\n",srcfile);

    if (nPos < 0 || nPos > 100)
    {
       printf("Error de descarga [%d]\n", NET_DVR_GetLastError());
       bRes = -1;
       return bRes;
    }
    else
    {
        return 0;
    }
}

int main()
{
    printf("Hello world!\n");
    return 0;
}

It uses the HCNetSDK.h header, which throw me an error in multiple lines: syntax error before string constant. This header file have more than 41K lines, and most of the error are after typedef:

typedef void (CALLBACK *MSGCallBack)(LONG lCommand, NET_DVR_ALARMER *pAlarmer, char *pAlarmInfo, DWORD dwBufLen, void* pUser); 
NET_DVR_API BOOL __stdcall NET_DVR_SetDVRMessageCallBack_V30(MSGCallBack fMessageCallBack, void* pUser);

What could be the problem? Before this lines, there are more than 6K typedef struct like this:

typedef struct  tagNET_DVR_MATRIX_STATUS_V50
{
    DWORD dwSize;
    BYTE  byMainFrameType;
    BYTE  bySoltNum;
    BYTE  byBoardNum;
    BYTE  byLCDPanelStatus;
    NET_DVR_MATRIX_SUBBOARD_V50 struMatrixSubboard[MAX_MATRIX_SUBBOARD_NUM];
    DWORD dwFanSequence;
    DWORD dwFanConnectStatus;
    DWORD dwFanOperationStatus;
    BYTE  byDeviceModel[32];
    BYTE  byRes[32];
}NET_DVR_MATRIX_STATUS_V50, *LPNET_DVR_MATRIX_STATUS_V50;

And even that I make comments over each typedef struct to catch the mistake, I couldn't figure out how.


Solution

  • A few things to try: Look for another file that includes this header. Does it compile? What other headers does it use and which of those come before this header in the list?

    Can you copy (duplicate and rename) this code into a C file with a simple hello world main function? It might force the compiler to tell you which line the actual problem is on.

    Are you using an old compiler? I used to get problems with an old version of Visual Studio - it wasn’t up to date with C99 so it couldn’t compile certain data types (that were no problem for GNU compilers). C standards are sometimes updated and you need to use a suitable compiler (or code in an old style!).

    Finally, is it possible to extract or convert the data with ffmpeg? If you can do it on a command line, there’s no need to compile any code.