using System.IntPtr

  • Thread starter Thread starter Sushi
  • Start date Start date
S

Sushi

I need to get a pointer of a variable...
How can I get it ?

for example:
Dim a() as CStructure
Dim z as System.IntPtr

z = ??????

Sushi
 
The Marshal class has methods to help in this.

See Marshal.UnsafeAddressOfPinnedArrayElement.

You can create and use unmananged blocks of memory with Marshal.AllocHGlobal
and it's related methods

Vou can copy to and from C structs with StructureToPtr and PtrToStructure.

HTH

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Sushi said:
I need to get a pointer of a variable...

Variables that are declared as a reference type are "type-safe pointers":

\\\
Dim f1 As New Foo()
Dim f2 As Foo = f1 ' Points to the same instance as 'f1'.
///
How can I get it ?

for example:
Dim a() as CStructure
Dim z as System.IntPtr

What exactly do you want to archieve/to do with the pointer?
 
I will try to explain better

I want to execute some TrackServer functions...
Follow the prototype

COMSVCSLib.IGetAppData.GetApps(ByRef nApps As System.UInt32, ByVal aAppData
As System.IntPtr)

So
aAppData is pointer of an array of COMSVCSLib.CAppData

In another words...
pAppData() As COMSVCSLib.CAppData
aAppData As IntPtr = pAppData


Well...
After I get this IntPtr, I will need to convert this IntPtr to the pAppData
array


Did you understand me ?

Thanks for all,
Sushi
 
You need to declare a VB structure that corresponds to the layout of the C
structure that you are passed from the unmanaged side. Once you have that
you can use Marshal.PtrToStructure to obtain the contents of your structure.
For an array of structures you need to modify the IntPtr that you have to
the offset of the particular array element that you wish to access.

Unfortunately I can't find a reference to the structure you're trying to
grab.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
thanks... I will try to create a structure in vb.net...

the reference is COMSVCSLib...
I already saw this article... but it's doesn't help me more than the object
browser for COMSVCS :-))))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top