tags:

views:

901

answers:

2

This might be a little QT specific, but here we go...

I've got a QT app that I need to interface with a couple of external libraries written in C. Everything seems to be working, as I can link correctly, but when I try and call any function in one of the libraries I always get an access violation error. For the other library, I call like 10 functions in my process, but the 11th one gives me the same thing. I'll give the specifics for the first one here since I think it should be more obvious what's wrong.

The library comes with a .lib, .h, and installs a .dll to system32. Here's a function declaration from the .h: __declspec(dllimport) unsigned short InPortB(unsigned long Port);

The library comes with a digital IO card that you use this function to write data to. Port is the address of the card. I know that the address is 0xdeb0 and I can verify that writing to this address is valid because the sample code I got with the card does that without errors. The sample code I get is a C++ VS2005 solution. I can build it and everything is fine. When I try and copy the sample code into my QT app, I get the access violation.

So, I first thought there was a mismatch with calling conventions, but I don't see how the application would link if that was the case.

I just looked at my app's exe in depends and it's a little strange. It looks like my application isn't actually calling any of the functions in the external library. Also, when I view the debug output from the windows error message, I don't see the DLL loaded anywhere.

Do I have to manually load a dll? I don't have to do anything about the dll when running the visual studio project, so that doesn't make sense to me. I'm pretty lost here.

A: 

Sorry, but it won't let me comment on the last comment.

Yes, I did run it under the debugger, but I don't really get any more information. The access violation happens immediately on my call to InPortB. In the debugger the only things in the call stack are my exe and then 0x0001bbcc(), which is the address of the function I'm trying to call, or at least that's the address that I get when I do something like cout << InPortB

Use the same login you used to create the question (you are using IDs 130799 and 131093 here; see http://stackoverflow.com/questions/53598 for how to merge your two accounts). Even if you don't have enough reputation to comment, you can edit the original question in response.
ephemient
Then I doubt it is something related to Qt. You might want to create a simpler, e.g. pure minimalistic C++, test program first based on the given sample code, then grow it slowly to reach the targeted module.
Ariya Hidayat
Yes, I think that's true. I've somewhat narrowed the problem down in that I can successfully call the functions I'm interested in if I build my project with VS2005. This seems to indicate to me that either there is a calling convention mismatch or that the VS runtime is doing something that I'm not aware of. I'll try building some generic code and compile with gcc and cl and see what happens.
A: 

Check that the other library is built against the same runtime as Qt and your app (debug/release, mainly).