Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C++
I have a program in visual basic and aren't sure what approach to take for the following: I have a neural network created (well options for several) but for the preprocessing I want the user to be able to specify HOW they can do it, freely, if they wish (generic options also available) by inputting c++ code.
I was thinking just a large textbox which then writes this to a file... and then reads & executes. I've found reference to doing this but don't understand how. If you could explain/know of a link to similar topic or see a better option I'd vastly appreciate it! Even if there's an easier option I'm very curious how to read a file as code.
Many thanks!
Posted 26-Feb-13 10:41am
Sergey Alexandrovich Kryukov at 26-Feb-13 15:55pm
Is it C++ or C++/CLI (.NET), where it's totally possible?
lostandconfused1234 at 26-Feb-13 15:57pm
.NET I hope. Using Visual studio basic
Sergey Alexandrovich Kryukov at 26-Feb-13 16:01pm
Then my answer will help you. I'll add some links...
Sergey Alexandrovich Kryukov at 26-Feb-13 16:03pm
Done. Please see my answer now.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

The problem is just that you have to have the compiler (and linker) with your application, because, in case of unmanaged C++, you cannot guarantee there is a compiler in the system, forget about the problem of finding this compiler and its invocation. I don't think you really want to deal with that, unless you want to use some compiler with its source code, so you could embed it in your application.
With .NET, the story is very different, as C# and VB.NET compilers are always bound with the redistributable .NET Framework and are always available (but not C++!). Then the problem is solved via CodeDOM (and Application Domains, which is mode difficult part of the problem). If you are interested, I can give you some links.
[EDIT — after OP's clarification]
Thank you for clarification. Please see my past answers:
code generating using CodeDom[^],
Create WPF Application that uses Reloadable Plugins...[^].
Some more advanced issues are explained in my past answers:
Create WPF Application that uses Reloadable Plugins...[^],
AppDomain refuses to load an assembly[^],
Dynamically Load User Controls[^],
C# Reflection InvokeMember on existing instance[^],
Gathering types from assemblies by it's string representation[^].
lostandconfused1234 at 26-Feb-13 16:05pm
@SA yes please :) I didn't consider the fact it WILL need a compiler to run, which I hold my hands up and say yes, that was stupid not to consider! It's fascinating however and a link would be appreciated
Sergey Alexandrovich Kryukov at 26-Feb-13 16:32pm
Wait a second! If this is .NET, there is nothing stupid. A compiler is also comes at run-time, to support CodeDOM.
lostandconfused1234 at 26-Feb-13 16:14pm
many thanks
Sergey Alexandrovich Kryukov at 26-Feb-13 16:33pm
You are welcome.
I hope now you can accept this answer formally (green button), will you?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

One option would be to use CINT[^].
Root[^] also have several features you may find useful.
You'll have to use P/Invoke or C++/CLI to interface with CINT, but you will be able to execute C++ code directly.
Best regards
Espen Harlinn
Sergey Alexandrovich Kryukov at 26-Feb-13 16:34pm
Even though OP mentioned, in respond to my question, that is "hopefully" can be .NET, it does not makes me sure, so your answer could be used, my 5.
Espen Harlinn at 26-Feb-13 16:42pm
When I started on my latest article: CIMTool for Windows Management Instrumentation - Part 3
I was hoping to express the code generator in a language independent manner. While I'm still using the CodeDom, it will now only output C#. Using the CodeDom is fairly convoluted, even the simplest things takes a lot of work. If it wasn't for the snippet classes, I would have rewritten the code to using a template engine.
Sergey Alexandrovich Kryukov at 26-Feb-13 16:52pm
I am not sure if I agree with you.
I do have couple of works with CodeDOM, and one of them is quite serious: I developed a core of a very unusual (CAS) Computer Algebra System, and one of the applications is the "symbolic calculator": the user can enter expressions in C# and VB.NET, and the system performs required symbolic calculations. No wonder, it is done with CodeDOM, and the API accessible to the user and passed to CodeDOM is quite advanced (with cunning way to represent symbolic expressions instead of numeric, without string data, of course).
So, there is a lot of problem in this work: CAS itself, Application Domains and associated IPC, even some UI problems, but — not a single problem with CodeDOM! I would say, this way the most smooth part, if you know its secrets, but those "secrets" are not secret, documentation was adequate... You see?
Espen Harlinn at 26-Feb-13 17:02pm
Yes, but getting things done in terms of the CodeDom certainly takes time ...
Using the compiler features is something different, and much more practical ;)
Sergey Alexandrovich Kryukov at 26-Feb-13 17:14pm
In my opinion, much less than anything else requiring compilation... I don't see where this time comes from. Development is pretty fast, runtime is pretty fast... Hard to agree with you... And also, all standard...
Espen Harlinn at 26-Feb-13 17:17pm
To generate the code required for a property with a setter and a getter:
public int SslFlags
return this.GetInt32("SslFlags");
this.Write("SslFlags", value);
You have to write something like this:
CodeMemberProperty property = new CodeMemberProperty();
property.Name = Name;
property.Type = new CodeTypeReference(GetPropertyType());
property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
if (PropertyData.Read)
property.GetStatements.Add(new CodeMethodReturnStatement(
new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(
new CodeThisReferenceExpression(), GetGetterFunctionName()),
new CodePrimitiveExpression(Key))));
if (PropertyData.Write)
new CodeMethodInvokeExpression(
new CodeMethodReferenceExpression(
new CodeThisReferenceExpression(), GetSetterFunctionName()),
new CodePrimitiveExpression(Key), new CodeVariableReferenceExpression("value")));
Sergey Alexandrovich Kryukov at 26-Feb-13 17:19pm
Sorry, I don't understand which Ssl flags you are talking about...
Espen Harlinn at 26-Feb-13 17:20pm
That's an example of the generated code ...
If I understood you correctly, you are using the CodeDom to compile C# or VB code - this is the opposite, I'm using the CodeDom to create c# code ...
Sergey Alexandrovich Kryukov at 26-Feb-13 17:26pm
That was my first though, so I was confused, because I don't see how it that related to the question or our discussion...
Espen Harlinn at 26-Feb-13 17:35pm
Ok, fair point - I'm just a wee bit frustrated with the thing ...
And it may seem like a reasonable approach for creating alternative ways to perform the preprocessing - which would be possible, but do take a lot of effort ...
Sergey Alexandrovich Kryukov at 26-Feb-13 17:38pm
That happens... :-)
I'm telling you, CodeDOM for parsing and execution of a dynamically created code (execution is more difficult due to memory leak problem, so a separate Application Domain should be used, which is a bit harder then the whole CodeDOM usage) is more then reasonable thing.
Espen Harlinn at 26-Feb-13 17:45pm
Absolutely, and yes a separate AppDomain allows you to unload the generated assembly ... btw: Have you looked at CS-Script?
Sergey Alexandrovich Kryukov at 26-Feb-13 17:59pm
Not yet, and one reason it this:
I majorly lost my interest to C# (.NET) scripts because
1) I have my own code and sure I can develop it to anything by myself;
2) I looked at PowerScrip which is amazing, especially v.3. I've done some tiny but interesting work (introduced meta-objects and a truly OOP style of scripting, in a way, more advanced then classes and hence more suitable for scripting, specifically), and looking when I get time and courage to write an article text.
Thank you very much for the reference though; I'll take a look.
Espen Harlinn at 26-Feb-13 18:05pm
If you're into PowerScript, I assume you're doing stuff related to system management - in which case I guess you'll find CIMTool quite informative, as it's certainly easier to use than MS WMI CIM Studio ...
Sergey Alexandrovich Kryukov at 26-Feb-13 18:46pm
I know. Most interesting work. Just tell me one thing: does it come with all source code? I know you are using 3rd-party: Avalon and more. Is it supposed to build all from source?
Espen Harlinn at 26-Feb-13 18:53pm
You should be able to build it from the provided source code.
It uses AvalonDock, AvalonEdit & •WPF PropertyGrid
Sergey Alexandrovich Kryukov at 26-Feb-13 18:57pm
Very, very good. I was especially interested in WPF property grid, thank you for mentioning it.
What do you think about its customization properties? I had a hard time with Forms PropertyGrid (but managed to make advanced customization, amazingly, I work in the company where my colleague did it in the past, and we're using his code now), mainly due to the awkward ComponentModel. Is this WPF component better?
Espen Harlinn at 26-Feb-13 19:13pm
The WPF Property is pretty good, I had a few surprises though; as the way it caches type information tripped me up. Calling MetadataRepository.Clear(); fixed that - and I still haven't had any performance problems related to the WPF Property grid.
Sergey Alexandrovich Kryukov at 26-Feb-13 19:17pm
I'm not sure I would be able to remember your hint, but is sounds like it makes sense.
Thank you very much for this information.
Espen Harlinn at 26-Feb-13 19:21pm
I only ran into this problem because the number, and names, of the properties of objects of the ManagementObjectWrapper class changes dynamically depending on the WMI object it represents.
Sergey Alexandrovich Kryukov at 26-Feb-13 19:36pm
That's understandable and fine. Have you been able to represent property data as a tree-like structure, as in Forms.PropertyGrid?
For example, the property of the type System.Graphics.Point is shown as a tree node, but to make it with your custom type, it needs customization of the data presentation...
Sergey Alexandrovich Kryukov at 26-Feb-13 18:01pm
Ah, by O.Shilo? Yes, I saw it before...
Thank you very much anyway...
Espen Harlinn at 26-Feb-13 18:05pm

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 195
1 Peter Leow 160
2 Zoltán Zörgő 160
3 BillWoodruff 85
4 CPallini 70
0 Sergey Alexandrovich Kryukov 9,568
1 OriginalGriff 6,901
2 Peter Leow 4,737
3 Zoltán Zörgő 4,404
4 CHill60 2,932

Advertise | Privacy | Mobile
Web02 | 2.8.150129.1 | Last Updated 26 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100