Click here to Skip to main content
15,905,566 members
Home / Discussions / C#
   

C#

 
GeneralRe: Threading - CPU/RAM Usuage Pin
Xmen Real 7-Apr-09 6:28
professional Xmen Real 7-Apr-09 6:28 
GeneralRe: Threading - CPU/RAM Usuage Pin
Luc Pattyn7-Apr-09 6:44
sitebuilderLuc Pattyn7-Apr-09 6:44 
GeneralRe: Threading - CPU/RAM Usuage Pin
Xmen Real 7-Apr-09 6:45
professional Xmen Real 7-Apr-09 6:45 
QuestionHow to create InstallShield with c#.net 3.5 windows application Pin
Narendra Reddy Vajrala7-Apr-09 5:48
Narendra Reddy Vajrala7-Apr-09 5:48 
AnswerRe: How to create InstallShield with c#.net 3.5 windows application Pin
Rajdeep.NET is BACK7-Apr-09 7:06
Rajdeep.NET is BACK7-Apr-09 7:06 
GeneralRe: How to create InstallShield with c#.net 3.5 windows application Pin
Narendra Reddy Vajrala7-Apr-09 22:58
Narendra Reddy Vajrala7-Apr-09 22:58 
GeneralRe: How to create InstallShield with c#.net 3.5 windows application Pin
nooraldeen1-Dec-09 19:35
nooraldeen1-Dec-09 19:35 
QuestionHow to put Text to speech output into a Direct sound 3d buffer Pin
ETEDS7-Apr-09 3:09
ETEDS7-Apr-09 3:09 
QuestionHow to Create shortcut to our application on client desctop in c#.net 3.5 windows application? Pin
Narendra Reddy Vajrala7-Apr-09 3:02
Narendra Reddy Vajrala7-Apr-09 3:02 
AnswerRe: How to Create shortcut to our application on client desctop in c#.net 3.5 windows application? Pin
Mirko19807-Apr-09 3:42
Mirko19807-Apr-09 3:42 
GeneralRe: How to Create shortcut to our application on client desctop in c#.net 3.5 windows application? Pin
Narendra Reddy Vajrala7-Apr-09 4:16
Narendra Reddy Vajrala7-Apr-09 4:16 
GeneralRe: How to Create shortcut to our application on client desctop in c#.net 3.5 windows application? Pin
Mirko19807-Apr-09 5:04
Mirko19807-Apr-09 5:04 
QuestionTransfer big file from PC to PPC Pin
E_Gold7-Apr-09 2:47
E_Gold7-Apr-09 2:47 
QuestionHow can we use AutoCompleteCustomSource for a TextBox ? Pin
Mohammad Dayyan7-Apr-09 2:43
Mohammad Dayyan7-Apr-09 2:43 
AnswerRe: How can we use AutoCompleteCustomSource for a TextBox ? Pin
DaveyM697-Apr-09 2:54
professionalDaveyM697-Apr-09 2:54 
GeneralRe: How can we use AutoCompleteCustomSource for a TextBox ? Pin
Mohammad Dayyan7-Apr-09 3:26
Mohammad Dayyan7-Apr-09 3:26 
GeneralRe: How can we use AutoCompleteCustomSource for a TextBox ? Pin
DaveyM697-Apr-09 3:41
professionalDaveyM697-Apr-09 3:41 
GeneralRe: How can we use AutoCompleteCustomSource for a TextBox ? Pin
Mohammad Dayyan7-Apr-09 3:42
Mohammad Dayyan7-Apr-09 3:42 
QuestionRetrieve array from unmanaged DLL into C# application Pin
User 127827-Apr-09 2:38
User 127827-Apr-09 2:38 
AnswerRe: Retrieve array from unmanaged DLL into C# application Pin
Nicholas Butler7-Apr-09 2:54
sitebuilderNicholas Butler7-Apr-09 2:54 
GeneralRe: Retrieve array from unmanaged DLL into C# application Pin
User 127828-Apr-09 16:41
User 127828-Apr-09 16:41 
AnswerRe: Retrieve array from unmanaged DLL into C# application Pin
Luc Pattyn7-Apr-09 3:42
sitebuilderLuc Pattyn7-Apr-09 3:42 
Hi,

If data gives a NullReferenceException, something must be wrong in the unmanaged code; here are some possibilities:
1. a silly mistake, say "return 0;"
2. your function pointer (accepting the delegate) not being defined as __stdcall
3. something going wrong with parameter alignment on stack (native long=32 bit, managed long=64 bit;
native char=8 bit, managed char=16 bit); this assumes your post was showing simplified code only.
4. IntPtr needs a 4 or 8 byte pointer, depending on Win32/Win64; your native code must match that.

As far as P/Invoke goes:

I prefer to allocate arrays, structures, objects on the managed side, and somehow pass their pointer to the unmanaged world; this has the advantage of being a managed object from the start, and not requiring any copying, and the disadvantage it is difficult to achieve when there are unknown values, such as the array size.

However, you are using a delegate to pass results, so you could instead use two delegates:
- one to inform the managed world about the array size, and ask for an array pointer;
- one to signal the managed world the array has been filled.

Passing a pointer can be done in two ways:
- with the "fixed" keyword; simple, unless the array must remain fixed afterwards, as in your case.
- with the GCHandle class; don't forget to eventually free the handle!

BTW: you were using the ref keyword, "out" would have been more appropriate.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


GeneralRe: Retrieve array from unmanaged DLL into C# application Pin
User 127828-Apr-09 16:42
User 127828-Apr-09 16:42 
QuestionMappings SSIS Pin
Bajker7-Apr-09 2:36
Bajker7-Apr-09 2:36 
QuestionExcel ADO and Cell Format Pin
pjank427-Apr-09 2:08
pjank427-Apr-09 2:08 

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.