dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Instantiating objects from user independent code.

Threaded View

  1. #1
    Join Date
    Jul 2017
    Location
    Greece
    Posts
    112

    Instantiating objects from user independent code.

    I want to create a mechanism similar to what java and python does. In java and python, you can instantiate actual code (classes) that are not contained to the original code of your program and run it as it was hard-coded into you program without linking it to your actual program.

    For example lets say I have a program RunPlugin.exe that read's a config.txt file which contains paths to plugins (user defined code). Now lets say that a user creates a plugin MyPlugin by inheriting a special class which I provide (Lets name it PluginClass) in order to create his plugin. Also the user is adding in the config.txt the path of his source code.

    I want somehow my RunPlugin.exe for each source code path into the config.txt file to run the code of the user by instantiating an object of his MyPlugin class which inherits the PluginClass. I don't want the user to edit the source code of the RunPlugin.exe in order to link his code with the .exe program, i want some how to be done automatically by the program only by knowing the path of his source code or better the compiled one (maybe a dll file).

    But as far as I know, you need to edit the source code of the .exe program in order to include the class MyPlugin and instantiate an object of that classe and ofcource recompile the entire executable to link with the .dlls .lib file that the user is providing and for each plugin that a user is making he needs to update again the executable.

    Do you understand what I'm trying to achieve? I hope you do, I'm not sure if i explain what i need to do correctly

    I think this is similar of how an operating system is running the main() function of a program. That program is not part of the OS, neither you link it with the OS, but the OS somehow can call that main function and run the code inside it. How can i achieve that? How can i call a function from my program without link it with the code that has the function which i need to call?

    I found this on the internet and its exactly what i want to create:
    (If a moderator see this better change the title of my thread considering the document below because i'm sure i'm not asking what i was looking for.)

    The fact that most Java programs are written in this fashion is the result of Java's C and C++ heritage: Both C and C++ are statically linked languages, which means that all of the pieces that make up a C or C++ program must be present at the link step. Couple this with the fact that many Java programmers migrated from a C and/or C++ environment, and you can see why this type of programming is the norm. The thing is, in Java, we are not limited by the language in this way. Java, as you will soon see, allows programs to be dynamically extensible -- that is, to dynamically load in and execute new code, including code that wasn't in existence when the program was written. Sound far-fetched? It's not. What's more, I'm betting you use at least one program like this every day.
    Source: https://www.javaworld.com/article/20...lications.html


    Thanks!
    Last edited by babaliaris; November 29th, 2018 at 04:29 PM.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)