Click here to Skip to main content
16,012,759 members
Home / Discussions / C#
   

C#

 
QuestionAny ideas? Pin
yonidebest8-Dec-06 1:02
yonidebest8-Dec-06 1:02 
QuestionHow to use Sql Transactions in Client/Server Database ? Pin
hdv2127-Dec-06 11:43
hdv2127-Dec-06 11:43 
AnswerRe: How to use Sql Transactions in Client/Server Database ? Pin
Guffa7-Dec-06 14:58
Guffa7-Dec-06 14:58 
QuestionHelp with a datagrid Pin
~~~Johnny~~~7-Dec-06 11:33
~~~Johnny~~~7-Dec-06 11:33 
QuestionAdding text to RichTextBox in form from another class Pin
NZSmartie7-Dec-06 11:13
NZSmartie7-Dec-06 11:13 
AnswerRe: Adding text to RichTextBox in form from another class Pin
Judah Gabriel Himango7-Dec-06 11:59
sponsorJudah Gabriel Himango7-Dec-06 11:59 
GeneralRe: Adding text to RichTextBox in form from another class Pin
NZSmartie7-Dec-06 12:00
NZSmartie7-Dec-06 12:00 
QuestionGCHandle... Pin
Shy Agam7-Dec-06 8:22
Shy Agam7-Dec-06 8:22 
Hello good people,

I recently discovered the GCHandle class and its use.
However, I can't seem to understand something...
In one of my projects I'm using SetWindowsHookEx(), which gets a function pointer, or a delegate to be exact...
However, I've no use with this delegate whatsoever...
My first attemt at writing the code was something like the following:
SetWindowsHookEx(... ,new BlaBlaDelegate(MyCallback), ...);
The above, sometimes, generated an exception which said that I tried to reference a null object (Not in these exact words of course Wink | ;) ).
The solution I came up with was to keep a reference in a global variable inside my class.
So the new code is somewhat like:
BlaBlaDelegate bla;
...
SetWindowsHookEx(..., bla = new BlaBlaDelegate(MyCallback), ...);
Works fine.

As MSDN documents:
"...Once allocated, you can use a GCHandle to prevent the managed object from being collected by the garbage collector when an unmanaged client holds the only reference. Without such a handle, the object can be collected by the garbage collector before completing its work on behalf of the unmanaged client."

Question is... Should I use GCHandle instead of holding a direct reference?
If so, when should I use the Free() method?
Right after the call to SetWindowsHookEx()?
GCHandle is supposed to "prevent the managed object from being collected...when the unmanaged client holds the only reference.".
So why use the Free() method right after the API call? (That's what MSDN examples show BTW)

Thanks in advance,
Shy.
AnswerRe: GCHandle... Pin
Judah Gabriel Himango7-Dec-06 9:34
sponsorJudah Gabriel Himango7-Dec-06 9:34 
GeneralRe: GCHandle... Pin
Shy Agam7-Dec-06 9:41
Shy Agam7-Dec-06 9:41 
GeneralRe: GCHandle... Pin
Judah Gabriel Himango7-Dec-06 11:58
sponsorJudah Gabriel Himango7-Dec-06 11:58 
QuestionResearching new project: Ability to speak answer phone calls via a PC? Pin
Goalie357-Dec-06 7:54
Goalie357-Dec-06 7:54 
QuestionHiding your computer's mouse Pin
Marc Clifton7-Dec-06 7:24
mvaMarc Clifton7-Dec-06 7:24 
AnswerRe: Hiding your computer's mouse Pin
Stefan Troschuetz7-Dec-06 7:38
Stefan Troschuetz7-Dec-06 7:38 
GeneralRe: Hiding your computer's mouse Pin
Marc Clifton7-Dec-06 8:24
mvaMarc Clifton7-Dec-06 8:24 
AnswerRe: Hiding your computer's mouse Pin
Ravi Bhavnani7-Dec-06 9:05
professionalRavi Bhavnani7-Dec-06 9:05 
GeneralRe: Hiding your computer's mouse Pin
Marc Clifton7-Dec-06 9:38
mvaMarc Clifton7-Dec-06 9:38 
AnswerSuccess! [modified] Pin
Ravi Bhavnani7-Dec-06 9:54
professionalRavi Bhavnani7-Dec-06 9:54 
GeneralRe: Success! Pin
Marc Clifton7-Dec-06 10:04
mvaMarc Clifton7-Dec-06 10:04 
GeneralRe: Success! Pin
Ravi Bhavnani7-Dec-06 10:10
professionalRavi Bhavnani7-Dec-06 10:10 
GeneralRe: Success! Pin
Marc Clifton7-Dec-06 11:48
mvaMarc Clifton7-Dec-06 11:48 
GeneralRe: Success! Pin
Ravi Bhavnani7-Dec-06 12:13
professionalRavi Bhavnani7-Dec-06 12:13 
AnswerRe: Hiding your computer's mouse Pin
Judah Gabriel Himango7-Dec-06 9:36
sponsorJudah Gabriel Himango7-Dec-06 9:36 
GeneralRe: Hiding your computer's mouse Pin
Marc Clifton7-Dec-06 9:41
mvaMarc Clifton7-Dec-06 9:41 
GeneralRe: Hiding your computer's mouse Pin
Judah Gabriel Himango7-Dec-06 9:47
sponsorJudah Gabriel Himango7-Dec-06 9:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.