[MSCE 10.16 C#] How to get actual config variable value instead of expanded value

MicroStation sets the default value of the MS_REPORT_OUTPUT variable to $(_DGNDIR).

When I use the following code to read the variable: string ReportLocation = ConfigurationManager.GetVariable("MS_REPORT_OUTPUT");

I get the actual disk location of the active file, is there a way to get the non-expanded value? I'm writing an addin for reporting and I have to use keyins to kick off the report and I want to set the location by changing the variable then setting it back to the original before I exit the addin.

Below is quick code test:

 string ReportLocation = ConfigurationManager.GetVariable("MS_REPORT_OUTPUT"); //returns expanded value (the physical file location), not the value of the variable
 ConfigurationManager.DefineVariable("MS_REPORT_OUTPUT", @"C:\temp");            //set location I want the report generated (just a test location for now)
 Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.CadInputQueue.SendCommand(@"reports export ""Untitled\piertest"""); //run report
 ConfigurationManager.DefineVariable("MS_REPORT_OUTPUT", ReportLocation);  //reset the variable back to it initial non-expanded value

Parents
  • Hi ,

    As explained here GetVariable takes a simplified path forward in MicroStation CONNECT to help eliminate: improper use, dormant memory allocations and confusion when calling: mdlSystem_getCfgVar() vs the more often needed call to: mdlSystem_expandCfgVar(). If there is a need to obtain the unexpanded variable value then it is recommended to import and call msMacro_expandMacroExpression() located in mdlbltin.lib passing false as the last parameter value.

    When providing a forward declaration using the SDK types, it should appear as:

    MSCORE_EXPORT StatusInt     msMacro_expandMacroExpression(WStringR expansion, WCharCP expression, bool immediate, bool fmtExpansion)

    When providing a forward declaration using Microsoft types, it should appear as:

    int __cdecl msMacro_expandMacroExpression(struct Bentley::WString & __ptr64,wchar_t const * __ptr64,bool,bool)

    HTH,
    Bob 



  • Robert,

    Any chance you could point me in the right direction, do I import a lib file using the DllImport attribute like I would for accessing the ustation.dll file?

    I can't find documentation on msMacro_expandMacroExpression method in the MicroStation API Documentation (doing a search on just msMacro shows no hits in the documentation)

  • Hi Mike

    I can't find documentation on msMacro_expandMacroExpression method in the MicroStation API Documentation

    I think it's not documented anywhere. But as Bob wrote, it is available in mdlbltin.lib and published also in ustation.dll

    do I import a lib file using the DllImport attribute like I would for accessing the ustation.dll file?

    I think you should use ustation.dll in DllImport.

    Any chance you could point me in the right direction

    Because P/Invoke is standard NET Framework feature from version 1, it's is well documented (including how data types are marshalled), and for more complicated marshalling a lot of tutorials and discussions can be found on Internet.

    With regards,

      Jan

  • Using Dependency Walker I can see the declaration:

    int __cdecl msMacro_expandMacroExpression(struct Bentley::WString & __ptr64,wchar_t const * __ptr64,bool,bool)

    In my code I have the following:

    [DllImport("ustation.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
    static extern int msMacro_expandMacroExpression(ref string expansion, string expression, bool immediate, bool fmtExpansion);

    Then inside a method I call:

    string output = string.Empty;
    string expression = "MS_REPORT_OUT";
    int statusInt = msMacro_expandMacroExpression(ref output, expression, true, false);

    The code throws the following exception:

    "Unable to find an entry point named 'msMacro_expandMacroExpression' in DLL 'ustation.dll'

    I tried using both Int32 & Int64 for the return type, are my parameter types wrong?

Reply
  • Using Dependency Walker I can see the declaration:

    int __cdecl msMacro_expandMacroExpression(struct Bentley::WString & __ptr64,wchar_t const * __ptr64,bool,bool)

    In my code I have the following:

    [DllImport("ustation.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
    static extern int msMacro_expandMacroExpression(ref string expansion, string expression, bool immediate, bool fmtExpansion);

    Then inside a method I call:

    string output = string.Empty;
    string expression = "MS_REPORT_OUT";
    int statusInt = msMacro_expandMacroExpression(ref output, expression, true, false);

    The code throws the following exception:

    "Unable to find an entry point named 'msMacro_expandMacroExpression' in DLL 'ustation.dll'

    I tried using both Int32 & Int64 for the return type, are my parameter types wrong?

Children