[gme-users] Help with paradigm registration

Peter Volgyesi peter.volgyesi at vanderbilt.edu
Fri Jul 23 13:50:49 CDT 2004


Hi,

1., Create a new Win32 Console Application (Choose simple application)

2., Add MgaUtil.idl, Mga.idl and Meta.idl to your project (right click on
Source Files, select Add Files to Folder... and find these files in the
Interfaces folder of the GME installation)

3., Open Project/Settings...

4., In the Settings For: combolist select "All configurations"

5., For each .idl files you've just added set the Custom Build parameters:
    a., Command textbox: midl $(InputPath) /server none /client none
/IC:\Program Files\GME\Interfaces
    b., Outputs textbox: .\$(InputName).h

6., In your .cpp file include the following files (right after stdafx.h):
    #include <objbase.h>
    #include "mgautil.h"

7., Here comes the contents of the main function:
------------------------------------------------------
int main(int argc, char* argv[])
{
	HRESULT hr;
	CLSID clsid;
	IMgaRegistrar *reg;

	//Initialize the OLE libraries
	hr = ::CoInitialize(NULL);
	if (FAILED(hr)) {
		// TODO: error handling
	}

	hr = ::CLSIDFromProgID(OLESTR("Mga.MgaRegistrar"), &clsid);
	if (FAILED(hr)) {
		// TODO: error handling
	}

	hr = ::CoCreateInstance(clsid, NULL, CLSCTX_ALL, 
		__uuidof(IMgaRegistrar),reinterpret_cast<void**>(&reg));
	if (FAILED(hr)) {
		// TODO: error handling
	}
	
	BSTR connstr = ::SysAllocString(OLESTR("XML=C:\\Temp\\foo.xmp"));
	BSTR parname = NULL;

	hr = reg->RegisterParadigmFromData(connstr, &parname,
REGACCESS_SYSTEM);
	if (FAILED(hr)) {
		// TODO: error handling
	}
	::SysFreeString(connstr);
	::SysFreeString(parname);


	reg->Release();

	::CoUninitialize(); 

	return 0;
}
------------------------------------------------------

Hope, this helps.
--
peter

 

> -----Original Message-----
> From: gme-users-bounces at list.isis.vanderbilt.edu 
> [mailto:gme-users-bounces at list.isis.vanderbilt.edu] On Behalf 
> Of Krishnakumar B
> Sent: Thursday, July 22, 2004 6:40 PM
> To: gme-users at list.isis.vanderbilt.edu
> Subject: [gme-users] Help with paradigm registration
> 
> Hi,
> 
> I am trying to make an installer for our toolsuite. As part 
> of finishing up
> the installation, I would like to register the paradigm with 
> GME. I saw
> some example code in InstallScript which looked something like:
> 
> try
>    set oGME = CreateObject("Mga.MgaRegistrar");
> catch
>    SendErrorMsg(hInstall, "Can't create Mga.MgaRegistrar
>                 object. Please check if you have a valid GME 
> installaton.
>                 \n" + Err.Description, 1); 
> endcatch; 
> // System-wide register
> nParadigmRegMode = REGACCESS_SYSTEM;
> nBuffer = 256;
> 
> // Register the UML paradigm
> 
> svParadigmDir = INSTALLDIR ^ "etc";
> nParadigmRegMode = REGACCESS_USER;
> svParadigmName = "UML.xmp";
> 
> // User registeration
> SendMsgToProgressBar(hInstall, svParadigmName);
> try
>                 oGME.RegisterParadigmFromData("XML=" + svParadigmDir ^
> svParadigmName, svParadigmRegName, nParadigmRegMode);
> catch
>                 SendErrorMsg(hInstall, "Can't register Paradigm
>                 "+svParadigmDir ^ svParadigmName +". Please 
> check if you
> have a valid GME installaton. \n" + Err.Description, 1);
> endcatch;
> 
> I am trying to write a C++ equivalent of the above (with the 
> hope of making
> an executable someday which can be installed as a custom 
> action in the MSI
> that I am creating). I need some information/help about the internal
> functions of GME. If you see the above snippet, it creates a 
> COM object and
> calls RegisterParadigmFromData(). So can someone please help 
> me with the
> small bit of magic needed to do the same with C++?
> 
> I tried the following but it wouldn't compile (obvious since 
> I don't know
> COM). Also where can I get information about the API supported by
> Mga.MgaRegistrar inteface?
> 
> Any help is very much appreciated.
> 
> Thanks,
> kitty.
> 
> 
> 
> UINT __stdcall RegisterParadigm (MSIHANDLE hInstall)
> {
>   // installable paradigm number
>   int nParadigmNum = 0;
> 
>   // Initialize progress bar
>   InitProgressBar(hInstall, nParadigmNum, PARADIGMCOST,
>                   "Paradigm Install",
>                   "Registering Paradigms into GME.", 
> "Registering [1]");
> 
>   // Try to get the GME COM object
>   CObject* GME = CreateObject("Mga.MgaRegistrar");
>   if (GME == NULL)
>     SendErrorMsg (hInstall, "Can't create Mga.MgaRegistrar 
> object. Please check"
>                   "if you have a valid GME installaton. \n" + 
> LastError(), 1);
>   const int nBuffer = 256;
> 
>   char* value = GetRegistryValue (HKEY_LOCAL_MACHINE,
>                                   "SOFTWARE\\ISIS\\CoSMIC",
>                                   "TargetDir");
>   if (value == 0)
>     SendErrorMsg (hInstall, "Unable to access Registry Key 
> TargetDir", 1);
> 
>   CString targetDir (value);
> 
>   // Register the PICML paradigm
> 
>   CString svParadigmDir = targetDir + "paradigms";
> 
>   // User-wide register
>   int nParadigmRegMode = REGACCESS_USER;
>   CString svParadigmName = "PICML.xmp";
> 
>   // User registeration
>   SendMsgToProgressBar(hInstall, svParadigmName);
>   try
>     {
>       GME->RegisterParadigmFromData("XML=" + svParadigmDir + 
> svParadigmName,
>                                     svParadigmRegName, 
> nParadigmRegMode);
>     }
>   catch (...)
>     {
>       SendErrorMsg (hInstall, "Unable to register Paradigm " 
> + svParadigmDir +
>                    svParadigmName + ". Please check if you 
> have a valid GME"
>                    "installation. \n" + LastError(), 1);
>     }
> 
>   // System Wide registration
>   nParadigmRegMode = REGACCESS_SYSTEM;
>   SendMsgToProgressBar(hInstall, svParadigmName);
>   try
>     {
>       GME->RegisterParadigmFromData("XML=" + svParadigmDir + 
> svParadigmName,
>                                     svParadigmRegName, 
> nParadigmRegMode);
>     }
>   catch (...)
>     {
>       SendErrorMsg (hInstall, "Unable to register Paradigm " 
> + svParadigmDir +
>                    svParadigmName + ". Please check if you 
> have a valid GME"
>                    "installation. \n" + LastError(), 1);
>     }
>   return ERROR_SUCCESS;
> }
> 
> _______________________________________________
> gme-users mailing list
> gme-users at list.isis.vanderbilt.edu
> http://list.isis.vanderbilt.edu/mailman/listinfo/gme-users



More information about the gme-users mailing list