-
[RESOLVED] Problem with adding DLL/lib file into VC++ Project
Hi,
I am developing a VC++ MFC SDI Project. I have to use a bunch of functions from a dll/lib which is provided by the hardware provider (I have to use an external usb hardware).
In the source code provided I have a dll file, a lib file, and a folder with a bunch of include (.h ) files.
I first added the dll and lib in the project folder. I added the lib file in the project. and used
extern "C" __declspec(dllimport)
to get the functions in my project, but it did not help. The project compiles properly, but apparently the functions don't do the tricks that they are supposed to do.
Then I added and included the header files provided, and had to remove the dllimport (since it gave error 'overloaded functions' (the header files had declaration of functions). It compiled well, but still the functions don't do the trick.
I don't know what the problem is. It does not give any errors, but the functions don't do what they are supposed to do, when they are called.
I would be really glad if someone could help.
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
guptesanket
I don't know what the problem is. It does not give any errors, but the functions don't do what they are supposed to do, when they are called.
I would be really glad if someone could help.
WEll, there may be at least two reasons when "the functions don't do what they are supposed to do":- the functions were developed/implemented not 100% correctly
- you are using those functions not 100% correctly
-
Re: Problem with adding DLL/lib file into VC++ Project
The dll/lib was provided by the hardware vendor, so there is no way that the functions would be defined incorrectly.
I used the functions exactly as they had used it in their source code, i don't think there is any incorrect syntax.
I think there is some mistake that i did during the connection. Could you just briefly tell me, what are the steps involved for including a dll. The following are the things that I have:
1 dll file
1 lib file
5 header files.
I would be really glad if someone could help me, I cannot move ahead in my work without resolving this issue.
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
guptesanket
... I would be really glad if someone could help me, I cannot move ahead in my work without resolving this issue.
But you didn't provide any useful info about this "issue" except:
Quote:
Originally Posted by
guptesanket
... I don't know what the problem is. It does not give any errors, but the functions don't do what they are supposed to do, when they are called.
I would be really glad if someone could help.
Please, define "don't do what they are supposed to do"
-
Re: Problem with adding DLL/lib file into VC++ Project
Include the header files in the CPP file that uses the API. Link with the lib (add it to your project properties in Linker option: "Input" "Additional Dependencies". Just make sure the dll is in the same directory as the EXE or somewhere in the PATH.
That should be it.
-
Re: Problem with adding DLL/lib file into VC++ Project
Ok I will elaborate. I have to use a Dynamometer to get input into my program.
The hardware vendor have provided me a bunch of files. 1 dll file, 1 lib file, and a few header files. In addition to that there is a source code for a program using all the .h and .cpp files which are actually included into the .dll file. Since the source code is in VC++ 6.0 is does not run in VC++9.0. It gives hundreds of errors.
In a document provided by them, they say that to use the hardware in your own program you need to use the provided dll/lib. Files
I have done all the things as mentioned in my first post. But it does not help.
The functions help in establishing a connection with the hardware. Then collect input in a buffer. But first of all, one of the functions gives a list of all the hardware compatible with that vendor. Currently I get nothing in the list. Leave aside the input in buffer etc.
I have an exe of the program provided by the vendor, which works very well. So there is definitely no problem with the Hardware (Dynamometer).
If it is of any help, (if someone as already used it before) the hardware vendor is 'Vernier' and the files that I have to use are 'GoIO_DLL.dll' 'GoIO_DLL.lib' and other bunch of include files.
Thank you very much in advance. :)
-
Re: Problem with adding DLL/lib file into VC++ Project
Again: could you be so kind to define "don't do what they are supposed to do" ?
-
Re: Problem with adding DLL/lib file into VC++ Project
I am sorry edited the last post and wrote the details. I do not know if it is of any help. But here it is.. again
As of now, the functions that I have used are for,
Getting a list of 'Vernier' hardware.
Establishing a connection to one of the selected hardware from the list.
Start getting input from the selected hardware.
Store the input in a buffer.
Stop input from the hardware.
-
Re: Problem with adding DLL/lib file into VC++ Project
Well, this is my last attempt to understand what your problems are:
what do you mean by "don't do what they are supposed to do" ?
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
hoxsiew
Include the header files in the CPP file that uses the API. Link with the lib (add it to your project properties in Linker option: "Input" "Additional Dependencies". Just make sure the dll is in the same directory as the EXE or somewhere in the PATH.
That should be it.
I am sorry, but i am a bit new to VC++ programming. I have the dll and lib in the program folder. and I have added the lib into the project. But as you mentioned, there is nothing in 'Additional Dependencies'. That field is blank. Could you please tell me what to do in that. When I go in 'Additional Dependencies' it gives a blank text area. What am I supposed to write in there?
Thank you very much.
-
Re: Problem with adding DLL/lib file into VC++ Project
Dear guptesanket!
Don't you understand what I ask? :confused:
Or my English is so bad that you couldn't understand it? Then could you suggest some other language that you'd understand better?
-
Re: Problem with adding DLL/lib file into VC++ Project
I am sorry Mr. VictorN. But i already edited the earlier post and mentioned, that I do not get anything in the list, by the function which is supposed to give me the name of the hardware in the list. And hence it does not move ahead in any other functions. and the tasks of the other functions are as mentioned in my earlier posts.
Thank you
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
guptesanket
I am sorry Mr. VictorN. But i already edited the earlier post and mentioned, that I do not get anything in the list, by the function which is supposed to give me the name of the hardware in the list. And hence it does not move ahead in any other functions. and the tasks of the other functions are as mentioned in my earlier posts.
Thank you
:confused: :confused: :confused:
- Have you added all the #includes?
- Have you implemented the calls of some DLL function?
- Have you added the .lib file in the list of additional libraries/modules?
- Does your project compile?
- Does it link?
- Do you have some errors by executing?
-
Re: Problem with adding DLL/lib file into VC++ Project
1.Yes i have added the include files.
2. ---- I did not understand that---
3.-- I have not done that--.. how do I do that>?
4. Yes, my project compiles
5. Yes, my project links.
6. There are no errors.
It actually executes well.
There is a 'Devices' menu in my project. When I click on the 'Devices', it should give a menu, with a list of all 'plugged in' (Vernier Company) devices. In the menu, I have named 7 devices. If that device is not attached, then, that name in the menu is removed. So, currently i have nothing in the 'Devices' menu.
I would be glad, if you could tell me about point 2 and 3 above.
Thank you.
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
VictorN
:confused: :confused: :confused:
- Have you added all the #includes?
- Have you implemented the calls of some DLL function?
...
Quote:
Originally Posted by
guptesanket
1.Yes i have added the include files.
2. ---- I did not understand that---
Do you call some of the functions exported from a dll of 'Vernier' hardware? Yes or no?
-
Re: Problem with adding DLL/lib file into VC++ Project
I am still not sure what you want to kno, I am sure you are clear, but I am inexperienced. But following could be an answer to your question.
Yes, the dll was provided by Vernier Hardware and they have a detailed documentation of each function in the dll.
Like I mentioned in my very first post. I first used 'extern "C" __declspec(dllimport)' to get the functions. Then I used them in my program normally. But that was without including the header files.
The header already had declarations of the functions. So, after using the headers if i used dllimport, then it gave some error of re-declaration/ function overloading. So I removed the dllimport. I just used the functions normally. like function(arg1,arg2);
I hope this answers your question.
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
guptesanket
I just used the functions normally. like function(arg1,arg2);
I hope this answers your question.
Show your code with such a call of some dll function.
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
VictorN
Show your code with such a call of some dll function.
GOIO_SENSOR_HANDLE CRT_TDoc::OpenDevice(int vendorId, int productId, LPCSTR pDeviceName)
{
CRT_TView *pView = (CRT_TView *)(((CFrameWnd *) AfxGetMainWnd())->GetActiveView());
ASSERT(pView);
char tmpstring[50];
if (m_pDevice)
{
char openDeviceName[GOIO_MAX_SIZE_DEVICE_NAME];
int openVendorId, openProductId;
GoIO_Sensor_GetOpenDeviceName(m_pDevice, openDeviceName, GOIO_MAX_SIZE_DEVICE_NAME, &openVendorId, &openProductId);
if (0 != strcmp(openDeviceName, pDeviceName))
{
//Close the open device if it does not match the new one.
CloseDevice();
}
}
if (!m_pDevice)
m_pDevice = GoIO_Sensor_Open(pDeviceName, vendorId, productId, 0);
if (m_pDevice)
{
unsigned char charId;
GoIO_Sensor_DDSMem_GetSensorNumber(m_pDevice, &charId, 0, 0);
float ftemp[3];
unsigned char calPageIndex;
GoIO_Sensor_DDSMem_GetActiveCalPage(m_pDevice, &calPageIndex);
GoIO_Sensor_DDSMem_GetCalPage(m_pDevice, calPageIndex,
&ftemp[0], &ftemp[1], &ftemp[2], tmpstring, sizeof(tmpstring));
SetMeasurementPeriodInSeconds(GoIO_Sensor_GetMeasurementPeriod(m_pDevice, SKIP_TIMEOUT_MS_DEFAULT));
}
return m_pDevice;
}
Above is my function to open the device. The dll vendor (Vernier) provided functions are the ones which start with GoIO.
Thank you.
-
Re: Problem with adding DLL/lib file into VC++ Project
1. Please, use Code tags while posting code snippets. See Announcement: Before you post....
2. What is the m_pDevice and what is this value when GOIO_SENSOR_HANDLE CRT_TDoc::OpenDevice(...) is called?
Please, set a break point in the begin of this function, then start Debugger (F5), execute this code step by step (F10) and see what happens, the values of variables and so on...
-
Re: Problem with adding DLL/lib file into VC++ Project
m_pDevice is the handle to open the device. It is NULL initially. The function opens the device and the sensor associated with the hardware, and returns the handle to it.( It is supposed to but it doesnt)
I am sure there is no problem with the code, since I am using most of the code as provided in the source code. I am just missing something in the connection. Like you said,
"added the .lib file in the list of additional libraries/modules" or
"Project Properties->Linker->Input->Additional Dependencies"
I do not know what is supposed to be done in the above mentioned things. I would be really glad if you could put some light in that matter.
Thank you
-
Re: Problem with adding DLL/lib file into VC++ Project
Quote:
Originally Posted by
guptesanket
... I am just missing something in the connection. Like you said,
"added the .lib file in the list of additional libraries/modules" or
"Project Properties->Linker->Input->Additional Dependencies"
I do not know what is supposed to be done in the above mentioned things. I would be really glad if you could put some light in that matter.
Thank you
Please, forget this type of problems!
Since your App compiles and links OK, since you don't have any error messages/crashes while executing - all these things seem to be OK.
Please, have a look at the executing. Do it with debug and see whether all the thing are OK or somewhere some error occurs.
What does GoIO_Sensor_DDSMem_GetSensorNumber() return? A valid handle or NULL?
How could you get the reason of an error if it occurs?
-
Re: Problem with adding DLL/lib file into VC++ Project
Hey Mr. VictorN,
Thank you very much for your expert advice. I really appreciate your help and patience. It was really helpful when you said that "Since your App compiles and links OK, since you don't have any error messages/crashes while executing - all these things seem to be OK."
I concentrated on the debugging part, and found a tiny mistake. The sensors are to be initialized before I use them, and apparently the vendor provided me a dll, which did not initialize it in the dll and nor was it mentioned in the source code and documentation.
But thanks a lot for your help.
-
Re: [RESOLVED] Problem with adding DLL/lib file into VC++ Project
Hi,
For me it seems that the problem is not with #include and dlls and libs; it is with connections. E.g. if you scan the external devices, your functions are sending requests to external devices and the devices can't understand them or they replay and your program does not understand the replays. Did you check the communication protocols?