Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In vb6 I used to use ObjPtr(functionname) to get the address of a method inside a class, is there some (low level or undocumented ok, but as direct [fast] a means as possible). The reason is I'd like to try and patch vtable and push some asm into the method..
As for Delegates, I did a test in this article:
http://www.codeproject.com/KB/audio-video/PWR.aspx
Turns out it takes delegate to RtlMoveMemory -10* longer- to move a byte array then a straight copy, (way too much idiot proofing in .Net). So.. delegates are out. Anything undocumented? Is there a way to get class address so I can try GetProcAddress?

thanks,
John
Posted
Updated 12-Jan-12 8:39am
v4
Comments
Kethu Sasikanth 12-Jan-12 13:29pm    
Try unsafe in c#. I have seen samples getting data pointers using unsafe, but i think it's possible to get a function pointer too.
Sergey Alexandrovich Kryukov 12-Jan-12 13:53pm    
Hm... :-) better not. No, don't do it. There are delegates, much superior to function pointers.
--SA

Look at Delegates[^] - they are effectively function pointers under a different name, but with parameter type safety built in.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 12-Jan-12 13:53pm    
Well, basically... a 5.
--SA
Wonde Tadesse 12-Jan-12 17:29pm    
5+
This gets me a handle (to something), but is probably too slow:

C#
private GCHandle _hndCompare;
private IntPtr _addCompare;

public Utils()
{
    Object mcmp = (Object)this.Compare("","");
    GCHandle _hndCompare = GCHandle.Alloc(mcmp, GCHandleType.Pinned);
    IntPtr _addCompare = _hndCompare.AddrOfPinnedObject();
}

public int Compare(string str1, string str2)
{
    int ret = 0;
    return ret;
}

~Utils()
{
    try
    {
        if (_hndCompare.IsAllocated)
        {
            _hndCompare.Free();
            _addCompare = IntPtr.Zero;
        }
    }
    catch { }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900