How to use templates in dll?
I have the following code in a dll:
umath.h#ifndef __UMATH_H__
#define __UMATH_H__
#include <Common.h> //my common file...
namespace nsUMath
{
class __DLL_SPEC_ UMath
{
public:
template<typename T>
static T mod(T x, T y) throw();
private:
UMath(void); //Default constructor.
UMath(const UMath&); //Copy constructor.
UMath& operator=(const UMath&); //Assignment operator.
};
}
//
extern "C"
{
__DLL_SPEC_ double mod(double x, double y) throw();
}
#endif
umath.cpp #define __COMPILING_DLL_ //Use in common.h to compile to dll. #include "UMath.h" //using namespace std; using namespace nsUMath; template<typename T> T UMath::mod(T x, T y) throw() { return(x - y * floor(x / y)); } double UMath::mod<double>(double x, double y) throw(); main.cpp ...
m_hModMath = ::LoadLibraryEx(_t("Mathematics.dll"), NULL, 0); if (m_hModMath == NULL) ThrowException(::GetLastError(), __LINE__); // //Retrieving the address of the exported functions. // m_mod = reinterpret_cast<double (*)(double, double) throw()> (::GetProcAddress(m_hModMath, _t("mod"))); if (m_mod == NULL) ThrowException(::GetLastError(), __LINE__); -
The dll code compile and link OK; however, the problem is with code in main.cpp. The GetProcAddress function returns NULL for the address "mod." Does anybody know what am I doing wrong here.

