-
Non-sensical errors
does anyone know what these errors are for?
Here is my Code:
Code:
/*********************************************************************************
*********************************************************************************/
#include <stdio.h>
#include "HLGrab.h"
#include <memory.h>
#include <stdlib.h>
// error checking macro
#define errChk(fCall) if (error = (fCall), error < 0) {goto Error;} else
/*******************************************************************************************
DisplayIMAQError
If there is an error this will display the error
int32_t error Error code to be tranlated by imgShowError
Int8 ErrorMessage Address the error message will be written to
*******************************************************************************************/
void DisplayIMAQError(int32_t error)
{
int i;
static Int8 ErrorMessage[256];
memset(ErrorMessage, 0x00, sizeof(ErrorMessage));
// converts error code to a message
imgShowError(error, ErrorMessage);
//show error message
for (i = 0; i < 256; i++) {
printf("%c", ErrorMessage[i]);
}
printf("\n");
}
/*******************************************************************************************
AnalogueCardSnap
Takes image using Analogue card with defined parameters.
unsigned int32_t Sid Session ID used to interact with card
Int8* Imaq Buffer 1D-Array which will store image data
unsigned int32_t top defines top of area where image will start to be taken out of total image area
unsigned int32_t left defines left side of area where image will start to be taken out of total image area
unsigned int32_t height defines height of image to be taken out of total image area
unsigned int32_t width defines width of image to be taken out of total image area
*******************************************************************************************/
int AnalogueCardSnap(unsigned int32_t Sid, unsigned int8_t* ImaqBuffer, unsigned int32_t top, unsigned int32_t left, unsigned int32_t height, unsigned int32_t width)
{
long error;
//Take image
//rval imgSnapArea(unsigned int32_t sid, void** bufAddr, unsigned int32_t top, unsigned int32_t left, unsigned int32_t height, unsigned int32_t width, unsigned int32_t rowPixels);
errChk(imgSnapArea(Sid, (void**)&ImaqBuffer, top, left, height, width, width));
return 0;
Error:
if(error<0){
printf("Error while trying to take image \n");
DisplayIMAQError(error);
}
return 0;
}
/*******************************************************************************************
AnalogueCardInit
Initializes card and takes needed parameters from image
unsigned int32_t *Sid Session ID used to interact with card
unsigned int32_t *Iid Interface ID used to interact with card
*******************************************************************************************/
int AnalogueCardInit (unsigned int32_t *Sid, unsigned int32_t *Iid, unsigned int8_t *image1D, unsigned int8_t **image2D)
{
long error;
int i;
char intfName[64];
unsigned int BitsInPixel = 0;
unsigned int plotFlag;
intfName[0] = 'i';
intfName[1] = 'm';
intfName[2] = 'g';
intfName[3] = '2';
intfName[4] = 'a';
// Open an interface and a session
errChk(imgInterfaceOpen (intfName, Iid));
errChk(imgSessionOpen (*Iid, Sid));
width = 640;
height = 480;
//Make buffer size for image1D and image2D
*image1D = (unsigned int8_t) malloc ((*width)*(*height)*sizeof(int8_t));
if (image1D==NULL) printf("Allocating memory for image in memory failed.");
**image2D = (unsigned int8_t) malloc ((*width)*(*height)*sizeof(int8_t));
if (image2D==NULL) printf("Allocating memory for image in memory failed.");
//Make image2D point to parts of image1D to make a 2D array of image1D
for (i=0;i<480;i++){
image2D[i][0]=image1D[(i*640)];
}
return 0;
Error :
if(error<0){
printf("Error during card initialization \n");
DisplayIMAQError(error);
}
return 0;
}
/*******************************************************************************************
AnalogueCardClose
Closes the interface and the session
unsigned int32_t *Sid Session ID used to interact with card
unsigned int32_t *Iid Interface ID used to interact with card
*******************************************************************************************/
int AnalogueCardClose(unsigned int32_t *Sid, unsigned int32_t *Iid)
{
if(Sid)
imgClose (*Sid, TRUE);
if(Iid)
imgClose (*Iid, TRUE);
return 0;
}
int main(void)
{
return(0);
}
line 23 is the void DisplayIMAQError(int32_t error)
line 81 is the int AnalogueCardInit...
line 165 is teh int AnalogueCardClose
Code:
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(23) : error C2146: syntax error : missing ')' before identifier 'error'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(23) : error C2061: syntax error : identifier 'error'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(23) : error C2059: syntax error : ';'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(23) : error C2059: syntax error : ')'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(24) : error C2449: found '{' at file scope (missing function header?)
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(36) : error C2059: syntax error : '}'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(81) : error C2143: syntax error : missing ')' before '*'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(81) : error C2143: syntax error : missing '{' before '*'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(81) : error C2059: syntax error : 'type'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(81) : error C2059: syntax error : ')'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(165) : error C2143: syntax error : missing ')' before '*'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(165) : error C2143: syntax error : missing '{' before '*'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(165) : error C2059: syntax error : 'type'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(165) : error C2059: syntax error : ')'
-
int32_t is defined in <stdint.h>, which you did not include.
-
Note that Visual Studio does not ship with stdint.h by default, but you can find one at wikipedia: http://en.wikipedia.org/wiki/stdint.h
-
ok so i downloaded it now i get wierd errors from a library i am using...
Code:
/*********************************************************************************
*********************************************************************************/
#include <stdio.h>
#include "HLGrab.h"
#include <memory.h>
#include <stdlib.h>
#include "stdint.h"
#include "imaq.lib"
// error checking macro
#define errChk(fCall) if (error = (fCall), error < 0) {goto Error;} else
//prototypes
void DisplayIMAQError(int32_t error);
int AnalogueCardSnap(uint32_t Sid, uint8_t* ImaqBuffer, uint32_t top, uint32_t left, uint32_t height, uint32_t width);
int AnalogueCardInit (uint32_t *Sid, uint32_t *Iid, uint16_t *width, uint16_t *height, uint8_t *image1D, uint8_t **image2D);
int AnalogueCardClose(uint32_t *Sid, uint32_t *Iid);
/*******************************************************************************************
DisplayIMAQError
If there is an error this will display the error
int32_t error Error code to be tranlated by imgShowError
Int8 ErrorMessage Address the error message will be written to
*******************************************************************************************/
void DisplayIMAQError(int32_t error)
{
int i;
int8_t ErrorMessage[256];
memset(ErrorMessage, 0x00, sizeof(ErrorMessage));
// converts error code to a message
imgShowError(error, ErrorMessage);
//show error message
for (i = 0; i < 256; i++) {
printf("%c", ErrorMessage[i]);
}
printf("\n");
}
/*******************************************************************************************
AnalogueCardSnap
Takes image using Analogue card with defined parameters.
unsigned int32_t Sid Session ID used to interact with card
Int8* Imaq Buffer 1D-Array which will store image data
unsigned int32_t top defines top of area where image will start to be taken out of total image area
unsigned int32_t left defines left side of area where image will start to be taken out of total image area
unsigned int32_t height defines height of image to be taken out of total image area
unsigned int32_t width defines width of image to be taken out of total image area
*******************************************************************************************/
int AnalogueCardSnap(uint32_t Sid, uint8_t* ImaqBuffer, uint32_t top, uint32_t left, uint32_t height, uint32_t width)
{
long error;
//Take image
//rval imgSnapArea(unsigned int32_t sid, void** bufAddr, unsigned int32_t top, unsigned int32_t left, unsigned int32_t height, unsigned int32_t width, unsigned int32_t rowPixels);
errChk(imgSnapArea(Sid, (void**)&ImaqBuffer, top, left, height, width, width));
return 0;
Error:
if(error<0){
printf("Error while trying to take image \n");
DisplayIMAQError(error);
}
return 0;
}
/*******************************************************************************************
AnalogueCardInit
Initializes card and takes needed parameters from image
unsigned int32_t *Sid Session ID used to interact with card
unsigned int32_t *Iid Interface ID used to interact with card
int *width Width of image read by frame grabber
int *height Height of image read by frame grabber
int *pixels Number of pixels read by frame grabber (usually = width)
*******************************************************************************************/
int AnalogueCardInit (uint32_t *Sid, uint32_t *Iid, uint16_t *width, uint16_t *height, uint8_t *image1D, uint8_t **image2D)
{
long error;
int i;
char intfName[64];
unsigned int BitsInPixel = 0;
unsigned int plotFlag;
intfName[0] = 'i';
intfName[1] = 'm';
intfName[2] = 'g';
intfName[3] = '2';
intfName[4] = 'a';
// Open an interface and a session
errChk(imgInterfaceOpen (intfName, Iid));
errChk(imgSessionOpen (*Iid, Sid));
width = 640;
height = 480;
/*
// Get Aquisition window height and width
errChk(imgGetAttribute (*Sid, IMG_ATTR_ROI_WIDTH, width));
errChk(imgGetAttribute (*Sid, IMG_ATTR_ROI_HEIGHT, height));
errChk(imgGetAttribute (*Sid, IMG_ATTR_BITSPERPIXEL, &BitsInPixel));
// Set pixel length
errChk(imgSetAttribute (*Sid, IMG_ATTR_ROWPIXELS, *height));
// get the pixel depth of the camera.
switch(BitsInPixel)
{
case 10:
plotFlag = IMGPLOT_MONO_10;
break;
case 12:
plotFlag = IMGPLOT_MONO_12;
break;
case 14:
plotFlag = IMGPLOT_MONO_14;
break;
case 16:
plotFlag = IMGPLOT_MONO_16;
break;
case 24:
case 32:
// assumes that a 24 bits camera is a color camera.
// in this mode, even if the camera is 24 bits the board returns 32 bits values
plotFlag = IMGPLOT_COLOR_RGB32;
break;
default:
plotFlag = IMGPLOT_MONO_8;
break;
}
*/
//Make buffer size for image1D and image2D
*image1D = (uint8_t) malloc ((*width)*(*height)*sizeof(int8_t));
if (image1D==NULL) printf("Allocating memory for image in memory failed.");
**image2D = (uint8_t) malloc ((*width)*(*height)*sizeof(int8_t));
if (image2D==NULL) printf("Allocating memory for image in memory failed.");
//Make image2D point to parts of image1D to make a 2D array of image1D
for (i=0;i<480;i++){
image2D[i][0]=image1D[(i*640)];
}
return 0;
Error :
if(error<0){
printf("Error during card initialization \n");
DisplayIMAQError(error);
}
return 0;
}
/*******************************************************************************************
AnalogueCardClose
Closes the interface and the session
unsigned int32_t *Sid Session ID used to interact with card
unsigned int32_t *Iid Interface ID used to interact with card
*******************************************************************************************/
int AnalogueCardClose(uint32_t *Sid, uint32_t *Iid)
{
if(Sid)
imgClose (*Sid, TRUE);
if(Iid)
imgClose (*Iid, TRUE);
return 0;
}
int main(void)
{
return(0);
}
Code:
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(1) : error C2059: syntax error : '!'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(2) : error C2018: unknown character '0x60'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(3) : error C2018: unknown character '0x2'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x10'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x10'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x10'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x10'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x1'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x1'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x10'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x10'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x1'
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\imaq.lib(4) : error C2018: unknown character '0x1'
-
Okay, you probably don't want to include a .lib file. That's pre-compiled, it's not human (or compiler!) readable, et cetera. You want to link with the lib file. In VS, you right click on the project name, and select properties, and then linker, and you get a place to add in .lib files (you'll probably see a bunch already). That's where you put imaq.lib.
-
Never include .lib files. You should only include header files.
.lib files contain information about exports from a .dll file that the linker uses to link the executable correctly. It does not contain code, so the compiler cannot read it.
-
oh yeah right.. waht was i thinking :P
-
I however get errors like.
Code:
1>c:\documents and settings\esorense\desktop\imaq code\new folder\dtest\dlltest.c(37) : warning C4013: 'imgShowError' undefined; assuming extern returning int
which is a function held within the library
EDIT: and i get this error
Code:
1>DLLTEST.obj : error LNK2019: unresolved external symbol _imgShowError referenced in function _DisplayIMAQError
-
I know nothing about this library. However, I assume that, if you have a .lib file, you must also have a .h file that tells you what is in that library. Include that file, so that the compiler can see the definitions of the functions and knows how to call them.
-
1st: there is no prototype for the function. Treat that warning like an error. You must include the header where this prototype resides.
2nd: seems the linker can't find the function imgShowError. This can be more tough, however. There's no ways way to tell. Does the function exist in the dll (not misspelled), and are you using the same calling convention?
-
ok i didnt include that header because i didnt think i needed it and it was giving me errors... but now i have just deleated the parts i dont need and viola the errors are gone :P
thanks guys!
-
You always need to include the file containing the functions you need to use.
In C, you can get away with not to, but in C++ it's an error.
And just because you can get away with it in C doesn't mean you should. It's very, very bad (which is why it isn't allowed in C++ either).
-
Code:
#define errChk(fCall) if (error = (fCall), error < 0) {goto Error;} else
If you must do this sort macro, at the very least skip the else - there's no point in having an else after a goto, since it will jump away from the code following the if-statement anyways [there may be really strange cases where this is not true, but in your code I don't see any reason to use an else].
Also, as you have always written errChk(...) with a semicolon immediately after, it's clear that you don't actually use the else-branch anyways.
Edit: And there should be no reason to check the error again at the error label.
Code:
Error:
if(error<0){
printf("Error while trying to take image \n");
--
Mats