From: Faraz on
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
From: ScottMcP [MVP] on
On Feb 2, 11:32 am, 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.
>
> regards,
> Faraz

You said the company has provided you with a DLL, but you seem to be
asking how to make a DLL. Do you really mean to ask how to use a DLL?

To use a DLL you must #include the provided .h file and you must add
the name of the provided .lib file into your project's linker settings
(at 'Additional Dependencies'). Then you can call functions in the
DLL. When you run the program make sure the provided DLL is in the
same directory as your program.


From: Ulrich Eckhardt on
Faraz wrote:
> The sensor [...] 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.

So far, that is common.

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

Some steps:
1. Create a new VC project for C or C++.
2. Add "#include <sensor_header.h>" in a source file. You might have to
tweak the path where the compiler searches for include files or move the
file so it gets found.
3. Add "#pragma comment(lib, "sensor_library.lib")" in a source file. You
might have to tweak the path where the linker searches for libraries or
move the lib file so it gets found.
4. Add "&MTCSGetADCAVR2;" in a function in a source file. This just takes
the address of a function of the library for testing, so the DLL must be
present for that. You might have to move the DLL so it gets found, see the
documentation for LoadLibrary() at http://msdn.microsoft.com.

After each step, verify that your project still compiles, links and runs
correctly. If you're through, you have a working setup capable of using the
functions declared in the header.

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

You don't want to create a DLL but use the one you already got. ;)

Uli

--
Sator Laser GmbH
Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932

From: r_z_aret on
On Tue, 2 Feb 2010 08:32:06 -0800 (PST), Faraz <farashes(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 02116
www.penfact.com
Useful reading (be sure to read its disclaimer first):
http://catb.org/~esr/faqs/smart-questions.html
From: Faraz on
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