I created DLL that it includes Bryan() function, but
Bryan2() function is defined outside DLL so function
pointer is created. I tried to tell DLL that function
pointer should be declared, but not defined. The problem
is that error linkage message says unresolved linkage to
function pointer so I decided to define it by adding zero.
Bryan2() function is defined in EXE's source code.
main() function is able to access pBryan() to retreive
memory address inside DLL. I attempt to duplicate
Bryan2() function into pBryan(), but it seems that EXE
can't link to pBryan() in DLL.
I believe that it may be two duplicated pBryan().
One is in DLL. Another is in EXE.
If you run, you will get error exception message,
it is because pBryan() inside DLL is never modified
that it is always equals to zero.
I want all unmodified functions in DLL while they
can be linked to modified functions in EXE. Please
take a look at my code below so it gives you your idea.
Please explain what is __declspec(dllimport). I
believe that it is only declaration. Should I use it
in EXE source code while __declspec(dllexport) is
always used in DLL.
/* Header for DLL */
#ifndef _DLLTEST_H_
#define _DLLTEST_H_
extern "C" __declspec(dllexport) void Bryan();
extern "C" __declspec(dllexport) void (*pBryan)(void) = 0;
#endif
/* Source Code for DLL */
#include "dlltest.h"
extern "C" __declspec(dllexport) void Bryan()
{
printf("Hello, this is Bryan.\n");
pBryan();
}
/* Source Code for EXE */
#include "dlltest.h"
void Bryan2()
{
printf("Hello, this is Jon.\n");
}
void main()
{
void (*pBryan)(void) = Bryan2;
Bryan();
}