Click here to Skip to main content
15,923,374 members
Home / Discussions / C#
   

C#

 
GeneralWebcontrol inside a webcontrol Pin
ezazazel5-Mar-08 3:26
ezazazel5-Mar-08 3:26 
GeneralRe: Webcontrol inside a webcontrol Pin
Vasudevan Deepak Kumar5-Mar-08 4:34
Vasudevan Deepak Kumar5-Mar-08 4:34 
GeneralRe: Webcontrol inside a webcontrol Pin
ezazazel5-Mar-08 5:01
ezazazel5-Mar-08 5:01 
GeneralRe: Webcontrol inside a webcontrol Pin
ezazazel5-Mar-08 6:28
ezazazel5-Mar-08 6:28 
GeneralDataGridView & DataSet - Updating the DataBase Pin
half-life5-Mar-08 3:23
half-life5-Mar-08 3:23 
QuestionP/Invoking void * - is this the right way? Pin
Luca Leonardo Scorcia5-Mar-08 2:54
professionalLuca Leonardo Scorcia5-Mar-08 2:54 
AnswerRe: P/Invoking void * - is this the right way? Pin
led mike5-Mar-08 4:56
led mike5-Mar-08 4:56 
AnswerRe: P/Invoking void * - is this the right way? Pin
Luc Pattyn5-Mar-08 5:43
sitebuilderLuc Pattyn5-Mar-08 5:43 
Hi Luca,

I have used GCHandle many times to pass a reference type from managed C# to unmanaged C code;
I never needed GCHandle.Target since my object was either an instance of a class I created,
or a simple array. What really gets passed on is a memory pointer, pointing to the
managed data (which got pinned down so the GC cannot move it around any more), so the
unmanaged world can manipulate the data in the managed object.

I assume you need GCHandle.Target to get the same result when you pass on a value type
(such as the int and float in your examples); but I cannot confirm that from experience,
and I have never come across any example of GCHandle.Target till now.

However, when you know the argument is a value type, you can declare another prototype
of your unmanaged method using the ref or out keyword, and forget all about GCHandle:
reffing/outing a local value type is OK, since locals are on stack, and stack does not get
moved around, so the following should work:
[DllImport(" ... .dll")]
public static extern void H5Aread(... , out float val);
 
public int GetValueInt32(){
    int value = 0;
    DllImports.H5Aread(ObjectId, ImportedDataTypes.H5T_NATIVE_INT, out value);
    return value;}


The hearth of the matter is you can overload the method, i.e. have multiple managed method
prototypes with different parameter signatures, but all pointing to the same unmanaged
function.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.


GeneralRe: P/Invoking void * - is this the right way? Pin
Luca Leonardo Scorcia5-Mar-08 7:32
professionalLuca Leonardo Scorcia5-Mar-08 7:32 
AnswerRe: P/Invoking void * - is this the right way? Pin
Ernest Laurentin5-Mar-08 5:59
Ernest Laurentin5-Mar-08 5:59 
GeneralInvalidPrinterException when printer is installed and working - only with HP LaserJet 1010 series Pin
Dragan Matic5-Mar-08 2:22
Dragan Matic5-Mar-08 2:22 
GeneralStarting point to Crystal Reports Pin
Harvey Saayman5-Mar-08 2:16
Harvey Saayman5-Mar-08 2:16 
General[Message Deleted] Pin
Krishnaraj Barvathaya B5-Mar-08 0:52
Krishnaraj Barvathaya B5-Mar-08 0:52 
GeneralRe: How to copy files in a folder tree into a single folder Pin
pmarfleet5-Mar-08 1:26
pmarfleet5-Mar-08 1:26 
GeneralRe: How to copy files in a folder tree into a single folder Pin
Krishnaraj Barvathaya B5-Mar-08 5:48
Krishnaraj Barvathaya B5-Mar-08 5:48 
GeneralRe: How to copy files in a folder tree into a single folder Pin
Anthony Mushrow5-Mar-08 6:03
professionalAnthony Mushrow5-Mar-08 6:03 
GeneralRe: How to copy files in a folder tree into a single folder Pin
pmarfleet5-Mar-08 8:32
pmarfleet5-Mar-08 8:32 
GeneralRe: How to copy files in a folder tree into a single folder Pin
Pete O'Hanlon5-Mar-08 1:32
mvePete O'Hanlon5-Mar-08 1:32 
GeneralUnable to access SQL Reports in C#.Net windows application Pin
Vinay Babu4-Mar-08 23:20
Vinay Babu4-Mar-08 23:20 
GeneralRe: Unable to access SQL Reports in C#.Net windows application Pin
pmarfleet5-Mar-08 1:27
pmarfleet5-Mar-08 1:27 
GeneralRe: Unable to access SQL Reports in C#.Net windows application Pin
Paul Conrad5-Mar-08 4:32
professionalPaul Conrad5-Mar-08 4:32 
QuestionHow do I write to another window through a C# form [modified] Pin
Deresen4-Mar-08 23:07
Deresen4-Mar-08 23:07 
AnswerRe: How do I write to another window through a C# form Pin
V.4-Mar-08 23:48
professionalV.4-Mar-08 23:48 
GeneralBackgroundworker in .NET1.1 [modified] Pin
SPanicker*4-Mar-08 22:58
SPanicker*4-Mar-08 22:58 
GeneralRe: Backgroundworker in .NET1.1 Pin
N a v a n e e t h4-Mar-08 23:38
N a v a n e e t h4-Mar-08 23:38 

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.