-
Is it possible to marshall the Right now the type of this field is
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Is there a risk that a future version of Windows could overload lpDesktop with some new flag in dwFlags, similar to how hStdInput can be either a handle or a hot key? That would then conflict with any automatic string marshalling. Although there is STARTUPINFOEX nowadays, the GetStartupInfo function doesn't appear to support it, so any new settings that need to be readable by application code (as opposed to operating system code) in the new process might still be placed in STARTUPINFO. |
Beta Was this translation helpful? Give feedback.
-
@AArnott is this a C#/Win32 question? |
Beta Was this translation helpful? Give feedback.
-
There are two sides to your question:
Yes. This is easy: just call But your code snippet asks a different question: var si = new STARTUPINFOW();
si.lpDesktop = @"winsta0\" + desktopName; This requires marshaling a string to a PWSTR, which is a bit trickier, because now you have to manage pinned memory while you use the struct. Here's how to do it: fixed (char* pDesktopName = @"winsta0\" + desktopName)
{
STARTUPINFOW si = default;
si.lpDesktop = pDesktopName;
// Also *pass* STARTUPINFOW to any function that needs it within this fixed block so the pointer remains valid.
} As this uses pointers, you'll need to be in an |
Beta Was this translation helpful? Give feedback.
There are two sides to your question:
Yes. This is easy: just call
PWSTR.ToString()
.But your code snippet asks a different question:
This requires marshaling a string to a PWSTR, which is a bit trickier, because now you have to manage pinned memory while you use the struct. Here's how to do it:
A…