Marshaling
-
I have a control that overrides
WndProc
. I handleWM_NCCALCSIZE
and in the case whereLParam
is true I need to store a pointer to a value in theResult
field of theMessage
structure. I do so as follows:msg.Result = Marshal.AllocHGlobal(4)
Marshal.WriteInt32(msg.Result, WVR_REDRAW)I never call
Marshal.FreeHGlobal
since theResult
is used outside the scope ofWndProc
. Will this code cause a memory leak? If so, is there any way to do this without a memory leak? Thanks -
I have a control that overrides
WndProc
. I handleWM_NCCALCSIZE
and in the case whereLParam
is true I need to store a pointer to a value in theResult
field of theMessage
structure. I do so as follows:msg.Result = Marshal.AllocHGlobal(4)
Marshal.WriteInt32(msg.Result, WVR_REDRAW)I never call
Marshal.FreeHGlobal
since theResult
is used outside the scope ofWndProc
. Will this code cause a memory leak? If so, is there any way to do this without a memory leak? Thanksmsg.Result = WVR_REDRAW;
will be just fine
-
msg.Result = WVR_REDRAW;
will be just fine
-
Ok, msg.Result = new IntPtr(WVR_REDRAW); As far as I'm concerned you are a lower form of life than B*** S***** and M***** M******** combined. Colin Davies on some guy called R*** G****
-
Ok, msg.Result = new IntPtr(WVR_REDRAW); As far as I'm concerned you are a lower form of life than B*** S***** and M***** M******** combined. Colin Davies on some guy called R*** G****
That doesn't work either.. That creates a pointer to memory location WVR_REDRAW, the value at that location is not controlled by me.. I need to set Result to an IntPtr that points to a location containing the value WVR_REDRAW... The only way that I know of to do this is with the AllocHGlobal and WriteInt32 calls...
-
That doesn't work either.. That creates a pointer to memory location WVR_REDRAW, the value at that location is not controlled by me.. I need to set Result to an IntPtr that points to a location containing the value WVR_REDRAW... The only way that I know of to do this is with the AllocHGlobal and WriteInt32 calls...
Kastro wrote: That doesn't work either.. No my code was right IntPtr is a value type so you will not have any problems. You don't need AllocHGlobal As far as I'm concerned you are a lower form of life than B*** S***** and M***** M******** combined. Colin Davies on some guy called R*** G****
-
Kastro wrote: That doesn't work either.. No my code was right IntPtr is a value type so you will not have any problems. You don't need AllocHGlobal As far as I'm concerned you are a lower form of life than B*** S***** and M***** M******** combined. Colin Davies on some guy called R*** G****
From the .NET help docs:
public IntPtr(
int value
);value - A pointer or handle contained in a 32-bit signed integer."
IntPtr is a value type, but the value that it stores is an address. My original code works (presumably leaking memory though). When I switch to using new IntPtr(WVR_REDRAW) it doesn't work...
-
From the .NET help docs:
public IntPtr(
int value
);value - A pointer or handle contained in a 32-bit signed integer."
IntPtr is a value type, but the value that it stores is an address. My original code works (presumably leaking memory though). When I switch to using new IntPtr(WVR_REDRAW) it doesn't work...
IntPtr is a value type of size same as the default pointer size for the platform. It can be used for numbers or pointers. All it is is that it size varies the number stored in it can be anything. In window messages LParam, and WParam are 32 bit ints or 64 bit ints depending on the platform. In window messages LParam and WParam mean different things depending on the context. Same thing about LResult it can be used to return integers or pointers. In case of WM_NCCALCSIZE windows expect an integer to be returned so if return as
new IntPtr(WVR_REDRAW)
it is ok. -
From the .NET help docs:
public IntPtr(
int value
);value - A pointer or handle contained in a 32-bit signed integer."
IntPtr is a value type, but the value that it stores is an address. My original code works (presumably leaking memory though). When I switch to using new IntPtr(WVR_REDRAW) it doesn't work...
Ok, I figured out what's going on... You are right about just using new IntPtr(WVR_REDRAW).. I used Spy++ to see what result was being returned for the WM_NCCALCSIZE message... For my code I was getting WVR_ALIGNBOTTOM | WVR_REDRAW | 0019F008 From what you suggested I get WVR_REDRAW... What you suggested wasn't working (as far as the control went) because of other reasons... Also is the wording of the help file incorrect then? That's what led me to believe what I did.
-
Ok, I figured out what's going on... You are right about just using new IntPtr(WVR_REDRAW).. I used Spy++ to see what result was being returned for the WM_NCCALCSIZE message... For my code I was getting WVR_ALIGNBOTTOM | WVR_REDRAW | 0019F008 From what you suggested I get WVR_REDRAW... What you suggested wasn't working (as far as the control went) because of other reasons... Also is the wording of the help file incorrect then? That's what led me to believe what I did.
Kastro wrote: Also is the wording of the help file incorrect then? Not entirely, IntPtr is used to represent an integer value that varies in size depending on the platform. A specific use of such an integer is a pointer. There isn't anything special about a pointer, except that its value refers to a location in memory. James "Java is free - and worth every penny." - Christian Graus