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
Hi Mike Robertson,
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
Mike Robertson said: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
Mike Robertson said: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.
Mike Robertson said: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
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Using Dependency Walker I can see the declaration:
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?
Mike Robertson said:Unable to find an entry point named 'msMacro_expandMacroExpression' in DLL 'ustation.dll'
Then that function must be implemented in another DLL. Use Windows tools to search the installed DLLs to find which one exports the function you want. For example, DLL Export Viewer.
Regards, Jon Summers LA Solutions
Jon,
Using Dll Export Viewer the method is located in the ustation.dll. I'm wondering if my declaration of parameter types is incorrect so the method signature is not found.
Mike Robertson said:I'm wondering if my declaration of parameter types is incorrect so the method signature is not found
Probably. Here's Bob's function definition...
StatusInt msMacro_expandMacroExpression(WStringR expansion, WCharCP expression, bool immediate, bool fmtExpansion)
The first arg is a C++ reference. I don't know how to translate that to C# — consult Microsoft web sites. ref string expansion must be wrong, because a Bentley WString is not a C# string.
ref string expansion
WString
string
The second arg is a pointer-to-string, and I think you can use a C# string as you have.
Third and fourth args are pass-by-value bools.
bool
FYI. I updated my original response above and provided forward declarations - originally the first containing MicroStation Data Types needed and (now) second - added the pure underlying Microsoft Data Types expected too.
Please try the Microsoft Data Type declaration and see if it helps you access msMacro_expandMacroExpression.