471,337 Members | 1,198 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

How to use a DLL in .NET?

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);
}

Jul 21 '05 #1
0 929

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.