Calling functions from sensors dll c++
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.
well it looks like you have everything you need. In fact I believe all you now need to do is to make sure that the header files you got delivered are in the paths where your compiler looks for them (try -I option or configure in your compiler settings/options) and that your DLL is in the DLL-paths (again you might need to configure the compiler/linker options and or the commandline option -L) . Then you should be good to go to run the exe from your Dev environment. If you happy with your development and deploy the exe then you have to put the DLLs in a global path (%PATH% variable on windows).
That should be it. Hope that helps.
Life is a short warm moment -
Death is the long cold rest.
Hardware interfaces are so often so very bad. A lot of them are written in C, too, making it difficult to work into a modern program without wrapping the stuff into an object. And, there is some sort of need to provide an example program that does not make any sense at all, you never get a 1-2-3 this is all you need to get the basics sort of example, its always an A to Z full program that shows off the widgets and extras while hiding the basics!
Anyway, here is how to handle the dll side of it:
add the headers to your project, and # include them.
add the .LIB file to your project
build, and it should all work, try calling the first function or 2 (usually, you have to init the hardware and or tell it your liscense or some sort of keycode to get started).
If you get that far, its simply figureing out what order to call the functions in and which functions you need to call.... Which always turns out to be just a few functions (like 10 or less out of 100 or more provided..).
Dear both of you,
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 (could be wrong). 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
/* The actual call to the function contained in the dll */
int ReturnVal = MTCSInitSystem("0", 0x152a, 0x8220);
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. I was wondering if one of you could suggest that where the problem lies.
this isnt it, but, use:
using namespace std;
int main ()
Those change what you have, which works and probably compiles, from a 1980's style program to a modern c++ look.
Your issue is one of 2 things. Either you failed to include some of the header files,
you need a MFC program to use their library (many libraries make use of MFC stuff, when they should not, usually its something unnecessary like CSTRING or HANDLE etc.)
What it is telling you is that the custom type or function 'MTCSDllGetVersion' cannot be found, so its header or defination is not "seen" by the compiler. Most likely then, your library has multiple headers that must be included.
I was able to fix those errors, it appeared that one of the define statement in the header was missing, now i dont have any compilation error but loads of linking error that I am unable to resolve. I have correctly linked to the header and the lib but still get this. do you have any idea...
sen2.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@YAPAXIHPBDH@Z)
libcid.lib(_ios.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int,int,char const *,int)" (??2@YAPAXIHPBDH@Z)
libcid.lib(streamb.obj) : error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int,int,char const *,int)" (??2@YAPAXIHPBDH@Z)
Debug/Sensor2.exe : fatal error LNK1120: 2 unresolved externals
Last Post: 09-08-2009, 04:09 PM
By Carson Saunders in forum .NET
Last Post: 06-20-2002, 12:12 PM
By Bruce Casson in forum VB Classic
Last Post: 03-21-2002, 11:51 AM
By Big John in forum VB Classic
Last Post: 02-22-2002, 03:25 PM
By PV in forum VB Classic
Last Post: 05-26-2001, 04:09 PM
Tags for this Thread
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL