From: Faraz on
On Feb 4, 10:35 am, Faraz <faras...(a)gmail.com> wrote:
> On Feb 2, 9:44 am, r_z_aret(a)pen_fact.com wrote:
>
>
>
>
>
> > On Tue, 2 Feb 2010 08:32:06 -0800 (PST), Faraz <faras...(a)gmail.com>
> > wrote:
>
> > >Dear All,
>
> > >Lately during one of my projects i have encountered a problem and
> > >stuck on that point. I have an optical sensor that i have attached to
> > >my pc and it detects colors in terms of RGB values. The sensor is from
> > >a famous company and has been supplied with its own software where I
> > >could see the data. Now to access those RGB values on visual C (so i
> > >could further manipulate the data) the company has provided me with a
> > >header file and lib file and ofcourse the dll file. In the
> > >documentation  which is poorly written they have also described some
> > >API functions that have been defined in the header file and should be
> > >called in order to access the values from sensor. For example, int
> > >USB_DLL_API MTCSGetADCAVR2( int iIndex, unsigned short* usBuf, int
> > >iCounts); is one of the functions that I have to use.
> > >Now since I am new to dll programming and want to use these functions
> > >so I could access the values from sensor, I was wondering if someone
> > >could give me a help in order to trigger off my work. I mean I read
> > >some articles on how to make a dll but they are rather confusing and I
> > >think if the company has already given me the files with functions it
> > >should be rather easier to use.
> > >I would deeply appreciate your help.
>
> > Earlier posts provide good detail. I'll add a somewhat different
> > perspective.
>
> > The usual, and easier, method is to use static binding. For this, you
> > 1) use #include for the header file so your compiler recognizes the
> > functions, etc.
> > 2) link to the lib file. You can use a #pragma as an earlier post
> > suggested, or you can modify the settings in your project file
> > (probably using the settings dialog in your IDE)
> > 3) distribute the DLL with your executable, and put it in a directory
> > that the operating system searches for DLLs (could be with the
> > executable)
>
> > If you want your program to run even when the DLL is not present, you
> > need to use dynamic linking. For this, you
> > 1) use #include for the header file
> > 2) use LoadLibrary and GetProcAddress to load the DLL and access its
> > functions.
> > I don't think this is the way to go for your project, so I didn't
> > bother with some important details.
>
> > >regards,
> > >Faraz
>
> > -----------------------------------------
> > To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
>
> > Robert E. Zaret, eMVP
> > PenFact, Inc.
> > 20 Park Plaza, Suite 400
> > Boston, MA 02116www.penfact.com
> > Useful reading (be sure to read its disclaimer first):
> >    http://catb.org/~esr/faqs/smart-questions.html-Hide quoted text -
>
> > - Show quoted text -
>
> Dear All,
> Thanks so far!
> Using the implicit Dll call atleast I have started the way you said
> and have written a code. What I have done is that in Project settings->preprocesser->include directories, I have given the path of where my
>
> header file is, in my case I have set to D:\Program Files\Microsoft
> Visual Studio\MyProjects\sensor\MTCSApi.h because this is where I have
> placed my header file (is this the right place for it?). Similarly for
> linker I have given the path putting .lib file in debug folder where
> my exe also exists.
>
> I have written a small code
>
> #include<iostream.h>
> #include<MTCSApi.h>
>
> main()
> {
>
> /* The actual call to the function contained in the dll */
> int ReturnVal = MTCSInitSystem("0", 0x152a, 0x8220);
> cout<<"The value"<<ReturnVal;
>
> }
>
> just to see, as you said that if sensor was being initialized or not.
> i made this cpp file like normal win32 console application, and have
> included the header as shown. Now at compilation I am getting the
> following errors:
>
> d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
> error C2146: syntax error : missing ';' before identifier
> 'MTCSDllGetVersion'
> d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
> error C2182: 'USB_DLL_API' : illegal use of type 'void'
> d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
> fatal error C1004: unexpected end of file found
>
> and when I try to debug it takes me to the header file of the sensor
> with the above mentioned errors. I was wondering if one of you could
> suggest that where the problem lies since it is a prechecked h file
> from the company.
> regards- Hide quoted text -
>
> - Show quoted text -

just for clarity i am also adding the header file

#ifdef EXE
#ifdef USB_DLL_EXPORTS
#define USB_DLL_API __declspec(dllexport) __stdcall
#else
#define USB_DLL_API __declspec(dllimport) __stdcall
#endif
#endif

#ifdef INDEX
#include "MTCSApi_idx.h"
#endif


#ifndef OBJECT
#if defined(__cplusplus)
extern "C" {
#endif
#endif


void USB_DLL_API MTCSDllGetVersion(char* cBuf);
int USB_DLL_API MTCSInitSystem( char cTyp, int iVendorID, int
iProductID );
int USB_DLL_API MTCSReadVersion( char* cBuf);
int USB_DLL_API MTCSReadMemory( unsigned char* cBuf, int iNum);
int USB_DLL_API MTCSWriteMemory( unsigned char* cBuf, int iNum);
int USB_DLL_API MTCSGetADCBL( unsigned short* usBuf, int iCounts);
int USB_DLL_API MTCSGetADCAVR( unsigned short* usBuf, int
iCounts);
int USB_DLL_API MTCSGetADCBuf( unsigned short* usBuf);
int USB_DLL_API MTCSGetADC( unsigned short* usBuf);
int USB_DLL_API MTCSSetSwitch( int iCounts);
int USB_DLL_API MTCSSetEPoti( int iCounts);
int USB_DLL_API MTCSGetRGB( unsigned short* usBuf);
int USB_DLL_API MTCSStartRGB( unsigned short* usBuf, int iTime,
int iCycles);
int USB_DLL_API MTCSStopRGB( unsigned short* usBuf);
int USB_DLL_API MTCSCloseDevice(void);
int USB_DLL_API MTCSSetUpdateMode(void);


void USB_DLL_API MTCSGetSerienNummer( unsigned char idx, char
*buffer);
int USB_DLL_API MTCSGetADCAVR2( int iIndex, unsigned short* usBuf,
int iCounts);
int USB_DLL_API MTCSGetADCSummen( int iIndex, unsigned long* ulBuf,
int iCounts);
int USB_DLL_API MTCSSetParameter( int iIndex, int iVerst, int iTol);
int USB_DLL_API MTCSSearchAmplification( int iIndex, unsigned short*
usBuf, int iLimit);
int USB_DLL_API MTCSReadMemFromAdr( int iIndex, unsigned char* cBuf,
int iAdr, int iNum);
int USB_DLL_API MTCSWriteMemToAdr(int iIndex, unsigned char* cBuf,
int iAdr, int iNum);
int USB_DLL_API MTCSSetShift( int iIndex, int iShift);

#ifndef OBJECT
#ifdef __cplusplus
}
#endif
#endif

/
**************************************************************************************/

#endif /* _USB_API_H_ */

/
**************************************************************************************/
From: Faraz on
Dear All,
Above is the header file. Despite after defining the paths where this
"h" file is and linking the .lib with C++ 6 compiler by changing the
project settings, I have encountered some linking errors. I was
wondering if once could give it a look and tell me the solution.


en2.obj : error LNK2001: unresolved external symbol
__imp__MTCSGetADCAVR2
libcid.lib(iostrini.obj) : error LNK2001: unresolved external symbol
"void * __cdecl operator new(unsigned int,int,char const *,int)" (??
2(a)YAPAXIHPBDH@Z)
libcid.lib(_ios.obj) : error LNK2001: unresolved external symbol "void
* __cdecl operator new(unsigned int,int,char const *,int)" (??
2(a)YAPAXIHPBDH@Z)
libcid.lib(streamb.obj) : error LNK2001: unresolved external symbol
"void * __cdecl operator new(unsigned int,int,char const *,int)" (??
2(a)YAPAXIHPBDH@Z)
Debug/Sensor2.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

Sensor2.exe - 5 error(s), 0 warning(s)
From: r_z_aret on
On Thu, 4 Feb 2010 10:35:58 -0800 (PST), Faraz <farashes(a)gmail.com>
wrote:

>On Feb 2, 9:44�am, r_z_aret(a)pen_fact.com wrote:
>> On Tue, 2 Feb 2010 08:32:06 -0800 (PST), Faraz <faras...(a)gmail.com>
>> wrote:

clip

>
>Using the implicit Dll call atleast I have started the way you said
>and have written a code.

> What I have done is that in Project settings-
>>preprocesser->include directories, I have given the path of where my
>header file is, in my case I have set to D:\Program Files\Microsoft
>Visual Studio\MyProjects\sensor\MTCSApi.h because this is where I have
>placed my header file (is this the right place for it?).

You found the right place, but not the right setting. You used the
full path for one header file. You should list all the _directories_
that contain header files. That means the directory for the headers
you create and the directories for headers that come with libraries
you use.


> Similarly for >linker I have given the path putting .lib file in debug folder where
>my exe also exists.

If you look at the dialog box you used to set the header directories,
you should see something similar for libraries. And you want to add
the path to all _directories_ containing lib files you want searched.

You should also see a setting for executables. I _think_ you can enter
the directory containing the DLL from famous company. Or you can put
that DLL in one of the "standard" locations, like the Windows
directory. I rarely use DLLs, so I'm vague on this.

I recommend putting library files some place _other_ than in project
files. For simple libraries (such as the one from famous company), you
can put all the files (header, dll, and lib) in one directory. Except,
perhaps dll files. You may need

clip

>
>d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
>error C2146: syntax error : missing ';' before identifier
>'MTCSDllGetVersion'
>d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
>error C2182: 'USB_DLL_API' : illegal use of type 'void'
>d:\program files\microsoft visual studio\vc98\include\mtcsapi.h(43) :
>fatal error C1004: unexpected end of file found

These are consistent with header file problems. Either the compiler
can't find all the headers it needs, or they are not included in the
right order. Is mtcsapi.h yours? Or is it the header that came with
the library? My hunch is it's yours, and USB_DLL_API is defined in the
header from famous company. If I'm right, that's a very clear sign you
got the settings wrong. If mtcsapi.h is the header from famous
company, then you've #included it in the wrong place in your source
file. Most library files need to be included after windows.h, but some
need to be included before.
..

>
>and when I try to debug it takes me to the header file of the sensor
>with the above mentioned errors. I was wondering if one of you could
>suggest that where the problem lies since it is a prechecked h file
>from the company.
>regards

With those compilation errors, I'm surprised you got any executable to
test.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 400
Boston, MA 02116
www.penfact.com
Useful reading (be sure to read its disclaimer first):
http://catb.org/~esr/faqs/smart-questions.html
From: Faraz on
Dear Robert,

Thanks a lot on your insight. I thought on your solutions and changed
the settings. But unfortunately the problem still persists, I have
changed the Additional include directories settings to ..\Sensor2,
basically i read on net about the relative path thing coz there is a
bug in c++ once you enter the entire path. I dont get header errors
atleast but now a new one,

Linking...
LINK : fatal error LNK1104: cannot open file "..\Sensor2.obj"
Error executing link.exe.
stuck on this now...

any idea

From: Richard Heathfield on
Faraz wrote:
> Dear Robert,
>
> Thanks a lot on your insight. I thought on your solutions and changed
> the settings. But unfortunately the problem still persists, I have
> changed the Additional include directories settings to ..\Sensor2,
> basically i read on net about the relative path thing coz there is a
> bug in c++ once you enter the entire path.

Firstly, it isn't a bug in C++. It could conceivably be a bug in your
particular implementation of C++, but even this is far less likely than
the possibility that you've been misled by someone who doesn't know what
they're talking about.

> I dont get header errors
> atleast but now a new one,
>
> Linking...
> LINK : fatal error LNK1104: cannot open file "..\Sensor2.obj"
> Error executing link.exe.
> stuck on this now...
>
> any idea

This is the same kind of error as before, except that instead of being
unable to find the header of the Sensor2 module, now it can't find the
object file. Just add the object file's directory to your library path,
in much the same way that you added the header file's directory to your
include path.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within