Click here to Skip to main content
15,927,946 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to pass null to a ref bool or out bool parameter? Pin
Judah Gabriel Himango26-Mar-04 6:45
sponsorJudah Gabriel Himango26-Mar-04 6:45 
GeneralRe: How to pass null to a ref bool or out bool parameter? Pin
Heath Stewart26-Mar-04 7:54
protectorHeath Stewart26-Mar-04 7:54 
GeneralRe: How to pass null to a ref bool or out bool parameter? Pin
Judah Gabriel Himango26-Mar-04 7:59
sponsorJudah Gabriel Himango26-Mar-04 7:59 
GeneralRe: How to pass null to a ref bool or out bool parameter? Pin
Heath Stewart26-Mar-04 8:09
protectorHeath Stewart26-Mar-04 8:09 
AnswerRe: How to pass null to a ref bool or out bool parameter? Pin
leppie28-Mar-04 7:32
leppie28-Mar-04 7:32 
GeneralAnother Interop Question.... Pin
schnee2k326-Mar-04 5:23
schnee2k326-Mar-04 5:23 
GeneralRe: Another Interop Question.... Pin
John Fisher26-Mar-04 7:13
John Fisher26-Mar-04 7:13 
GeneralRe: Another Interop Question.... Pin
schnee2k326-Mar-04 7:28
schnee2k326-Mar-04 7:28 
Cool, thanks...I got it figured out, it was a toughy. Here's how it's done:

// The structures<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]<br />
public classMYSTRUCT<br />
{<br />
public uint size;<br />
public String aString;<br />
public String anotherString;<br />
public MYSTRUCT()<br />
{<br />
this.aString= null;<br />
this.anotherString= null;<br />
this.size= 0;<br />
}<br />
}<br />
<br />
[StructLayout(LayoutKind.Sequential)]<br />
public class ArrayOfPtrs<br />
{<br />
public IntPtr ptr;<br />
public ArrayOfPtrs()<br />
{<br />
ptr = IntPtr.Zero;<br />
}<br />
}


And here is the call (allong with forming up the data after the call is made:

IntPtr outArray;<br />
BaseP2P.PeerGetNextItem(something, numItems, out outArray);<br />
<br />
MYSTRUCT[] pairs = new MYSTRUCT[numItems];<br />
ArrayOfPtrs ptrs;<br />
<br />
IntPtr current = outArray;<br />
IntPtr structure;<br />
<br />
for(int i=0; i < numItems; i++)<br />
{<br />
	pairs[i] = new MYSTRUCT();<br />
	ptrs = new WinP2P.BaseP2P.ArrayOfPtrs();<br />
<br />
	Marshal.PtrToStructure(current, ptrs);<br />
	structure = ptrs.ptr;<br />
	Marshal.PtrToStructure(structure, pairs[i]);<br />
	current = (IntPtr)((int)current + Marshal.SizeOf(ptrs));<br />
}


That works great. There should be a call to Marshal.DestroyStructure(...) made in there to clear up the unmanaged memory, but there is a function in the dll that clears this memory for me, so I do not use Marshal.DestroyStructure(...).


Jason
GeneralRe: Another Interop Question.... Pin
Heath Stewart26-Mar-04 7:51
protectorHeath Stewart26-Mar-04 7:51 
GeneralRe: Another Interop Question.... Pin
schnee2k326-Mar-04 8:29
schnee2k326-Mar-04 8:29 
GeneralDataGrid, 2 (easy) Questions Pin
DougW4826-Mar-04 4:59
DougW4826-Mar-04 4:59 
GeneralRe: DataGrid, 2 (easy) Questions Pin
SapiensBwG26-Mar-04 6:20
SapiensBwG26-Mar-04 6:20 
GeneralRe: DataGrid, 2 (easy) Questions Pin
DougW4826-Mar-04 6:55
DougW4826-Mar-04 6:55 
GeneralRe: DataGrid, 2 (easy) Questions Pin
Charlie Williams26-Mar-04 7:16
Charlie Williams26-Mar-04 7:16 
GeneralRe: DataGrid, 2 (easy) Questions Pin
partyganger26-Mar-04 9:54
partyganger26-Mar-04 9:54 
GeneralCommunicating with a Thread Pin
Demian Panello26-Mar-04 4:24
Demian Panello26-Mar-04 4:24 
GeneralRe: Communicating with a Thread Pin
Judah Gabriel Himango26-Mar-04 4:51
sponsorJudah Gabriel Himango26-Mar-04 4:51 
GeneralRe: Communicating with a Thread Pin
SapiensBwG26-Mar-04 5:00
SapiensBwG26-Mar-04 5:00 
GeneralRe: Communicating with a Thread Pin
Judah Gabriel Himango26-Mar-04 5:05
sponsorJudah Gabriel Himango26-Mar-04 5:05 
GeneralRe: Communicating with a Thread Pin
Heath Stewart26-Mar-04 4:58
protectorHeath Stewart26-Mar-04 4:58 
GeneralRe: Communicating with a Thread Pin
Judah Gabriel Himango26-Mar-04 5:24
sponsorJudah Gabriel Himango26-Mar-04 5:24 
GeneralRe: Communicating with a Thread Pin
SapiensBwG26-Mar-04 5:44
SapiensBwG26-Mar-04 5:44 
GeneralRe: Communicating with a Thread Pin
Demian Panello26-Mar-04 6:45
Demian Panello26-Mar-04 6:45 
GeneralRe: Communicating with a Thread Pin
Demian Panello26-Mar-04 7:21
Demian Panello26-Mar-04 7:21 
GeneralRe: Communicating with a Thread Pin
Heath Stewart26-Mar-04 7:41
protectorHeath Stewart26-Mar-04 7:41 

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.