0

Question as above. For example, I have a custom DLL/binary/executable file, and I want to get an array of pointers, pointing to all functions stored in this file.

I thought about (1) virtual/pure virtual functions and (2) placing functions under a specific address, but I'm not sure about the first (I'd like to use malloc and raw data loading) and I cannot make second solution easy-to-use for potential modders.

How to do this in C/C++, is this possible at all?

Thanks in advance!

  • how do you want to catch the functions? each one has different signature. – David Haim Jul 20 '15 at 08:42
  • 1
    Could you please provide more information about why do you need these pointers and what are you going to do with them? Do you want to implement a system to load mods to your application? – stgatilov Jul 20 '15 at 08:44
  • 4
    "*I thought about virtual/pure virtual functions and placing them under a specific address*" you really deserve your name creepyman900. –  Jul 20 '15 at 08:46
  • @DavidHaim What do you mean by "catching" functions? – creepyman900 Jul 20 '15 at 08:47
  • how do you want the pointer to the function to look like? GetProcAddress returns void* and it expects you to know what signature the function has – David Haim Jul 20 '15 at 08:48
  • @stgatilov Exactly, I want implementation like this. I just have troubles with getting pointers to custom calls. – creepyman900 Jul 20 '15 at 08:49
  • @DavidHaim It has to look like `int ( *function )( void* )` if you mean this. – creepyman900 Jul 20 '15 at 08:52
  • *ALL* the functions in the DLL are with this signature? int ( function )( void ) – David Haim Jul 20 '15 at 08:53
  • Well, potential modder will have to declare them like that. I'm not an expert, and I don't know another solutions for that ;) – creepyman900 Jul 20 '15 at 08:57
  • well, you can enumerate the functions of the dll with some ugly hack that gives their names. you can use GetProcAddres on them but it only return void*. you have to know their signature on the first place,. – David Haim Jul 20 '15 at 08:59
  • @knm241 Sorry for my bad english; it had to be 2 different solutions. – creepyman900 Jul 20 '15 at 09:00
  • @DavidHaim So there isn't any simple way to do what I want? – creepyman900 Jul 20 '15 at 09:02
  • Don't mind :) It is just that you are using a very confusing terminology, I can't really figure out what you want to do. If you just want to export a bunch of functions from a DLL just mark them for exportation and you can get their address with `GetProcAddress` using ordinal numbers or names. Then cast the `void*` to the appropriate function pointer. –  Jul 20 '15 at 09:06
  • So thank you, I will try, and when succeed I'll post the proper solution, just in case that somebody has same problem. :) – creepyman900 Jul 20 '15 at 09:12
  • I can post an answer about how to implement modding system. However, your current question is more specific and a bit meaningless. If you are interested in modding systems, maybe you could provide more detail in question? – stgatilov Jul 20 '15 at 09:22
  • @stgatilov It's just my small game engine, I wanted this as a test modding system. But thanks ;) – creepyman900 Jul 20 '15 at 09:29
  • See http://stackoverflow.com/questions/1128150/win32-api-to-enumerate-dll-export-functions for how to see all EXPORTED functions in DLL using WinAPI. – stgatilov Jul 20 '15 at 09:32

1 Answers1

0

Well, you can't get "all" functions in a file, because that's typically a bit ill-defined. And besides, what would you do with __new_behind_the_scenes(__some_type_you_dont_understand&)?

You are of course free to export void(*ptrs[23])(void*), and it wouldn't be excessively hard to fill that array. What would be hard is to do something useful with such an API. And it will be hell for modders. Do they need to remember tho call ptrs[16](&Widget) to default-initialize a widget and ptrs[17](&Widget) to destroy it again?

MSalters
  • 173,980
  • 10
  • 155
  • 350