I need to extract the environment strings from a call to CreateEnvironmentBlock( out IntPtr lpEnvironment, IntPtr hToken, bool bInherit ), so as to put them in dictionary based on the variable name and its value.
When this function returns,
lpEnvironmentreceives a pointer to the new environment block. The environment block is an array of null-terminated Unicode strings. The list ends with two nulls (\0\0).
I cannot easily use Marshal.Copy as I do not know the block's length. I'm wondering if there is an easy way to move along it or determine what to copy to something I can then convert more easily. One thought was to pass the out IntPtr lpEnvironment as out char [] lpEnvironment.
Any suggestions?
Marshal.ReadInt16 (IntPtr)method. Read unicode characters until two 0 values are read. Increment IntPtr returned by CreateEnvironmentBlock by two on every iteration.out IntPtrdeclaration is OK. Don't forget to callDestroyEnvironmentBlock.Environment.GetEnvironmentVariables()?