Re: A simple cast.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Doron Holan [MS] (doronh_at_nospam.microsoft.com)
Date: 02/26/04


Date: Wed, 25 Feb 2004 22:26:59 -0800

yes, you can always take the address of a function. the question is whether
you can cast it to PVOID or only store it under the correct pointer type

-- 
This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only.
"J.P. Iribarren" <famirib33@free.fr> wrote in message
news:c1hpia$me5$1@s1.read.news.oleane.net...
> I. Omega wrote:
> > if I want to print the address of on integer, for example, I can just
> > use:
> > fprintf( exportFile, "Address: %i\n", &m_iMyInt );
> >
> > I need to print the address of a long function.
> > I have a class MyClass, and I have instantiated it in the variable
> > mySuperClass.
> >
> > MyClass mySuperClass = new MyClass();
> >
> > Now I have a long function:
> >
> > long MyClass::CoolFunction( int thisInt, byte byteArray[], float
> > thisFloat );
> >
> > So, how do I find the address of this function?
> >
> > mySuperClass->CoolFunction( anInt, aByteArray, aFloat );
> > Okay, I can call it like this, but what kind of cast can I use to
> > determine its address and export with frpintf?
>
> I hope I'm not misleading you, but as far as I can tell, provided
> CoolFunction *is not virtual*, you can use the following syntax...
>
>     &MyClass::CoolFunction
>
> ... to get the address of CoolFunction.
>
> For further info, search MSDN and/or Google Groups for "C2276", which is
> the compiler error you get when you try to use the address of a virtual
> function.
>
> HTH,
> --
> Jean-Paul Iribarren (aka JPI)
> Anti-spam: ma véritable adresse électronique ne comporte pas de
> chiffres;donc...
> Anti-spam: my real e-mail address has no digits; consequently...
>


Relevant Pages

  • Re: Strange requirement of IConvertible from XML serializer
    ... I am trying to extract the essential part of the code that would reproduce ... MyClass, but the second fails. ... >> to cast serialized class from object to a type. ... I check in debugger that the type is correctly loaded. ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Unique GUID for an asynchronous task
    ... I am using SendAsync; userToken is the second argument of SendAsync. ... myClass mailid = e.UserState; ... you simply cast the UserState property back to the appropriate type. ... If you have a more complex data structure, you pass an instance to your data structure and then cast back to the data structure type. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# equivalent to TryCast
    ... double cast ... static void Main(stringargs) ... B myclass = new B; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# - auto-creating variables
    ... Dictionary < int, MyClass> ... thx again. ... so you don't need to cast the elements. ...
    (microsoft.public.dotnet.framework.aspnet)