I am attempting to convert some applications from Borland C++ builder to
Visual C++ .NET. Almost all of the applications use DLLs to interface to
some special hardware. Below is some code I use to load the DLLs at
runtime. It doesn't work in VC.NET, starting with the HANDLE. A quick
look at the help didn't turn up anything useful...
Can anyone please give me a quick start? Is it even possible to a Win32
DLL with .NET?
I really get tired of reading pages and pages of help text that really says
nothing.
HANDLE hlib; // DLL handle used by LoadLibrary and FreeLibrary
....
void __fastcall TFormMain::FormCreate(TObject *Sender)
{
// load the DLL into memory
hlib = LoadLibrary("HAI_NetLib.DLL");
if (hlib)
{
// set the address of each of the function variables to the address of
the
// exported functions in the DLL, complain and abort if not found...
OmniConnect = (pOmniConnect)GetProcAddress(hlib,"_OmniConnect");
if (!OmniConnect)
{
MessageBox(NULL, "ERROR: Unable to resolve OmniConnect in DLL!",
"ERROR", (MB_ICONERROR + MB_OK));
Application->Terminate();
}
...
OmniVersion = (pOmniVersion)GetProcAddress(hlib,"_OmniVersion");
if (!OmniVersion)
{
MessageBox(NULL, "ERROR: Unable to resolve OmniVersion in DLL!",
"ERROR", (MB_ICONERROR + MB_OK));
Application->Terminate();
}
}
}
....
void __fastcall TFormMain::FormDestroy(TObject *Sender)
{
// unload the DLL on the way out
if (hlib)
FreeLibrary(hlib);
}