Click here to Skip to main content
15,907,000 members
Home / Discussions / C#
   

C#

 
GeneralRe: Calling functions or checking objects of one form from another (MDI project) Pin
helkhoury25-Oct-09 10:53
helkhoury25-Oct-09 10:53 
GeneralRe: Calling functions or checking objects of one form from another (MDI project) Pin
Ekoj Lirpa25-Oct-09 12:15
Ekoj Lirpa25-Oct-09 12:15 
Questionwho can help me? Pin
Abdaqader25-Oct-09 7:34
Abdaqader25-Oct-09 7:34 
AnswerRe: who can help me? Pin
Richard MacCutchan25-Oct-09 8:02
mveRichard MacCutchan25-Oct-09 8:02 
AnswerRe: who can help me? Pin
Abhishek Sur25-Oct-09 8:42
professionalAbhishek Sur25-Oct-09 8:42 
AnswerRe: who can help me? Pin
Christian Graus25-Oct-09 9:16
protectorChristian Graus25-Oct-09 9:16 
AnswerRe: who can help me? Pin
Pete O'Hanlon25-Oct-09 12:10
mvePete O'Hanlon25-Oct-09 12:10 
GeneralRe: who can help me? Pin
Gerry Schmitz25-Oct-09 17:13
mveGerry Schmitz25-Oct-09 17:13 
GeneralRe: who can help me? Pin
Mycroft Holmes25-Oct-09 18:11
professionalMycroft Holmes25-Oct-09 18:11 
Questionwho can help me Pin
Abdaqader25-Oct-09 7:34
Abdaqader25-Oct-09 7:34 
AnswerRe: who can help me Pin
Dave Kreskowiak25-Oct-09 8:14
mveDave Kreskowiak25-Oct-09 8:14 
GeneralRe: who can help me Pin
Ekoj Lirpa25-Oct-09 8:59
Ekoj Lirpa25-Oct-09 8:59 
GeneralRe: who can help me Pin
Abhishek Sur25-Oct-09 12:09
professionalAbhishek Sur25-Oct-09 12:09 
GeneralRe: who can help me Pin
Christian Graus25-Oct-09 9:21
protectorChristian Graus25-Oct-09 9:21 
Questiontables Pin
csrss25-Oct-09 7:13
csrss25-Oct-09 7:13 
AnswerRe: tables Pin
Richard MacCutchan25-Oct-09 7:39
mveRichard MacCutchan25-Oct-09 7:39 
GeneralRe: tables Pin
csrss25-Oct-09 8:05
csrss25-Oct-09 8:05 
GeneralRe: tables Pin
Richard MacCutchan25-Oct-09 8:33
mveRichard MacCutchan25-Oct-09 8:33 
GeneralRe: tables Pin
csrss25-Oct-09 11:14
csrss25-Oct-09 11:14 
AnswerRe: tables Pin
Luc Pattyn25-Oct-09 12:32
sitebuilderLuc Pattyn25-Oct-09 12:32 
Hi,

you can't use out or ref for this.
you need one of two techniques that ensure the arrays don't get moved around by the GC:

1.
The fixed keyword (C# only): it requires the unsafe keyword, and the "allow unsafe code" compiler switch; it fixes the object, and allows you to get its pointer. Here is a C# example:
unsafe public int ArrayFixed() {
    int dim=1000;
    int[] numbers=new int[dim];
    ...
    int sum;
    fixed (int* pNumbers=&numbers[0]) {
        sum=SumArray(pNumbers, dim);
    }
    return sum;
}

[DllImport("native.dll")]
unsafe public static extern int SumArray(int* pNumbers, int count);


2.
The GCHandle class: it does not require any "unsafe" stuff; one needs to pin the object, get the pointer, and when done to unpin the object; here is a C# example:
public int ArrayHandle() {
    int dim=10000;
    int[] numbers=new int[dim];
    ...
    GCHandle handle=GCHandle.Alloc(numbers, GCHandleType.Pinned);
    int sum=SumArray(handle.AddrOfPinnedObject(), dim);
    handle.Free();
    return sum;
}

[DllImport("nativeC.dll")]
public static extern int SumArray(IntPtr pNumbers, int count);


Smile | :)

Luc Pattyn

I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


GeneralRe: tables Pin
Richard MacCutchan25-Oct-09 12:37
mveRichard MacCutchan25-Oct-09 12:37 
GeneralRe: tables Pin
Luc Pattyn25-Oct-09 12:42
sitebuilderLuc Pattyn25-Oct-09 12:42 
GeneralRe: tables [modified] Pin
csrss25-Oct-09 14:25
csrss25-Oct-09 14:25 
QuestionNOPs in disassembly Pin
Ekoj Lirpa25-Oct-09 6:34
Ekoj Lirpa25-Oct-09 6:34 
GeneralRe: NOPs in disassembly Pin
Henry Minute25-Oct-09 7:26
Henry Minute25-Oct-09 7:26 

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.