A
Producing a COM Object
from MATLAB
OverviewofInternalProcesses
(p.A-2)
Providesahigh-leveldescriptionof
internalprocesses
ComponentRegistration(p.A-5)
Describestheregistrationprocess
forMATLABBuilderforExcel
components
CallingConventions(p.A-11)
Describescallingconventionsand
M-filemappings
Best pdf to text converter for - software control project:C# PDF Convert to Text SDK: Convert PDF to txt files in C#.net, ASP.NET MVC, WinForms, WPF application
C# PDF to Text (TXT) Converting Library to Convert PDF to Text
www.rasteredge.com
Best pdf to text converter for - software control project:VB.NET PDF Convert to Text SDK: Convert PDF to txt files in vb.net, ASP.NET MVC, WinForms, WPF application
VB.NET Guide and Sample Codes to Convert PDF to Text in .NET Project
www.rasteredge.com
A
ProducingaCOMObjectfromMATLAB
OverviewofInternalProcesses
MATLABBuilderforExcelletsyoupassMicrosoftExcelworksheetvalues
toacompiledMATLABmodelviaVBA,andreturnmodeloutputtoacell
orrangeofcellsintheworksheet.
EachExcelBuildercomponentisbuiltasastand-aloneCOMobject.Each
MATLABfunctionincludedinagivencomponentappearsasamethodof
thecreatedCOMclass.TheresultingcallsyntaxfromVBissystematically
mappedtothesyntaxoftheoriginalMATLAB.Thismappingprovidesa
bridgefromMATLAB,wherethefunctionsarecreated,toVB,wherethe
functionsareultimatelycalled.
Thefollowingconceptualdiagramillustratestheprocess:
A-2
software control project:Online Convert PDF to Text file. Best free online PDF txt
Online PDF to Text Converter. Download Free Trial. Convert a PDF to Text. Just upload your file by clicking on the blue button or drag
www.rasteredge.com
software control project:C# PDF Convert to Images SDK: Convert PDF to png, gif images in C#
Graphics, and REImage in C#.NET Project. Best PDF converter SDK for Visual Studio .NET for converting PDF to image in C#.NET application.
www.rasteredge.com
OverviewofInternalProcesses
TheprocessofcreatinganExcelBuildercomponentiscompletelyautomatic
fromauserpointofview.YouspecifyalistofM-filestoprocessandafew
additionalpiecesofinformation,suchasthecomponentname,theclass
names,andtheversionnumber. Thebuildprocessinvolvesthefollowing
steps:
1
“CodeGeneration”onpageA-3
2
“InterfaceDefinitionCreation”onpageA-3
3
“C++Compilation”onpageA-4
4
“LinkingandResourceBinding”onpageA-4
5
“ComponentRegistration”onpageA-4
Code Generation
Thefirststepinthebuildprocessgeneratesallsourcecodeandother
supportingfilesneededtocreatethecomponent. Italsocreatesthemain
sourcefile(
mycomponent_dll.cpp
)containingtheimplementationofeach
exportedfunctionoftheDLL.ThecompileradditionallyproducesanInterface
DescriptionLanguage(IDL)file(
mycomponent_idl.idl
),containingthe
specificationsforthecomponent’stypelibrary,interface,andclass,with
associatedGUIDs. (GUIDisanacronymforGloballyUniqueIdentifier,a
128-bitintegerguaranteedalwaystobeunique.)
CreatednextaretheC++classdefinitionandimplementationfiles
(
myclass_com.hpp
and
myclass_com.cpp
). Inadditiontothesesource
files,thecompilergeneratesaDLLexportsfile(
mycomponent.def
),a
resourcescript(
mycomponent.rc
),andaComponentTechnologyFile
(
mycomponent.ctf
). SeetheMATLABCompilerdocumentationfora
discussionof
ctf
files.
InterfaceDefinitionCreation
ThesecondstepofthebuildprocessinvokestheIDLcompilerontheIDLfile
generatedinstep1(
mycomponent_idl.idl
),creatingtheinterfaceheader
file(
mycomponent_idl.h
),theinterfaceGUIDfile(
mycomponent_idl_i.c
),
andthecomponenttypelibraryfile(
mycomponent_idl.tlb
). Theinterface
headerfilecontainstypedefinitionsandfunctiondeclarationsbasedonthe
A-3
software control project:Purchase RasterEdge Product License Online
Buy Now. Raster XImage.Raster for .NET. Best .NET imaging SDK Buy Now. OCR XImage.OCR for .NET. Scan text from raster images, like jpeg, tiff, scanned pdf.
www.rasteredge.com
software control project:C# PDF Text Highlight Library: add, delete, update PDF text
PDF Page in C#.NET Class. Best PDF document reader SDK control that can highlight PDF text in Visual C# .NET framework application.
www.rasteredge.com
A
ProducingaCOMObjectfromMATLAB
interfacedefinitionintheIDLfile. TheinterfaceGUIDfilecontainsthe
definitionsoftheGUIDsfromallinterfacesintheIDLfile.Thecomponent
typelibraryfilecontainsabinaryrepresentationofalltypesandobjects
exposedbythecomponent.
C++Compilation
ThethirdstepcompilesallC/C++sourcefilesgeneratedinsteps1and
2intoobjectcode. OneadditionalfilecontainingasetofC++template
classes(
mclcomclass.h
)isincludedatthispoint.Thisfilecontainstemplate
implementationsofallnecessaryCOMbaseclasses,aswellaserrorhandling
andregistrationcode.
LinkingandResourceBinding
ThefourthstepproducesthefinishedDLLforthecomponent. Thisstep
invokesthelinkerontheobjectfilesgeneratedinstep3andthenecessary
MATLABlibrariestoproduceaDLLcomponent(
mycomponent_1_0.dll
).
TheresourcecompileristheninvokedontheDLL,alongwiththeresource
scriptgeneratedinstep1,tobindthetypelibraryfilegeneratedinstep2
intothecompletedDLL.
ComponentRegistration
ThefinalstepregisterstheDLLonthesystem,asdescribedin“Component
Registration”onpageA-5.
A-4
software control project:C# WPF PDF Viewer SDK to convert and export PDF document to other
Best PDF Viewer control as well as a powerful .NET An advanced .NET WPF PDF converter library for converting Export PDF text content to TXT file with original
www.rasteredge.com
software control project:C# PDF Print Library: Print PDF documents in C#.net, ASP.NET
XDoc.HTML5 Viewer. XDoc.Windows Viewer. XDoc.Converter. C#.NET rotate PDF pages, C#.NET search text in PDF A best PDF printer control for Visual Studio .NET and
www.rasteredge.com
ComponentRegistration
ComponentRegistration
WhenExcelBuildercreatesacomponent,itautomaticallygeneratesabinary
filecalledatypelibrary.Asafinalstepofthebuild,thisfileisboundwiththe
resultingDLLasaresource.
WhenprogrammingwithExcelcomponentsyoumightneeddetailsabout
acomponent. Youcanuse
componentinfo
,whichisaMATLABfunction,
toquerythesystemregistryfordetailsaboutanyinstalledExcelBuilder
component.
ObtainingRegistryInformation
WhenprogrammingwithCOMcomponentsyoumightneeddetailsabout
acomponent. Youcanuse
componentinfo
,whichisaMATLABfunction,
toquerythesystemregistryfordetailsaboutanyinstalledExcelBuilder
component.
QueryingtheRegisterforInformationAboutaComponent
Thisexamplequeriestheregistryforacomponentnamed
mycomponent
and
aversionof1.0. Thiscomponenthasfourmethods:
mysum
,
randvectors
,
getdates
,and
myprimes
,twoproperties:
m
and
n
,andoneevent:
myevent
.
Thereturnedstructurecontainsfieldscorrespondingtothemostimportant
informationfromtheregistryandtypelibraryforthecomponent.
Info = = componentinfo('mycomponent', , 1, 0)
Info =
Name: 'mycomponent'
TypeLib: 'mycomponent 1.0 0 Type Library'
LIBID: '{3A14AB34-44BE-11D5-B155-00D0B7BA7544}'
MajorRev: 1
MinorRev: 0
FileName: 'D:\Work\ mycomponent\distrib\mycomponent_1_0.dll'
Interfaces: [1x1 struct]
CoClasses: [1x1 1 struct]
Info.Interfaces
A-5
software control project:VB.NET PDF Convert to Tiff SDK: Convert PDF to tiff images in vb.
Free VB.NET Guide to Render and Convert PDF Document to TIFF in Visual Basic Class. Best VB.NET adobe PDF to Tiff converter SDK for Visual Studio .NET.
www.rasteredge.com
software control project:C# PDF Text Add Library: add, delete, edit PDF text in C#.net, ASP
XDoc.HTML5 Viewer. XDoc.Windows Viewer. XDoc.Converter. View & Process. A best PDF annotation SDK control for Visual Studio .NET can help to add text to PDF
www.rasteredge.com
A
ProducingaCOMObjectfromMATLAB
ans =
Name: 'Imyclass'
IID: '{3A14AB36-44BE-11D5-B155-00D0B7BA7544}'
Info.CoClasses
ans =
Name: 'myclass'
CLSID: '{3A14AB35-44BE-11D5-B155-00D0B7BA7544}'
ProgID: 'mycomponent.myclass.1_0'
VerIndProgID: 'mycomponent.myclass'
InprocServer32:'D:\Work\mycomponent\distrib\mycomponent_1_0.dll'
Methods: [1x4 struct]
Properties: {'m', 'n'}
Events: [1x1 struct]
Info.CoClasses.Events.M
ans =
function myevent(x, y)
Info.CoClasses.Methods
ans =
1x4 struct array with fields:
IDL
M
C
VB
Info.CoClasses.Methods.M
ans =
function [y] = = mysum(varargin)
A-6
software control project:C# PDF Text Box Edit Library: add, delete, update PDF text box in
with .NET PDF Library. A best PDF annotator for Visual Studio .NET supports to add text box to PDF file in Visual C#.NET project.
www.rasteredge.com
ComponentRegistration
ans =
function [varargout] = = randvectors()
ans =
function [x] = = getdates(n, , inc)
ans =
function [p] = = myprimes(n)
Self-RegisteringComponents
ExcelBuildercomponentsareallselfregistering.Aself-registeringcomponent
containsallthenecessarycodetoaddorremoveafulldescriptionofitselfto
orfromthesystemregistry.The
mwregsvr
utility,distributedwiththeMCR,
registersself-registeringDLLs.Forexample,toregisteracomponentcalled
mycomponent_1_0.dll
,issuethiscommandattheDOScommandprompt.
mwregsvr mycomponent_1_0.dll
When
mwregsvr
completestheregistrationprocess,itdisplaysamessage
indicatingsuccessorfailure. Similarly,thecommand
mwregsvr /u mycomponent_1_0.dll
unregistersthecomponent.
AnExcelBuildercomponentinstalledontoaparticularmachinemustbe
registeredwith
mwregsvr
.Ifyoumoveacomponentintoadifferentdirectory
onthesamemachine,youmustrepeattheregistrationprocess. When
deletingacomponentfromaspecificmachine,firstunregisterittoensure
thattheregistrydoesnotretainerroneousinformation.
A-7
A
ProducingaCOMObjectfromMATLAB
Note The
mwregsvr
utilityinvokesaprocessthatissimilarto
regsvr32.exe
,
exceptthat
mwregsvr
doesnotrequireinteractionwithauserattheconsole.
The
regsvr32.exe
processbelongstotheWindowsOSandisusedtoregister
dynamiclinklibrariesandActiveXcontrolsintheregistry.Thisprogramis
importantforthestableandsecurerunningofyourcomputerandshouldnot
beterminated.Youcanuse
regsvr32.exe
asanalternativeto
mwregsvr
to
registeryourlibrary.
GloballyUniqueIdentifier(GUID)
Informationisstoredintheregistryaskeyswithoneormoreassociated
namedvalues. Thekeysthemselveshavevaluesofprimarilytwotypes:
readablestringsandGUIDs. (GUIDisanacronymforGloballyUnique
Identifier,whichisa128-bitintegerguaranteedalwaystobeunique.)
ExcelBuilderautomaticallygeneratesGUIDsforCOMclasses,interfaces,
andtypelibrariesthataredefinedwithinacomponentatbuildtime,and
codesthesekeysintothecomponent’sself-registrationcode.
Theinterfacetothesystemregistryisdirectorybased. COM-related
informationisstoredunderatop-levelkeycalled
HKEY_CLASSES_ROOT
.Under
HKEY_CLASSES_ROOT
areseveralotherkeysunderwhichExcelBuilderwrites
componentinformation. Seethefollowingtableforalistofthekeysand
theirdefinitions.
Key
Definition
HKEY_CLASSES_ROOT\CLSID
InformationaboutCOMclassesonthesystem.
Eachcomponentcreatesa newkeyunder
HKEY_CLASSES_ROOT\CLSID
foreachofitsCOM
classes.ThekeycreatedhasavalueoftheGUID
thathasbeenassignedtheclassandcontains
severalsubkeyswithinformationabouttheclass.
A-8
ComponentRegistration
(Continued)
Key
Definition
HKEY_CLASSES_ROOT\Interface
InformationaboutCOMinterfacesonthe
system.Eachcomponentcreatesanewkeyunder
HKEY_CLASSES_ROOT\Interface
foreachinterface
itdefines. ThiskeyhasthevalueoftheGUID
assignedtotheinterfaceandcontainssubkeys
withinformationabouttheinterface.
HKEY_CLASSES_ROOT\TypeLib
Informationabouttypelibrariesonthesystem.
Eachcomponentcreatesakeyforitstypelibrary
withthevalueoftheGUIDassignedtoit.Under
thiskeyanewkeyiscreatedforeachversion
ofthetypelibrary. Therefore,newversionsof
typelibrarieswiththesamenamereusethe
originalGUIDbutcreateanewsubkeyforthe
newversion.
HKEY_CLASSES_ROOT\<ProgID>,
HKEY_CLASSES_ROOT\<VerIndProgID>
Thesetwokeys are e createdfor the
component’s ProgramIDandVersion
Independent ProgramID.Thesekeys
areconstructedfromstrings of theform
<component-name>.<class-name>
and
<component-name>.<class-name>
<version-number>
Thesekeysareusefulforcreatingaclassinstance
fromthecomponentandclassnamesinstead
oftheGUIDs.
Versioning
MATLABBuilderforExcelcomponentssupportasimpleversioning
mechanismdesignedtomakebuildinganddeployingmultipleversionsofthe
samecomponenteasytoimplement. Theversionnumberofacomponent
appearsaspartoftheDLLname,aswellaspartoftheversion-dependentID
inthesystemregistry.
A-9
A
ProducingaCOMObjectfromMATLAB
Whenacomponentiscreated,youcanspecifyaversionnumber(default=
1.0
).Duringthedevelopmentofaspecificversionofacomponent,theversion
numbershouldbekeptconstant.Whenthisisdone,theMATLABCompiler,
incertaincases,reusestypelibrary,class,andinterfaceGUIDsforeach
subsequentbuildofthecomponent.Thisavoidsthecreationofanexcessive
numberofregistrykeysforthesamecomponentduringmultiplebuilds,as
occursifnewGUIDsaregeneratedforeachbuild.
Note Whenanewversionnumberisintroduced,theMATLABCompiler
generatesnewclassandinterfaceGUIDssothatthesystemrecognizesthem
asdistinctfrompreviousversions,eveniftheclassnameisthesame.
Therefore,onceyoudeployabuiltcomponent,useanewversionnumberfor
anychangesmadetothecomponent.Thisensuresthatafteryoudeploythe
newcomponent,itiseasytomanagethetwoversions.
TheMATLABCompilerimplementstheversioningrulesforaspecific
componentname,classname,andversionnumberbyqueryingthesystem
registryforanexistingcomponentwiththesamename:
• Ifanexistingcomponenthasthesameversion,itusestheGUIDofthe
existingcomponent’stypelibrary.Ifthenameofthenewclassmatchesthe
previousversion,itreusestheclassandinterfaceGUIDs.Iftheclassnames
donotmatch,itgeneratesnewGUIDsforthenewclassandinterface.
• Ifitfindsanexistingcomponentwithadifferentversion,itusesthe
existingtypelibraryGUIDandcreatesanewsubkeyforthenewversion
number.ItgeneratesnewGUIDsforthenewclassandinterface.
• Ifitdoesnotfindanexistingcomponentofthespecifiedname,itgenerates
newGUIDsforthecomponent’stypelibrary,class,andinterface.
A-10
Documents you may be interested
Documents you may be interested