Calling functions from sensors dll c++


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 12 of 12

Thread: Calling functions from sensors dll c++

Hybrid View

  1. #1
    Join Date
    Feb 2010
    Posts
    6

    Unhappy Calling functions from sensors dll c++

    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.

    regards,
    Faraz

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    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.
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

  3. #3
    Join Date
    Dec 2003
    Posts
    3,366
    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..).

  4. #4
    Join Date
    Feb 2010
    Posts
    6
    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


    #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. I was wondering if one of you could suggest that where the problem lies.
    regards

  5. #5
    Join Date
    Dec 2003
    Posts
    3,366
    this isnt it, but, use:
    <iostream>
    using namespace std;

    and also:
    int main ()
    {
    return 0;
    }

    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,
    OR
    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.

  6. #6
    Join Date
    Feb 2010
    Posts
    6
    Dear jonnin,

    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

Similar Threads

  1. calling a VB dll from C++
    By BigCTD in forum C++
    Replies: 2
    Last Post: 09-08-2009, 05:09 PM
  2. Calling Dll Functions from C#
    By Carson Saunders in forum .NET
    Replies: 0
    Last Post: 06-20-2002, 01:12 PM
  3. Calling a DLL from COM+ ActiveX DLL
    By Bruce Casson in forum VB Classic
    Replies: 1
    Last Post: 03-21-2002, 12:51 PM
  4. Calling a DLL
    By Big John in forum VB Classic
    Replies: 3
    Last Post: 02-22-2002, 04:25 PM
  5. Replies: 16
    Last Post: 05-26-2001, 05:09 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center