Implementing ATL COM object wrapper for Raster Manager API
Part of product |
Research |
Date |
February 2002 |
Programming languages |
VC++ & ATL |
Company |
|
Description |
In first releases of MicroStation v8, DGN COM object didn't offer Raster Management functionalities. That led me to think on alternatives - how to create COM object encapsulating MDL API for Raster Management. I have used ATL in Visual Studio v 6 and implemented functions for open and close raster as well for raster notification events. The COM object was subsequently tested in different environments (JScript, VBScript, VBA, WSH, HTML). Now raster Object is implemented in MicroStation COM object, but still this work showed how to make custom ATL objects from MDL API. |
#include "stdafx.h"
#include "RasterObjx.h"
#include "RasterMan.h"
static void *rasObj;
....
//------------------ open raster test
STDMETHODIMP CRasterMan::OpenRaster(BSTR fileNameP,
int view){char name[256];long ramHnd;
WideCharToMultiByte(CP_ACP, 0, fileNameP,SysStringLen(fileNameP)+1, name, 256, 0, 0);
mdlRaster_fileOpen(&ramHnd,name,mdlModelRef_getActive(),
FILE_ACCESSMODE_READ,EVENT_UPDATE);
RasterRenderingInfo rendInfo;
mdlRaster_renderingInfoGet(&rendInfo,ramHnd);
rendInfo.view1 = 1;
// display in view 1mdlRaster_renderingInfoSet(&rendInfo,ramHnd,EVENT_UPDATE);
return S_OK;}
// ---------------- fire raster event test
void
RasterEvent (a long,b long, double, double, char){((CRasterMan*)rasObj)->Fire_OnRasterManEvent(a,b);
}
// --------------- set listener test
STDMETHODIMP CRasterMan::SetRasterListener(){
long handle;rasObj =(
void*) this; // not nice handled, just for test..mdlRaster_eventFunctionSet(RASTER_EVENT,
&handle,RasterEvent,mdlSystem_getCurrMdlDesc());
return S_OK;}
<HTML><HEAD>
<SCRIPT LANGUAGE="VBScript">
Sub Button1_OnClick
call raster.SetRasterListener()
call raster.OpenRaster("d:\img.hmr",0)
End Sub
Sub raster_OnRasterManEvent(a,b)
MsgBox "Raster from HTML Event"
End sub
</SCRIPT></HEAD>
<BODY>
<object classid="clsid:03D36700-4043-4211-BADC-3450BB0C9080"
id="raster" events="true"></object>
<FORM><INPUT NAME="Button1" TYPE="BUTTON" VALUE="Open
Raster"></FORM>
</BODY></HTML>
<job>
<object progid="RasterObjx.RasterMan" id="raster" events="true"/>
<script language="vbscript">
sub raster_OnRasterManEvent(a,b)
Wscript.echo "Raster from WSH Event"
end sub
call raster.SetRasterListener()
call raster.OpenRaster("d:\img.hmr",0)
wscript.sleep 5000
</script>
</job>
Dim
WithEvents msrastObj As RasterMan...
Set
msrastObj = CreateObject("RasterObjx.RasterMan")Call
msrastObj.SetRasterListenerCall
msrastObj.OpenRaster("d:\img.hmr",0)...
Sub
msrastObj_OnRasterManEvent(ByVal eventId As Long, ByVal param As Long)MsgBox
"Raster Event from VBA"End
Sub