Results 1 to 15 of 15

Thread: The Addressof Operator.

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    Does anyone know EXACTLY what the Addressof operator does, I know it returns the Address of a function in a standard module and that you can't get a number out of it without passing it to a function, I also know that the pointer is process specific, but I'd like to know exactly what it's pointing to, I can get the memory out of the address and into a byte array, but I can't seem to make much sense of what it's doing, It seems to have the same size if you don't change the interface, (I'm calculating the size by having 2 copies of the function in the same module with slichtly different names and finding the difference of their pointers.) I'd really like to know what's going on.

    N.B. I'm aware how to use the addressof operator for subclassing and callback functions, that's not what this post's about.

  2. #2
    Guest
    mhh... i know that the AddressOf returns the "entry-point" of the function, mainly used for api-callbacks. i'm mad, that only sub's & functions in moduls can be used. *sniff*

    if anything wrong.... correct me =)


    taLON

  3. #3
    Lively Member
    Join Date
    Mar 2000
    Posts
    82
    from my understanding, talon is correct in that it is pointer to a "entry point" for a function. Kinda of like when you call any function from your program, all the params and a return address are pused onto the stack so the called function knows where to return execution to when it is complete. Addressof is just a way to obtain one of these pointers, but only allows you to obtain a pointer to the beginning of a function.

    then again, i could be wrong

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    This is how I understood the thing:
    When the executable is started, all functions and other procedures from standard modules are loaded into memory. (If I'm correct the ones located in object modules are loaded when the first instance of the object is loaded.) AddressOf returns a pointer to the start of the memory location the procedure is loaded. In vb there is no way to call a procedure by it's memory location, so the only use would be to pass it to an api procedure that can do.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    That's how I understood it, but it seems more complicated than that, I'm still working on this damned foreign procedure subclassing Idea and I'm trying to allocate a load of memory in a foreign process and copy the function into it, the trouble is that there is some very compelling evidence that the memory pointed to by the addressof operator is not the whole function, I haven't been brave enough copying the function into the foreign process yet, but I can allocate memory in my own process and copy the function into that then subclass a window with a pointer to the new memory.

  6. #6
    Lively Member
    Join Date
    Jan 1999
    Location
    Rochester NY, USA
    Posts
    93
    Pssst... use a language that was meant to manipulate memory like C

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    OK, Write me a detailed set of instructions how to create a dll with exported functions in VC++ and I will.

    oh yes and there's a few people on this site who wan't to know how to subclass a foreign window so could you send them all a C compiler and a book on how to program in C.

  8. #8
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    I'm getting into this topic a little late, but on that last note, it is currently impossible to sub-class a foreign window using VB. We all know this already, right?However, using other languages like C or Windows assembler it is possible to write a DLL that can do this. Now I know you're saying I really don't want to learn (ie. become an expert at) another language just to do this one thing, that should be possible in VB alone! This is where third party DLLs come in, there are tons out there that will do this for you. I bought an API book by Dan Appleman a while ago and it includes a DLL (among many others) for this specific purpose, and I believe he even included the source code (I haven't got around to looking into it yet). Besides, if you're experienced at using the API in VB (which I know you are Sam) then reading C code shouldn't be that difficult. If you really want to do heavy duty memory handling with foreign processes then I suggest looking into this book or some third-party DLLs, otherwise you will have to learn C.

    Just a thought, later.

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I got that book to. I think you are talking about the spywork controls. The book includes these controls, but most of them can't be used in the development environment because the licence is missing. The subclassing control only works from within the vb ide. As soon as you compile and try to start the exe, you get the missing license message. So although the control is great, you have to buy it and it isn't cheap.

  10. #10

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I've been looking for that Appleman book for ages, I can't seem to find a copy, (I've forgotten the title, but I think we're all talking about the same thing). The annoying thing it I can quite happily write C code, but can't seem to find any info on how to export functions and classes using VC++ (obviously exporting the functions is going to be a lot easier than doing all the COM stuff that VB does for you), I don't have any help files or anything.

    I'm mainly doing it to prove that I can, If I get the hang of doing this then there's a lot of stuff I can do that I couldn't before, I've already learnt quite a lot about the windows memory architecture researching this and I think ther'll be a lot of things that doing this will let me do.

    I don't believe it is impossible, It's just not possible using the standard dll method which is how it's done in C.

  11. #11
    Hyperactive Member
    Join Date
    Nov 1999
    Location
    Leavenworth KS USA
    Posts
    482
    If you've got VC++ 5.x or better, there's a sample at http://support.microsoft.com/downloa...lfiles/PHD.exe that could be of use/interest.

  12. #12
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Hi Sam,

    look for any articles related to:

    IOLEInPlaceActiveObject
    tab-trapping mechanism for controls created using the API


    control/object by Mathew curland of MS

    Zaf

    course i may be barking up the wrong tree - its not unknown...

    [Edited by Zaf Khan on 04-26-2000 at 10:50 PM]

  13. #13
    Fanatic Member
    Join Date
    Jan 1999
    Location
    UK
    Posts
    554
    Nope I'm right this time.....


    {;->


    Quote:
    the code then uses various arcane hacks to modify the vtable of the UserControl object, replacing the existing IOLEInPlaceActiveObject interface pointers with a new set pointing to VB functions implemented in a module, mIOLEInPlaceActiveObject.Bas. As a consequence,


    See sample:http://vbaccelerator.com/codelib/scontrol/tabtrap.htm



  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089

    No, 'tis still the tree of wrong up which you bark.

    vtable modification is a different topic, what you would be doing there is changing a pointer to a function in a class modules interface,sutch that you can use things like for each etc on a class module whereas the VB interface won't support it. This'd be great If I could create a n instance of a class module in a foreign process, but I can't.

  15. #15
    Hyperactive Member
    Join Date
    Sep 1999
    Posts
    305

    A comment on grammar

    Congratulations, Sam Finch, on your excellent grammar in the title of the previous post. Few people bother to refrain from ending sentences in prepositions, and it is a pet peeve up with which I do not put (heehee). I love seeing someone who knows English as it should be known.

    bob

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width