1

Can anybody translate the following code to C++? Is this possible at all or are there vital information missing?

Dim Laser As Object
Sub EnableLaser
    ‘ Create a laser object if it hasn’t been done yet
    If Laser Is Nothing Then
       Set Laser = CreateObject("NWLaserXControl.NWLaserX")
    End If
    If Laser.Initialize Then
       Laser.RepRate = 10 ‘ set the rep rate to 10Hz
       Laser.LaserEnabled = True ‘ turn on laser power supply, get it ready
    End If
End Sub

1 Answer 1

1
// if (CoInitialize(0) == S_OK)
{
    CComPtr<INWLaserX> pMyPtr = NULL;

    CLSID clsid = IID_NULL;
    CLSIDFromProgID("NWLaserXControl.NWLaserX");

    if (pMyPtr.CoCreateInstance(clsid) == S_OK)
    {
         pMyPtr->put_RepRate(10);
         pMyPtr->put_LaserEnabled(TRUE);
    }

   // CoUnInitialize();
}
Sign up to request clarification or add additional context in comments.

3 Comments

@Vinay: +1, but it should be mentioned that you probably don't need to call CoInitialize every time. Once on app startup, and once on teardown (if you have one apartment) is fine.
You can get the CLSID using CLSIDFromProgId.
It'll be cleaner to replace "TRUE" with "VARIANT_TRUE".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.