registering
Programmer
Hi all,
I'm using VC++ 6.0 to try and explicitly load a DLL. However no
matter what I've tried GetProcessAddress() always returns NULL.
LoadLibrary works fine (not NULL anyway). I've checked the exported
name from the DLL via 'depends.exe' and it's not mangled: it shows
the same name ("fnTestDLL").
I've googled for a couple of hours with no luck, so I'm
out of ideas. Maybe it's my project settings? I've tried
including the testdll.lib in "Link", the testdll.h in testp.app
and the DLL in "Debug" all with no luck.
I've dumbed-down my code to the basics and still can't get it
to work.
Any help would be greatly appreciated!!
------------------------------------------------------------
This is my App's "testapp.cpp" that (tries to) call my DLL:
------------------------------------------------------------
----------------------------------------
This is my DLL's "testdll.cpp":
----------------------------------------
-----------------------------------------------------
This is the DLL's "testdll.h":
-----------------------------------------------------
I'm using VC++ 6.0 to try and explicitly load a DLL. However no
matter what I've tried GetProcessAddress() always returns NULL.
LoadLibrary works fine (not NULL anyway). I've checked the exported
name from the DLL via 'depends.exe' and it's not mangled: it shows
the same name ("fnTestDLL").
I've googled for a couple of hours with no luck, so I'm
out of ideas. Maybe it's my project settings? I've tried
including the testdll.lib in "Link", the testdll.h in testp.app
and the DLL in "Debug" all with no luck.
I've dumbed-down my code to the basics and still can't get it
to work.
Any help would be greatly appreciated!!
------------------------------------------------------------
This is my App's "testapp.cpp" that (tries to) call my DLL:
------------------------------------------------------------
Code:
#include "stdafx.h"
#include "testapp.h"
#ifdef _DEBUG_
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CWinApp theApp;
using namespace std;
typedef int (CALLBACK* LPFNDLLFUNC1)();
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{ .............. }
LPFNDLLFUNC1 LibMainEntryPoint;
HINSTANCE LoadMe = LoadLibrary("c:\\code\\begin\\testdll\\debug\\testdll.dll");
if (LoadMe == NULL)
{ ............. }
LibMainEntryPoint = (LPFNDLLFUNC1) GetProcAddress(LoadMe, "fnTestDLL");
if (LibMainEntryPoint == NULL)
[b] { ....ALWAYS FAILS HERE!!!...........} [/b]
LibMainEntryPoint();
FreeLibrary(LoadMe);
return (0);
}
This is my DLL's "testdll.cpp":
----------------------------------------
Code:
#include "stdafx.h"
#include "testdll.h"
using namespace std;
BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason, LPVOID lpreserved)
{
switch (ul_reason):
{
default: break;
}
return (TRUE);
}
TESTDLL_API int nTestDLL = 0;
TESTDLL_API int fnTestDLL(void)
{
return (42);
}
CTestDLL::CTestDLL()
{
cerr << "constructed";
}
CTestDLL::~CTestDLL()
{
cerr << "destructed";
}
This is the DLL's "testdll.h":
-----------------------------------------------------
Code:
#ifdef TESTDLL_EXPORTS
#define TESTDLL_API __declspec(dllexport)
#else
#define TESTDLL_API __declspec(dllimport)
#endif
class TESTDLL_API CTestDLL
{
public: CTestDLL(void);
~CTestDLL(void);
};
extern TESTDLL_API int nTestDLL;
TESTDLL_API int fnTestDLL(void);