I have been working on updating a program that was written by someone else in Microsoft Visual C++ 6.0 to Microsoft Visual .NET 2003 (7.1 compiler). After fixing all of the minor syntax errors I came accross one that I wasn't real sure about:
c:\DFC\dfc\source\DFCTfo.hpp(422): error C2491: 'DAssociationFile<KEY,VALUE>::getNextAssociation' : definition of dllimport function not allowed
When someone else was having this exact error he corrected it by moving the function definition to be right next to the declaration (inlining I believe is the proper word). He said he never got another error after that. I wasn't as lucky. After I moved the definitions of all of the functions in this class, I got more errors. The only 2 that no longer gave me errors were one virtual function and the function that was immediately next in the class definition. The other functions, including the constructor and destructor (which was virtual), all gave me an error saying this:
DFCDev error LNK2019: unresolved external symbol "__declspec(dllimport) public: bool __thiscall DAssociationFile<class DDeviceKey,class DDeviceValue>::getNextAssociation(class DDeviceKey &,class DDeviceValue &)" (__imp_?getNextAssociation@?$DAssociationFile@VDDeviceKey@@VDDeviceValue@@@@QAE_NAAVDDeviceKey@@AAVDDeviceValue@@@Z) referenced in function "public: virtual void __thiscall DDeviceAssociation::reload(void)" (?reload@DDeviceAssociation@@UAEXXZ)
Immediately followed by 2 of these errors:
DFCDev error LNK2001: unresolved external symbol "__declspec(dllimport) public: bool __thiscall DAssociationFile<class DDeviceKey,class DDeviceValue>::getNextAssociation(class DDeviceKey &,class DDeviceValue &)" (__imp_?getNextAssociation@?$DAssociationFile@VDDeviceKey@@VDDeviceValue@@@@QAE_NAAVDDeviceKey@@AAVDDeviceValue@@@Z)
After studying these errors and the .NET help files I tried a couple different things. The first was checking for spelling mistakes. Second, I checked to make sure my braces all lined up properly. Third, I replaced the file with the original about 3 times and moved the definitions over and over, double and triple checking my spelling. Having had these fail I moved on. The next thing I read up on was dllimports and dllexports. Being a student I haven't encountered anything like this before. So, after reading I thought I'd try a few more things. First, I made the rest of the functions virtual, this removed the unresolved externals. It obviously didn't work on the constructor, since it can't be declared anything but inline, it also didn't work on the destructor. I didn't like this method so I followed another path. I used the DAssociationFile class as basically a pointer to a DAssociationFileImp class because another class that it was derived from did this. Following the path laid out for me by the other class I used a pointer to accomplish all of the goals that were necessary. I thought it was a good idea but it didn't help anything, I still got the link errors.
Here is one of the function declarations, along with it's definition header and the function call that is bringing up the error.
Declaration: bool getNextAssociation(KEY &key, VALUE &value);
Definition: template<class KEY, class VALUE>
bool DAssociationFile<KEY, VALUE>::getNextAssociation(KEY & key, VALUE &value){
Function Call: while (associationFile.getNextAssociation(association.key, association.value))
Since I did not write the code I'm not entirely sure how it is supposed to work, but here is the code maybe you can decipher more than me. I think it is actually supposed to be exporting to a dll and not importing until later. What is confusing is the following set of code, from the very beginning of the hpp file:
#if !defined DTEXTFILE_CLASS
#define DTEXTFILE_CLASS
#include <stdio.h>
#include <strstream>
#if defined __IBMCPP__
#define TFO_Export
#endif
#if defined _WINDOWS
#ifndef __DTEXTFILE__
#define TFO_Export __declspec(dllimport)
#else
#define TFO_Export __declspec(dllexport)
#endif
#endif
I think that DTEXTFILE is always defined because it is in the cpp file, but I'm not sure. I think if this were supposed to be an export file it would be fine. But I just don't know why it would compile correctly in 6.0 and not 7.1. Thanks for the help file but that really doesn't do a whole lot it just says to not declare it as a dllimport, but it needs to be. Any other suggestions?
Any help that you guys can find for me would be greatly appreciated.