Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1200
  • Last Modified:

ObjPtr(obj) method in .Net 3.5

Hi Experts.
Please find my problem as below -
 objPtr(obj) is the method used in VB to retrieve the address of an object. This method has been supressed in .Net.  .Net approach to achieve the same can be something as follows -

                Dim obj as SFCTI.SFTSAPI
            Dim GC As System.Runtime.InteropServices.GCHandle = System.Runtime.InteropServices.GCHandle.Alloc(Marshal.SizeOf(obj), System.Runtime.InteropServices.GCHandleType.Pinned)

            Dim ret As IntPtr = GC.AddrOfPinnedObject.ToInt32

So as to Pin an object the object must be of blittable type (containing only basic types) but MyControl.MyFunction has arrays/strings/structs/enums etc hence cannot be used in above manner.

0
BMRA
Asked:
BMRA
  • 4
  • 3
1 Solution
 
Bob LearnedCommented:
May I be so bold as to ask what the "bigger picture" is here?  What are you trying to achieve, as there might be an easier way to approach this problem?
0
 
BMRAAuthor Commented:
Can you please tell that easier way to approach this?
0
 
Bob LearnedCommented:
I might be able to, if you tell me what you are hoping to achieve?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
BMRAAuthor Commented:
I'm developing an user defined control from an API and while developing that control at SetWindowLong function have to pass the address of my control.  Though my User defined control is in Visual Studio 2008 it have to use Marshalling and VBFixedLength String in it b'cause of that .Net is not able to get the address of my control.
0
 
Bob LearnedCommented:
With SetWindowLong, you would need to send the handle for the control.  Are you working with a 3rd-party, non-.NET API?
0
 
BMRAAuthor Commented:
yes am working with third party non-net APi. Please explain.
0
 
Bob LearnedCommented:
Platform Invoke (p/invoke).

SetWindowLong
http://pinvoke.net/default.aspx/user32/SetWindowLong.html

C# Signature:
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);


VB.NET Signature:
<DllImport("user32.dll")> _
Private Shared Function SetWindowLong( _
     ByVal hWnd As IntPtr, _
     ByVal nIndex As Integer, _
     ByVal dwNewLong As IntPtr) As Integer
End Function


hWnd is an IntPtr, which is also the Handle for a user control.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now