DeepButi
April 21st, 2004, 04:30 AM
A non-NET dll can be used with LoadLibrary and GetProcAddress:
typedef int (*MYPROC)(int);
int _tmain(void)
{
HMODULE hmod;
MYPROC ProcAdd;
int i;
CString txt;
hmod=LoadLibrary("MyC++DLL");
if (hmod != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hmod, "MyFunc");
if (NULL != ProcAdd)
{
i=(ProcAdd) (1);
txt.Format("VC++ MyFunc returns %d",i);
Console::WriteLine(txt);
}
FreeLibrary(hmod);
}
return 0;
}
A NET dll can be used as a class
#using "MyNETDLL.dll"
using namespace MyNETDLL;
int _tmain(void)
{
int i;
CString txt;
NetClass *NetObject;
NetObject = new NetClass;
i=NetObject->MyFunc(1);
txt.Format("NET MyFunc returns %d",i);
Console::WriteLine(txt);
return 0;
}
Using a NET dll as shown requires knowledge of the dll name and function at compile time, whereas LoadLibrary/GetProcAdress allows you to decide dll and func name at run time.
So, ... is there any way to build a NET dll that allows LoadLibrary/GetProcAddress to be used?
Following some suggestions I gave it a strong name, registered it for COM interop and registered it in the Global Assembly Cache, but nothing works.
Since NET dlls rely on CRT and MSIL, don't have external entry points so GetProcAdress can not find the adress at run time, but to guarantee compatibility with "old" programming some method should exist ... or perhaps it doesn't :rolleyes:
Any ideas?
Thanks
typedef int (*MYPROC)(int);
int _tmain(void)
{
HMODULE hmod;
MYPROC ProcAdd;
int i;
CString txt;
hmod=LoadLibrary("MyC++DLL");
if (hmod != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hmod, "MyFunc");
if (NULL != ProcAdd)
{
i=(ProcAdd) (1);
txt.Format("VC++ MyFunc returns %d",i);
Console::WriteLine(txt);
}
FreeLibrary(hmod);
}
return 0;
}
A NET dll can be used as a class
#using "MyNETDLL.dll"
using namespace MyNETDLL;
int _tmain(void)
{
int i;
CString txt;
NetClass *NetObject;
NetObject = new NetClass;
i=NetObject->MyFunc(1);
txt.Format("NET MyFunc returns %d",i);
Console::WriteLine(txt);
return 0;
}
Using a NET dll as shown requires knowledge of the dll name and function at compile time, whereas LoadLibrary/GetProcAdress allows you to decide dll and func name at run time.
So, ... is there any way to build a NET dll that allows LoadLibrary/GetProcAddress to be used?
Following some suggestions I gave it a strong name, registered it for COM interop and registered it in the Global Assembly Cache, but nothing works.
Since NET dlls rely on CRT and MSIL, don't have external entry points so GetProcAdress can not find the adress at run time, but to guarantee compatibility with "old" programming some method should exist ... or perhaps it doesn't :rolleyes:
Any ideas?
Thanks