Using it with VB
Create a new VB project and add a button to it. From the menu, choose project->references and pick our component:
Press OK and you are ready to use the library in our sample VB project. Within the button-code add the following code:
- Dim oMyObject As New MyObject
- MsgBox Format(oMyObject.Calculate(2, 5000000))
we are ready with this tutorial. Try the Sample (check the link at the
button). In the sample, I have implemented the same functionality in
VC++ and in VB. Compare the speed of both version. But try it more than
once, because our VC is loaded for the first time into memory. This
will cause our first execution a littlebit slower. Remember, that this
calculation is pretty uncomplex. You can get a lot more out of it.
hope this tutorial will help you develope VC++ COM-objects for VB. If
you have any question about using other data-types than "long", ask me
or take a look at msdn online or the VC++ online manual (OLE types).
- Debugging our component with VC++
How can I debug this object if
it is used from VB? This is easy: Make an executeable (project1.exe)
from your VB project. In VC++ set the compile option from "Win 32 -
Release MinSize" to "Win 32 - Debug".
Specify the VB project.exe as executeable for the debug session and set
a breakpoint in your code. Now press "F5" to "run" your component.
After that the VB application is started and if you reach the
breakpoint the VC++ debugger will stop at the C++ code. That's it.
Download the source: You can download the source of the tutorial here