At 12/4/2003 01:01 PM, Jason Teagle wrote:
 
>So based on the name MyControl.tlb, what class should I be declaring my
>objects as? The ClassWizard method gives me something derived from
>COleDispatchDriver, which allows me to use AttachDispatch() to connect an
>IDispatch to (some members may remember a question from a while back about
>one control using another).
>
>If I could just figure out how to use #import's results properly I think I'd
>be onto a winner.

I am not an expert on this, but it has always seemed very complex to me.

Here is some sample code.

The import statement:

#import "LandAuto.tlb" no_namespace

A function that uses this import tlb:

AeciUtils::CogoPointCode AeciUtils::getCogoPoint3 (int nCogoPt, AcGePoint3d& pt3dPoint)
{
   
// find the running instance of AutoCAD
    HRESULT result;
   
IUnknownPtr spUnknown;
   
result = GetActiveObject(__uuidof(AcadApplication), NULL, &spUnknown);
   
if (FAILED(result)) {
       
return kNoLddt;
    }

   
// get interface for AcadApplication
    IAcadApplicationPtr spAcadApp;
   
result = spUnknown->QueryInterface(__uuidof(IAcadApplication), (LPVOID*) &spAcadApp);
   
if (FAILED(result)) {
       
return kNoLddt;
    }

   
try {
       
// get AeccApplication object
        IDispatchPtr spDisp = spAcadApp->GetInterfaceObject("Aecc.Application");

       
// get AeccApplication interface
        IAeccApplicationPtr spAeccApp;
       
result = spDisp->QueryInterface(__uuidof(IAeccApplication), (LPVOID*) &spAeccApp);
       
if (FAILED(result)) {
           
return kNoLddt;
        }

       
// active project
        IAeccProjectPtr spProj = spAeccApp->GetActiveProject();

       
// points interface
        IAeccCogoPointsPtr spPoints = spProj->GetCogoPoints();

       
// cogo point
        IAeccCogoPointPtr spPoint;
       
try {
           
spPoint = spPoints->PointByNumber(nCogoPt);
        }
       
catch (_com_error ComError) {
           
return kNoLddt;
        }
       
pt3dPoint.x = spPoint->GetEasting();
       
pt3dPoint.y = spPoint->GetNorthing();
       
pt3dPoint.z = 0;
    }

   
// Exception thrown
    catch (_com_error ComError) {
       
return kNoLddt;
    }
   
return kSuccess;
}



Phil Daley          < AutoDesk >
http://personal.monad.net/~p_daley


Reply via email to