Importing COM Components
Many of the COM components that companies develop are not ActiveX Controls; they are standard COM dynamic link library (DLL ) files . To see how to use these with .NET, return to VB6 and create a COM business object that will act exactly as the component from the previous section did.
Tip
Once again, if you don't have VB6, you can download the DLL as explained earlier.
The first step is to create a new ActiveX DLL project. This is how VB6 creates standard COM DLLs. Name the class ComCalc and name the project ComCalculator. Save the file and project. Copy the methods from Example 7-1 (shown here for your convenience in Example 7-3) into the code window.
Example 7-3. Methods for VB6 COM DLL ComCalc
Public Function _
Add(left As Double, right As Double) _
As Double
Add = left + right
End Function
Public Function _
Subtract(left As Double, right As Double) _
As Double
Subtract = left - right
End Function
Public Function _
Multiply(left As Double, right As Double) _
As Double
Multiply = left * right
End Function
Public Function _
Divide(left As Double, right As Double) _
As Double
Divide = left / right
End FunctionIntegrating the COM DLL into .NET
Create a new form called frmCOMDLL. Add a menu choice to the Fun menu on the Welcome form that invokes that form.
Now that you have created the ComCalc DLL, you can import it into .NET. Before you can import it, however, you must choose between early and late binding. When the client calls a method on the server, the address ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access