You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey together, I got the following small program and I want to compile it as small as possible. So I tried to use the following command bflat build -o program --os windows --arch arm64 --no-reflection --no-stacktrace-data --no-globalization --no-exception-messages -Os --no-pie --separate-symbols --stdlib Zero. As you can see, I want to use the Zero stdlib because the program does not use any of the fancy stuff from the stdlib.
But when compiling the program, I noticed some problems regarding the external calls. One of them is the fact that the DllImport from the Zero lib does not support the SetLastError property. I don't know if that's by design or not.
The second thing is I am apparently not able to get the last global error set by the runtime. With the normal stdlib I would use Marshal.GetLastWin32Error or Marshal.GetLastPInvokeError, but both of these are not available in the zero stdlib. So my question is how should I go about this, because I'm not that deep into native interop with C#
internalstaticclassInterop{publicdelegateboolConsoleCtrlDelegate(uintdwCtrlEvent);[DllImport("kernel32.dll",SetLastError=true)]publicstaticexternboolFreeConsole();[DllImport("kernel32.dll",SetLastError=true)]publicstaticexternboolAttachConsole(uintdwProcessId);[DllImport("kernel32.dll",SetLastError=true)]publicstaticexternboolSetConsoleCtrlHandler(ConsoleCtrlDelegate?handlerRoutine,booladd);[DllImport("kernel32.dll",SetLastError=true)]publicstaticexternboolGenerateConsoleCtrlEvent(uintdwCtrlEvent,uintdwProcessGroupId);}internalstaticclassProgram{publicstaticintMain(string[]args){varprocessId=uint.Parse(args[0],CultureInfo.InvariantCulture);varsignal=uint.Parse(args[1],CultureInfo.InvariantCulture);// detach from the current console, if one is attached to the process.Interop.FreeConsole();varsuccess=// attach to the target process groupInterop.AttachConsole(processId)&&// set to ignore signals on self, so the proper exit code can be returnInterop.SetConsoleCtrlHandler(null,true)&&// send the signal to the process groupInterop.GenerateConsoleCtrlEvent(signal,0);returnsuccess?0:Marshal.GetLastPInvokeError();}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hey together, I got the following small program and I want to compile it as small as possible. So I tried to use the following command
bflat build -o program --os windows --arch arm64 --no-reflection --no-stacktrace-data --no-globalization --no-exception-messages -Os --no-pie --separate-symbols --stdlib Zero
. As you can see, I want to use theZero
stdlib because the program does not use any of the fancy stuff from the stdlib.But when compiling the program, I noticed some problems regarding the external calls. One of them is the fact that the
DllImport
from the Zero lib does not support theSetLastError
property. I don't know if that's by design or not.The second thing is I am apparently not able to get the last global error set by the runtime. With the normal stdlib I would use
Marshal.GetLastWin32Error
orMarshal.GetLastPInvokeError
, but both of these are not available in the zero stdlib. So my question is how should I go about this, because I'm not that deep into native interop with C#Beta Was this translation helpful? Give feedback.
All reactions