I have been trying to use the freeware (dll) version of Qcard32 in visual c++6 on a single document program. I cannot get the functions to work or complie properly. I have been reading about using the __declspec (dllexport) and __declspec(dllimport) keywords

I feel that if I can get the program to work with one of the functions that I should be able to use the rest. I have never tried to use an external function in visual c++ and the blogs I have seen seem confusing. The qcard 32 dll comes with a .lib file for use in c++.
I found this page on the web
DLL Lab
Creating and using Win32 *.DLL files By Chris Satterthwaite
which gives a pretty good discription but is not clear in some respects.
I tried his program but it wouldn't compile.

PROBLEM 1:
I'm confused about using the __declspec (dllexport) keyword. He talks about using it in the dll program itself and then he talks about using it in the function Call. Where do you use it???? Do you use it in the exe or the dll?
Microsoft says the __declspec (dllimport) keyword is not necessary but makes the code more efficient. Microsoft doesn't give you a clue about where to put these commands either.

PROBLEM 2:
the instructions are not clear about which files to include in the exe program that utilizes the dll functions. It talks about linking to the file but it doesn't explain which files to link (the dll or the lib or both) I also copied the contents of Qcard32.h to a new(Qcard32.h) file I created for the project. This file declares the dll functions.

PROBLEM 3:
One more problem with the Qcard32 functions is that they ask for a HWND (window handle). I don't know how to obtain this information and place it in an acceptable format for the function to utilize.

Problem 1: __declspec (dllexport) is only used in the dll to identify those functions or c++ classes that need to be visible to the outside world (i.e. application program or other dlls.). use __declspec (dllimport) in the function prototype in application programs.

int __declspec (dllimport)  foo(); // function prototype

int main()
{
   foo();
}

Problem 2: DLLs normally (but not always) come with a .lib file -- link with the .lib file if you use __declspec (dllimport) shown above. There is an alternative called "dynamic linking" which does not link to a library at all, but used LoadLibrary() to load the DLL into memory.

Problem 3: If you are writing a wn32 program you should already have the HWND of the window the program created. If, however, you are writng a console program, then you can use GetConsoleWindow(), which returns the HWND of the console window. If your program does not even have a console window, then you are SOL. Note: VC++ 6.0 has a bug -- GetConsoleWindow() is undefined in the header file -- either prototype it yourself or download the Windows Platform SDK, which contains the correction. It is ok in Dev-C++ too.

Thanks for quick responce
for Q 1 and 2 Thanks thats what it looked like to me.
for q 3 I am using vc++6 IDE to write single doc program (exe)
with one window. I don't know what the window handle is or how to access the info? Microsoft thinks I should allready know this too, but I don't.

are you using MFC? If you are, then the every window has an m_hWnd object, which is the HWND you need.

CMyWindow::MyFunction()
{
    SomeQcard32Function(m_hWnd, /* other parameters here */);
}

If you are writing pure win32 api then CreateWindow() or CreateWindowEx() returns the HWND.

thanks again
How come those people in Redmond Washington did't think of writing that
in their HWND description?

are you using MFC? If you are, then the every window has an m_hWnd object, which is the HWND you need.

CMyWindow::MyFunction()
{
    SomeQcard32Function(m_hWnd, /* other parameters here */);
}

If you are writing pure win32 api then CreateWindow() or CreateWindowEx() returns the HWND.

thanks again
How come those people in Redmond Washington did't think of writing that
in their HWND description?

They did tell you -- if you look in the right place. It's just normal c++ inheritance -- the average learning curve to get everything straight in your head is about one year. :eek: So don't feel too bad if you are lost at first -- we all are.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.