Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
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 
QuestionStatus bar Pin
Sajjad Leo7-Apr-09 1:14
Sajjad Leo7-Apr-09 1:14 
AnswerRe: Status bar Pin
stancrm7-Apr-09 1:30
stancrm7-Apr-09 1:30 
GeneralRe: Status bar Pin
Sajjad Leo7-Apr-09 1:39
Sajjad Leo7-Apr-09 1:39 
GeneralRe: Status bar Pin
Henry Minute7-Apr-09 2:02
Henry Minute7-Apr-09 2:02 
AnswerRe: Status bar [modified] Pin
12Code7-Apr-09 3:59
12Code7-Apr-09 3:59 
Questionhow to get the currency value from a website to local database Pin
gnanam.abraham7-Apr-09 0:50
gnanam.abraham7-Apr-09 0:50 
AnswerRe: how to get the currency value from a website to local database Pin
Vikram A Punathambekar7-Apr-09 1:02
Vikram A Punathambekar7-Apr-09 1:02 
AnswerRe: how to get the currency value from a website to local database Pin
Tom Deketelaere7-Apr-09 1:10
professionalTom Deketelaere7-Apr-09 1:10 
AnswerRe: how to get the currency value from a website to local database Pin
Christian Graus7-Apr-09 1:21
protectorChristian Graus7-Apr-09 1:21 
QuestionCannot open 2 or more outlook contact detail Pin
manfree7-Apr-09 0:38
manfree7-Apr-09 0:38 
QuestionHow to Create a setup file in c#.net3.5 windows application Pin
Narendra Reddy Vajrala7-Apr-09 0:14
Narendra Reddy Vajrala7-Apr-09 0:14 
AnswerRe: How to Create a setup file in c#.net3.5 windows application Pin
stancrm7-Apr-09 0:25
stancrm7-Apr-09 0:25 
GeneralRe: How to Create a setup file in c#.net3.5 windows application Pin
Narendra Reddy Vajrala7-Apr-09 0:56
Narendra Reddy Vajrala7-Apr-09 0:56 
GeneralRe: How to Create a setup file in c#.net3.5 windows application Pin
Henry Minute7-Apr-09 2:05
Henry Minute7-Apr-09 2:05 

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.