Click here to Skip to main content
15,909,953 members
Home / Discussions / C#
   

C#

 
QuestionReturn int* to C# from C++ DLL? Pin
Alan Balkany7-May-09 5:35
Alan Balkany7-May-09 5:35 
AnswerRe: Return int* to C# from C++ DLL? Pin
Luc Pattyn7-May-09 6:16
sitebuilderLuc Pattyn7-May-09 6:16 
GeneralRe: Return int* to C# from C++ DLL? Pin
Alan Balkany7-May-09 6:22
Alan Balkany7-May-09 6:22 
GeneralRe: Return int* to C# from C++ DLL? [modified] Pin
Luc Pattyn7-May-09 6:54
sitebuilderLuc Pattyn7-May-09 6:54 
GeneralRe: Return int* to C# from C++ DLL? [modified] Pin
Alan Balkany7-May-09 8:27
Alan Balkany7-May-09 8:27 
GeneralRe: Return int* to C# from C++ DLL? Pin
Luc Pattyn7-May-09 8:38
sitebuilderLuc Pattyn7-May-09 8:38 
GeneralRe: Return int* to C# from C++ DLL? Pin
Dan Neely7-May-09 9:29
Dan Neely7-May-09 9:29 
GeneralRe: Return int* to C# from C++ DLL? Pin
Luc Pattyn7-May-09 9:54
sitebuilderLuc Pattyn7-May-09 9:54 
Hi Dan,

the object has to be pinned since the GC could suddenly run and move objects around; say another thread kicks in and needs memory.

AFAIK there are three ways to achieve that:

1. use the "fixed" keyword, it will pin behind the scenes;
2. use GCHandle.Alloc, GCHandle.AddrOfPinnedObject and GCHandle.Free;
3. use automatic marshaling; it will also pin objects for you.

1. is OK for simple situations
2. is what I use most of all; it is fine when the pointer remains in use in the native world after the first native function call returns (e.g. when initiating asynchronous I/O). One should not forget to free the GCHandle when done!
3. is not always clear how things get done, quite often data gets copied which I don't like in general. The performance gained by using native code (say for image processing) is lost by one or two silly copy operations that don't accomplish anything. My main use for automatic marshaling is sending Unicode strings to ASCII-oriented C code.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


QuestionProblem in Toolstrip Pin
priyamtheone7-May-09 5:24
priyamtheone7-May-09 5:24 
QuestionUpdating confirmation box by commandfield. Pin
magshine7-May-09 5:15
magshine7-May-09 5:15 
QuestionHow to put powerpoint on different displays (multiply monitors)? Pin
molda7-May-09 5:06
molda7-May-09 5:06 
AnswerRe: How to put powerpoint on different displays (multiply monitors)? Pin
OriginalGriff7-May-09 5:11
mveOriginalGriff7-May-09 5:11 
GeneralRe: How to put powerpoint on different displays (multiply monitors)? Pin
OriginalGriff7-May-09 5:46
mveOriginalGriff7-May-09 5:46 
GeneralRe: How to put powerpoint on different displays (multiply monitors)? Pin
molda7-May-09 6:17
molda7-May-09 6:17 
GeneralRe: How to put powerpoint on different displays (multiply monitors)? Pin
Luc Pattyn7-May-09 7:18
sitebuilderLuc Pattyn7-May-09 7:18 
GeneralRe: How to put powerpoint on different displays (multiply monitors)? Pin
OriginalGriff7-May-09 8:19
mveOriginalGriff7-May-09 8:19 
AnswerRe: How to put powerpoint on different displays (multiply monitors)? Pin
Luc Pattyn7-May-09 7:17
sitebuilderLuc Pattyn7-May-09 7:17 
GeneralRe: How to put powerpoint on different displays (multiply monitors)? Pin
molda7-May-09 21:40
molda7-May-09 21:40 
GeneralRe: How to put powerpoint on different displays (multiply monitors)? Pin
Luc Pattyn8-May-09 0:40
sitebuilderLuc Pattyn8-May-09 0:40 
QuestionPlease help with NHibernate. Could not compile the mapping document. Pin
Nopo7-May-09 4:45
Nopo7-May-09 4:45 
QuestionWatermarking over Video Pin
anki1237-May-09 3:19
anki1237-May-09 3:19 
AnswerRe: Watermarking over Video Pin
Rajesh R Subramanian7-May-09 3:26
professionalRajesh R Subramanian7-May-09 3:26 
QuestionRemove duplicate nodes from xml using c# Pin
ipstefan7-May-09 2:56
ipstefan7-May-09 2:56 
AnswerRe: Remove duplicate nodes from xml using c# Pin
musefan7-May-09 4:26
musefan7-May-09 4:26 
GeneralRe: Remove duplicate nodes from xml using c# Pin
ipstefan7-May-09 6:00
ipstefan7-May-09 6:00 

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.