" **Developer**" <RE*************@a-znet.com> schrieb
Public Shared Sub junk...
Dim PF2 As Wnd.PARAFORMAT2
PF2.cbSize = Marshal.SizeOf(PF2) 'ERROR HERE
PF2.dwMask = Wnd.PFM_LINESPACING
...snip
I just converted a solution to VS2005 and it is complaining:
Warning 22 Variable 'PF2' is used before it has been assigned a
value. A null reference exception could result at runtime. Make sure
the structure or all the reference members are initialized before
use
How do I initialize PF2.
Each of its members?
What is the rational for requiring initialization - simply to
document what the developer wanted?
The compiler does not know which members of PF2 are accessed within
Marshal.SizeOf. Therefore there is a /potential/ risk that SizeOf accesses a
member that has not been initialized, thus you get the warning because it
would lead to a run time error (NullrefernceExeption). As you know this is
not true in this specific case, you can ignore the warning - it's only a
warning. The compiler only says "be aware, if you pass this object to a
function, the function might access it's members, thus have an eye on
initalizing all members before". You can change the behavior in the project
properties under the "compile" tab.
Alternatively, use "Marshal.SizeOf(Gettype(Wnd.paraformat2))".
Armin