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.

BMRAAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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 expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.