Hi all,
I'm porting some project from mingw to MSVC. I managed to get everything to compile and link, but one problem remains: from the main application i have to load some DLL at run time and get the address of a function from it.
This is my loader code (taken from MSDN):
Code:
#include <string>
#include <iostream>
#include <windows.h>
int main()
{
typedef const std::pair<const int, const std::string> (*LPFNDLLFUNC1)();
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
DWORD dwParam1;
UINT uParam2, uReturnVal;
hDLL = LoadLibrary("FennekEntity");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL, "getUserType");
if (!lpfnDllFunc1)
{
// handle the error
FreeLibrary(hDLL);
std::cout << "getadd error" << std::endl;
}
else
{
// call the function
//uReturnVal = lpfnDllFunc1(dwParam1, uParam2);
}
}
else
{
std::cout << "loadlib error" << std::endl;
}
return 0;
}
And this is the code inside the DLL:
Code:
// FennekEntity.h
#ifdef FENNEKENTITY_EXPORTS
#define FENNEKENTITY_API __declspec(dllexport)
#else
#define FENNEKENTITY_API __declspec(dllimport)
#endif
#ifndef FENNEKENTITY_H_
#define FENNEKENTITY_H_
[...]
FENNEKENTITY_API const std::pair<const int, const std::string> getUserType();
#endif /*FENNEKENTITY_H_*/
// FennekEntity.cpp
#include "FennekEntity.h"
[...]
//extern "C"
//{
FENNEKENTITY_API const std::pair<const int, const string> getUserType()
{
[...]
}
//} // extern "C"
Does anybody has an idea, why getProcAddress always returns NULL? Using mingw it works (if I comment in the extern "C"). MSVC compains what an extern "C" declared function can't return non-pod data types, so I took it out.
Thank you in advance!