Problem background: I am writing a Visual Studio C++ app referencing an Api library provided by a third party.

Problem: after calling the API function I am getting a 2059 "syntax error" that I don't understand. I have added the code exactly as the third party documentation has described.

Error:c:\documents and settings\********\my documents\visual studio 2005\projects\mvm\mvm\main.cpp(18) : error C2059: syntax error : 'if'

Code:

/* Input Values */
LPCSTR         filterName = "MVMCam";
CapInfoStruct  capInfo;
/* Initialise capInfo here */

/* Output Values */
int            index;
HANDLE         hImager;

/* Call function */
int nResult=FclInitialize("MVMCam",index,capInfo,&hImager);
if(ApiSuccess!=nResult) ****error line *****

I am a novice and could use some help. What is my mistake?

I see a couple of problems, but nothing that would give you a syntax error. Can you post some more code? Maybe something complete that we can brainpile? :)

Here is what I have so far. Why syntax error? Am I missing a class def.? I know there are other problems at the bottom, but I want to focus on that stupid syntax error.

#include "stdafx.h"
#include <iostream>
using namespace std;

 /* Input Values */
LPCSTR         filterName = "MVMCam";
CapInfoStruct  m_capInfo;
/* Initialise capInfo here */

/* Output Values */
int            index;
HANDLE         hDriver;

    int nIndex;
    int rt=FclInitialize("MVMCam",nIndex,m_capInfo,&hDriver);
    if(ResSuccess != rt){
        FclUninitialize(&hDriver);
        AfxMessageBox("Can not open USB camera!");
        return ;
        )

Here is what I have so far. Why syntax error? Am I missing a class def.? I know there are other problems at the bottom, but I want to focus on that stupid syntax error.

#include "stdafx.h"
#include <iostream>
using namespace std;

 /* Input Values */
LPCSTR         filterName = "MVMCam";
CapInfoStruct  m_capInfo;
/* Initialise capInfo here */

/* Output Values */
int            index;
HANDLE         hDriver;

    int nIndex;
    int rt=FclInitialize("MVMCam",nIndex,m_capInfo,&hDriver);
    if(ResSuccess != rt){
        FclUninitialize(&hDriver);
        AfxMessageBox("Can not open USB camera!");
        return ;
        )

If that's your whole code then you're missing a function. C++ is weird like that, you can put declarations and certain definitions outside of a function, but the instant you want to do some work, you need a function. The starting point for a program is called main().

#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
  /* Input Values */
  LPCSTR         filterName = "MVMCam";
  CapInfoStruct  m_capInfo;
  /* Initialise capInfo here */

  /* Output Values */
  int            index;
  HANDLE         hDriver;

  int nIndex;
  int rt=FclInitialize("MVMCam",nIndex,m_capInfo,&hDriver);
  if(ResSuccess != rt){
    FclUninitialize(&hDriver);
    AfxMessageBox("Can not open USB camera!");
    return;
  }
}

The error is a tricky one. It's saying that an if statement can't be used outside of a function. That's really reading between the lines and that kind of insight comes from experience working with C/C++. ;) As you write more and more code, you'll get a feel for what's allowed and what's not.

You really helped me and I was struggling so much with that error. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.