The MASM Forum

General => The Campus => Topic started by: Rav on June 07, 2022, 10:31:28 AM

Title: Can you detect assembling under ML.EXE as opposed to under Visual Studio?
Post by: Rav on June 07, 2022, 10:31:28 AM
When assembling my assembly routine, I want to have a section of conditional assembly which is only included if assembly is occurring via ML.EXE (from the Windows command prompt), and not include that section if it's being assembled within the Visual Studio app (by clicking the Local Windows Debugger button).  For example, I could pass some argument to ML.EXE which an IF statement in the assembly routine could detect the presence of.  Or I could set a Windows environment variable only when I'm running ML.EXE -- similarly, the IF statement would read the environment variable and decide to assemble (or not) the conditional section based on the environment variables contents.  For example, something like this:

; Include the following statements if we're being assembled by ML.EXE:
IF "%isRunUnderML%" == "1"
   statement
   statement
ENDIF

Thanks for any leads.  / Rav
Title: Re: Can you detect assembling under ML.EXE as opposed to under Visual Studio?
Post by: jj2007 on June 07, 2022, 11:01:58 AM
If you assemble a source using a batch file, you can set an environment variable. RichMasm (http://masm32.com/board/index.php?topic=5314.0), for example, recognises comment lines starting with OPT_xxx, such as OPT_Susy Console, and passes them on as e.g. set oSusy=console. In your code, you can access the variable as follows:

ifidni @Environ(oSusy), <Windows>
MsgBox 0, fname, "Map not found:", MB_OK
else
Inkey "Map not found: ", fname
endif


If you assemble a windows GUI application with /Subsystem:Windows, an Inkey would be dangerous because the user will never see it - therefore the MsgBox.
Title: Re: Can you detect assembling under ML.EXE as opposed to under Visual Studio?
Post by: Rav on June 07, 2022, 11:25:07 AM
Quote from: jj2007 on June 07, 2022, 11:01:58 AM
If you assemble a source using a batch file, you can set an environment variable. RichMasm (http://masm32.com/board/index.php?topic=5314.0), for example, recognises comment lines starting with OPT_xxx, such as OPT_Susy Console, and passes them on as e.g. set oSusy=console. In your code, you can access the variable as follows:

ifidni @Environ(oSusy), <Windows>
MsgBox 0, fname, "Map not found:", MB_OK
else
Inkey "Map not found: ", fname
endif


If you assemble a windows GUI application with /Subsystem:Windows, an Inkey would be dangerous because the user will never see it - therefore the MsgBox.

ifidni @Environ works perfectly!  Thanks!  / Rav