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
fixed a compile-time error in type-marshalling.md (#48780)
* fixed a compile-time error in type-marshalling.md
this change adds the `out` keyword to fix such compile-time error as well as inlines the variable declaration for simplicity and renames the variable from `st` to `systemTime` for both clarity and consistency.
* further improved a code block in `type-marshalling.md`
this change makes the code block ready-to-run for ease of use with copying.
Copy file name to clipboardExpand all lines: docs/standard/native-interop/type-marshalling.md
+23-20Lines changed: 23 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -99,31 +99,34 @@ When you are calling methods on COM objects in .NET, the .NET runtime changes th
99
99
Another aspect of type marshalling is how to pass in a struct to an unmanaged method. For instance, some of the unmanaged methods require a struct as a parameter. In these cases, you need to create a corresponding struct or a class in managed part of the world to use it as a parameter. However, just defining the class isn't enough, you also need to instruct the marshaller how to map fields in the class to the unmanaged struct. Here the `StructLayout` attribute becomes useful.
The previous code shows a simple example of calling into `GetSystemTime()` function. The interesting bit is on line 4. The attribute specifies that the fields of the class should be mapped sequentially to the struct on the other (unmanaged) side. This means that the naming of the fields isn't important, only their order is important, as it needs to correspond to the unmanaged struct, shown in the following example:
129
+
The previous code shows a simple example of calling into `GetSystemTime()` function. The interesting bit is on line 13. The attribute specifies that the fields of the class should be mapped sequentially to the struct on the other (unmanaged) side. This means that the naming of the fields isn't important, only their order is important, as it needs to correspond to the unmanaged struct, shown in the following example:
127
130
128
131
```c
129
132
typedefstruct _SYSTEMTIME {
@@ -135,7 +138,7 @@ typedef struct _SYSTEMTIME {
135
138
WORD wMinute;
136
139
WORD wSecond;
137
140
WORD wMilliseconds;
138
-
} SYSTEMTIME, *PSYSTEMTIME;
141
+
} SYSTEMTIME, *PSYSTEMTIME, *LPSYSTEMTIME;
139
142
```
140
143
141
144
Sometimes the default marshalling for your structure doesn't do what you need. The [Customizing structure marshalling](customize-struct-marshalling.md) article teaches you how to customize how your structure is marshalled.
0 commit comments