Consuming a DLL in Visual Basic

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Okay, I have this DLL provided by a vendor. I believe that it was written in
Visual C++ 6.0 (Visual Studio 6.0). Can I consume it in my app? And if so
how. Pointing me to an article or tutorial would be fine. If you need more
info, please ask. I'm not sure where to start here.
 
PS. I do have C++ source code that uses this, but I don't know C++ that well.
I'm pretty good with VB .Net though.
 
M K said:
Okay, I have this DLL provided by a vendor. I believe that it was written
in
Visual C++ 6.0 (Visual Studio 6.0). Can I consume it in my app? And if so
how. Pointing me to an article or tutorial would be fine. If you need more
info, please ask. I'm not sure where to start here.

If it's a COM dll, then just set a project reference to its type library
(.tlb or .dll). If it's not a COM dll then you need the header file to find
the definition of the exports and use PInvoke.

Here's your starting point:

http://msdn.microsoft.com/library/d...html/cpconInteroperatingWithUnmanagedCode.asp

David
 
Could you help me to understand what they mean when they say:
Note Win32 API functions that allocate a string enable you to free the
string by using a method such as LocalFree. Platform invoke handles such
parameters differently. For platform invoke calls, make the parameter an
IntPtr type instead of a String type. Use methods provided by the
System.Runtime.InteropServices.Marshal class to convert the type to a string
manually and free it manually.

http://msdn.microsoft.com/library/d.../html/cpconconsumingunmanageddllfunctions.asp
 
M K said:
Could you help me to understand what they mean when they say:
Note Win32 API functions that allocate a string enable you to free the
string by using a method such as LocalFree. Platform invoke handles such
parameters differently. For platform invoke calls, make the parameter an
IntPtr type instead of a String type. Use methods provided by the
System.Runtime.InteropServices.Marshal class to convert the type to a
string
manually and free it manually.

http://msdn.microsoft.com/library/d.../html/cpconconsumingunmanageddllfunctions.asp

This is all about who allocates the memory and who cleans it up for strings
used as output parameters.

When an unmanaged DLL function has an output parameter of variable length
it's a dilemma. In .NET and in COM this is no problem. COM is
reference-counted and .NET is garbage collected. So a method can pass a
newly allocated object back to a caller without creating a memory leak.

In C and C++ this can't be done. So either
1) the caller allocates the memory and the caller cleans it up
or
2) the callee allocates the memory and the caller cleans it up

1) is by far the most common, but there are a few functions where the caller
is required to clean up memory allocated inside the function. These should
be clearly documented as requiring the caller to free the memory after using
it.

David
 
Back
Top