I have quite novice to DLL programming.
I have created a DLL project as,
In DLL project SimpleH.h
namespace ME{
class base
{
public:
static __declspec(dllexport) void Hello();
};
}
__declspec(dllexport) void HelloWorld();
DLL.cpp
#include "stdafx.h"
#include <iostream>
#include "SimpleH.h"
using namespace std;
namespace ME
{
void base::Hello()
{
cout << "Hello World\n";
}
}
void HelloWorld()
{
cout << "Hello I am world\n";
}
I have created an .exe
.
Main.exe
#include "stdafx.h"
#include <stdlib.h>
#include <Windows.h>
#include <iostream>
using namespace std;
typedef void (*FunctionFunc)();
typedef void (*FunctionAno)();
int _tmain(int argc, _TCHAR* argv[])
{
FunctionFunc _FunctionFunc;
FunctionAno _FunctionAno;
HINSTANCE hInstLibrary = LoadLibrary(L"MyDLL.dll");
if(hInstLibrary)
{
/*Problem Happens here*/
_FunctionFunc = (FunctionFunc)GetProcAddress(hInstLibrary, "Hello");
_FunctionAno = (FunctionFunc)GetProcAddress(hInstLibrary, "HelloWorld");
/**/
if(_FunctionFunc)
{
_FunctionFunc();
}
if(_FunctionAno)
{
_FunctionAno();
}
DWORD error = ::GetLastError();
if (error)
{
LPVOID lpMsgBuf;
LPVOID lpDisplayBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
error,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
}
}
FreeLibrary(hInstLibrary);
system("pause");
return 0;
}
hInstance is getting updated properly.
But the GetProcAddress()
are not getting updated.
Please help me.
Where is it going wrong?