Click here to Skip to main content
16,007,809 members
Home / Discussions / C#
   

C#

 
GeneralRe: Control the setup directory for a .Net Setup package Pin
Skippums3-Jan-08 12:30
Skippums3-Jan-08 12:30 
GeneralMemory addressing Pin
damianrda3-Jan-08 5:37
damianrda3-Jan-08 5:37 
GeneralRe: Memory addressing Pin
led mike3-Jan-08 5:51
led mike3-Jan-08 5:51 
GeneralRe: Memory addressing Pin
damianrda3-Jan-08 7:27
damianrda3-Jan-08 7:27 
GeneralRe: Memory addressing Pin
led mike3-Jan-08 11:40
led mike3-Jan-08 11:40 
GeneralRe: Memory addressing Pin
Pete O'Hanlon3-Jan-08 9:54
mvePete O'Hanlon3-Jan-08 9:54 
GeneralRe: Memory addressing Pin
led mike3-Jan-08 11:42
led mike3-Jan-08 11:42 
GeneralRe: Memory addressing Pin
Luc Pattyn3-Jan-08 12:26
sitebuilderLuc Pattyn3-Jan-08 12:26 
Hi,

assuming the native function expects to get a buffer of sufficient size, this is
how you should do it:

- include a line using System.Runtime.InteropServices; // DllImport
- declare the native function as
[DllImport("myLibrary.dll")]
private extern static int ReadImage(IntPtr hObject, IntPtr pData, ulong dataSize);

- allocate an array of sufficient size (type is byte, uint, whatever you like);
- use class GCHandle methods Alloc (GCHandleType.Pinned) and AddrOfPinnedObject to get
pointer you need (an IntPtr). Pinning prevents the GC to move the array object around
until it gets freed again.
- call the native function as if it were part of your class (the extern static declaration
makes that possible)
- use GCHandle.Free to undo the pinning

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Happy 2008!


GeneralCommunicating with an USB Device Pin
haolan3-Jan-08 5:07
haolan3-Jan-08 5:07 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak3-Jan-08 5:37
mveDave Kreskowiak3-Jan-08 5:37 
GeneralRe: Communicating with an USB Device Pin
haolan3-Jan-08 8:24
haolan3-Jan-08 8:24 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak3-Jan-08 8:29
mveDave Kreskowiak3-Jan-08 8:29 
GeneralRe: Communicating with an USB Device Pin
haolan3-Jan-08 9:15
haolan3-Jan-08 9:15 
GeneralRe: Communicating with an USB Device Pin
haolan3-Jan-08 9:56
haolan3-Jan-08 9:56 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak3-Jan-08 10:54
mveDave Kreskowiak3-Jan-08 10:54 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak3-Jan-08 10:46
mveDave Kreskowiak3-Jan-08 10:46 
GeneralRe: Communicating with an USB Device Pin
haolan3-Jan-08 22:21
haolan3-Jan-08 22:21 
GeneralRe: Communicating with an USB Device Pin
haolan3-Jan-08 22:18
haolan3-Jan-08 22:18 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak4-Jan-08 1:52
mveDave Kreskowiak4-Jan-08 1:52 
GeneralRe: Communicating with an USB Device Pin
haolan4-Jan-08 7:31
haolan4-Jan-08 7:31 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak4-Jan-08 12:13
mveDave Kreskowiak4-Jan-08 12:13 
GeneralRe: Communicating with an USB Device Pin
haolan7-Jan-08 0:57
haolan7-Jan-08 0:57 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak7-Jan-08 3:08
mveDave Kreskowiak7-Jan-08 3:08 
GeneralRe: Communicating with an USB Device Pin
haolan9-Jan-08 3:40
haolan9-Jan-08 3:40 
GeneralRe: Communicating with an USB Device Pin
Dave Kreskowiak9-Jan-08 17:00
mveDave Kreskowiak9-Jan-08 17: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.