K
Konx
Hi everyone.
I'm a newbie of C++ programming, but because of work I have to use it;
the problem is that I don't have the time to learn everything to fully
understand the language, so I hope you can help me with this problem.
I'll try to explain the best I can, but of course, not being an
expert, i is difficult even to explain the problem
Situation: I have a board with an FPGA on it. I can communicate with
the FPGA using a USB2.0 port. The people that gave me the Board, gave
me a SiUSBLib.dll and a SiUSBLib.h file and, according to them, I
should use these files to communicate with the FPGA via the USB port.
Moreover, they sent me a Driver (that I successfully installed).
Always according to their instructions this .dll is "written for the
Borland C++ Builder 6.0, but can be integrated in MSVC applications as
well". This means, for what I understand, that I can use (and I'm in
fact using) Visual C++ 2008 express edition to write my code and use
the .dll.
So, at this point, I should write some kind of code and use the
function of this .dll to work with the FPGA.
Working with a friend, we've reached this point:
in the header file (SiUSBLib.h...I repeat everything to make myself as
clear as possible) there is such a structure:
#ifdef CF__LINUX
#define DECLDIR
#endif
#ifdef __VISUALC__
#ifdef DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#elif USE_STATIC_LIB
#define DECLDIR
#else
#define DECLDIR __declspec(dllimport)
#endif
#endif
I understand that this is done to define, in some way, what kind of
system I'm using, so the header file che load the library. But, for
some kind of reason, this doesn't happen automatically, so we have to
define in our test.cpp file something like this:
#define __VISUALC__
After this, we define this line:
typedef bool DECLDIR (*InitUSBFunc)();
that honestly, is totally unclear to me. It has to do, I suppose, with
something that is written in the header file:
// USB device management functions
bool DECLDIR InitUSB();
int DECLDIR GetNumberOfUSBBoards();
int DECLDIR GetMaxNumberOfUSBBoards();
void DECLDIR * GetUSBDevice(int Id, int DevClass = -1);
void DECLDIR * GetUSBDeviceIndexed(int index);
std::stringstream DECLDIR *GetDevInfoString(int index);
Then, in the main program, we load the library with the following
commands:
HINSTANCE hinstlib; //Handle to DLL.
hinstlib = LoadLibrary(TEXT("SiUSBLib.dll"));
We found these commands surfing the web; I can't say that is totally
clear to me, but I understand that, somehow, this tell to my code:
"load the .dll, so I can use the function implemented in the .dll
itself".
Now, we are sure that the library is loaded because we have a if cycle
(for debug purpose):
InitUSBFunc _initusb;
if (hinstlib != NULL) {
printf("Library successfully LOADED\n");
}
Now, at this point, I would like to use the functions in the .dll, but
I have no idea how to do this; I tried something like:
_initusb = (InitUSBFunc) GetProcAddress(hinstlib, "InitUSB");
Because this is something I've found on the web, but it is not clear
what I'm supposed to obtain with such a statement. Moreover, if I
write something like:
if (_initusb) {
printf("true\n");
} else {
printf("false\n");
}
I always have a "false" (my guess was: I have false if I don't connect
the board, I have true if I connect the board...but it dosen't work).
Just to point out clearly what we have in the header file, there is:
class DECLDIR SiUSBDevice
{
public:
SiUSBDevice(void * dev);
~SiUSBDevice();
// update internal USB device pointer
void SetDeviceHandle(void * dev);
//Then, we have some functions:
// identification values
int GetId();
const char* GetName();
int GetClass();
int GetFWVersion();
//Or other things like:
// FPGA access (via controller core)
bool WriteXilinx (unsigned short address, unsigned char *Data, int
length = 1);
bool ReadXilinx (unsigned short address, unsigned char *Data, int
length = 1);
// FPGA configuration
bool DownloadXilinx(const char *fileName);
..
..
..
..
Now, I understand that maybe the question is really large and open,
but I can't ask nothing more specific than "can you please give some
hints and explanation of what is happening here?". I'm trying to read
a lot of documentation about API, .dll and stuff like this, but the
level is a bit too high for me.
Thank you in advance just for reading through all this stuff
bye
Francesco.
I'm a newbie of C++ programming, but because of work I have to use it;
the problem is that I don't have the time to learn everything to fully
understand the language, so I hope you can help me with this problem.
I'll try to explain the best I can, but of course, not being an
expert, i is difficult even to explain the problem
Situation: I have a board with an FPGA on it. I can communicate with
the FPGA using a USB2.0 port. The people that gave me the Board, gave
me a SiUSBLib.dll and a SiUSBLib.h file and, according to them, I
should use these files to communicate with the FPGA via the USB port.
Moreover, they sent me a Driver (that I successfully installed).
Always according to their instructions this .dll is "written for the
Borland C++ Builder 6.0, but can be integrated in MSVC applications as
well". This means, for what I understand, that I can use (and I'm in
fact using) Visual C++ 2008 express edition to write my code and use
the .dll.
So, at this point, I should write some kind of code and use the
function of this .dll to work with the FPGA.
Working with a friend, we've reached this point:
in the header file (SiUSBLib.h...I repeat everything to make myself as
clear as possible) there is such a structure:
#ifdef CF__LINUX
#define DECLDIR
#endif
#ifdef __VISUALC__
#ifdef DLL_EXPORT
#define DECLDIR __declspec(dllexport)
#elif USE_STATIC_LIB
#define DECLDIR
#else
#define DECLDIR __declspec(dllimport)
#endif
#endif
I understand that this is done to define, in some way, what kind of
system I'm using, so the header file che load the library. But, for
some kind of reason, this doesn't happen automatically, so we have to
define in our test.cpp file something like this:
#define __VISUALC__
After this, we define this line:
typedef bool DECLDIR (*InitUSBFunc)();
that honestly, is totally unclear to me. It has to do, I suppose, with
something that is written in the header file:
// USB device management functions
bool DECLDIR InitUSB();
int DECLDIR GetNumberOfUSBBoards();
int DECLDIR GetMaxNumberOfUSBBoards();
void DECLDIR * GetUSBDevice(int Id, int DevClass = -1);
void DECLDIR * GetUSBDeviceIndexed(int index);
std::stringstream DECLDIR *GetDevInfoString(int index);
Then, in the main program, we load the library with the following
commands:
HINSTANCE hinstlib; //Handle to DLL.
hinstlib = LoadLibrary(TEXT("SiUSBLib.dll"));
We found these commands surfing the web; I can't say that is totally
clear to me, but I understand that, somehow, this tell to my code:
"load the .dll, so I can use the function implemented in the .dll
itself".
Now, we are sure that the library is loaded because we have a if cycle
(for debug purpose):
InitUSBFunc _initusb;
if (hinstlib != NULL) {
printf("Library successfully LOADED\n");
}
Now, at this point, I would like to use the functions in the .dll, but
I have no idea how to do this; I tried something like:
_initusb = (InitUSBFunc) GetProcAddress(hinstlib, "InitUSB");
Because this is something I've found on the web, but it is not clear
what I'm supposed to obtain with such a statement. Moreover, if I
write something like:
if (_initusb) {
printf("true\n");
} else {
printf("false\n");
}
I always have a "false" (my guess was: I have false if I don't connect
the board, I have true if I connect the board...but it dosen't work).
Just to point out clearly what we have in the header file, there is:
class DECLDIR SiUSBDevice
{
public:
SiUSBDevice(void * dev);
~SiUSBDevice();
// update internal USB device pointer
void SetDeviceHandle(void * dev);
//Then, we have some functions:
// identification values
int GetId();
const char* GetName();
int GetClass();
int GetFWVersion();
//Or other things like:
// FPGA access (via controller core)
bool WriteXilinx (unsigned short address, unsigned char *Data, int
length = 1);
bool ReadXilinx (unsigned short address, unsigned char *Data, int
length = 1);
// FPGA configuration
bool DownloadXilinx(const char *fileName);
..
..
..
..
Now, I understand that maybe the question is really large and open,
but I can't ask nothing more specific than "can you please give some
hints and explanation of what is happening here?". I'm trying to read
a lot of documentation about API, .dll and stuff like this, but the
level is a bit too high for me.
Thank you in advance just for reading through all this stuff
bye
Francesco.