I have a VS2005 solution project which consist of two dependent project. This project is a C console application which communicates with a device and gets some outputs from it. This project is an old project and it does not written by me. I am an Electrical-Electronics Engineer and mostly I use C language for projects. I do not know so much about C++ and C#. For some time I am dealing with VS2010 and c++ form applications. I get the basics but I have some problems. I want to add gui for this console project. I have designed a form applicatiom for this purpose. I have buttons to start the process in console application and RichTextbox for outputs.
I must call a function inside console project from winform application by clicking a button. I want to call that function in a loop for continuous readings.
I have tried to call "console.exe" file and run it inside my winform project and redirect the outputs to richtextbox but it was too slow for my projects. I have to do continuous speedy reading from my device.
What is the best way to do this? I want to convert my C console application to windows form application.
Thank you.
You cannot call a function inside of an EXE directly from another EXE.
You have several options here, depending on how much work you're willing to do and what the long-term goals of your old project is.
Simply copy the relevant code from your console project to your forms project; this works best if your console project is being obsoleted and you no longer plan to support it.
Move the relevant code from your console project into a library (DLL) project, and reference it from both your console and forms application; this works if the code in your console project is relatively isolated (e.g. you don't have a lot of global variables etc.)
Add some kind of IPC mechanism to your console project (listen on a TCP socket or named pipe, etc.) that you can connect to from your forms project and get data directly; this is as close as you can get to your original goal of "call a function in one EXE from another EXE" but it's significantly more work.
As C is a subset of C++, you should be able to compile your C source code from the CLR program into your C++ project, using it as a library that you can call directly from your gui. Check out this question for how to get started on doing this.
You should be able to use the C code almost exactly as it was used before, though it will most likely require some tweaking. Here's another related stack overflow question.
Typically you would move or convert your existing logic from the console app to a class library project. Then you would include a reference to this class library into your forms project. Next in your forms project you call your library methods (when you press a button for example) from another thread in order not to block your UI thread. ATTN! When updating your RichTextBox with the results you'll have to call the Invoke method to do the cross-thread operation (see here for a related topic).
Related
Recently I started to have a look at the GTK library in C, and wanted to create GUI application. In fact, I want to create an image application, but I don't know how to make my application looking exactly the same as my drawing, I've looked throught the gtk3-demo and also the widget factory but problems remains;
How to create GUI application, how do I know which container should I use, how do I know what kind of widget ? etc... So I have a picture of what I want to do, but I have absolutly no idea how. What is the process, what question should I ask myself in order to get my GUI application done ? Drawing of my application link
I would very much recommend you play with the Gtk3 GUI using python. You can interactively create windows, containers. Even later, it is much faster to develop the GUI in python, as many have already experienced.
Most of the Gtk3 C/C++ tutorials are available in Python too.
Glade is excellent in many cases - particularly if you want only standard behaviour of the widgets. If you even slightly wander from that straight path, things can get complicated quickly.
If it is really necessary, there are several ways to incorporate C/C++ functions into the Python GUI to make those critical apps go faster.
I want to start a Process Manager project in C and it's suppose to have a Graphical User Interface. It's my first GUI project and I have no idea about it. After some searches I found that I should use winapi32 libraries.
My question is:
Should I write my project like a Console-based one and then I add GUI to it or I should think about GUI at beginning of my project?
I would like to say that it's best to write the application as a command line application, then write a wrapper in GUI. This way you get the most flexible application with a total separation between the GUI and functionality.
But I won't say it! :-)
From my experience it's very difficult to totally seperate the GUI from the application, and thus you should built it with GUI in mind. Your code must open windows, report progress, react upon GUI events, so you must be well familiar with the GUI system you use.
But you must also maintain a separation between the GUI and the functionality as much as you can. For example, make your callbacks short, and direct the funcionality to non-GUI parts of the application. If you need to report progress during long calculation, pass a callback to the calculation algorithm instead of mixing GUI progress commands within the algorithm.
You also must bear in mind that most (if not all) GUI system can do GUI commands only within the main application thread, and build the program accodingly.
So in summary - yes, think about GUI at the beginning, it will be easier this way, but also keep a good separation between the GUI and the functionality,
Why changing the program during development? Just design it like it should be in the end.
You could design your program in a way that enables you to use both, text and graphical user interface. Offer an abstracted interface to the core functionality and use it from the text and the graphical interface.
If you want start top-down and not bottom-up you should choose whatever you prefer to start with a text or graphical interface that calls stub-versions of your interface.
Why write your project like a console-based one, since it's gonna end up with a GUI?
If there are any things you want to try it out first (like you don't know how to do a,b or c), sure you can implement that as a side project.
But as far as your main Project goes, that's what I'd do :
Carefully plan and design
What is it gonna do?
How are you gonna do it?
What should the User Interface contain in order to fully accomodate what you need
Coding
Test and Debug.
Repeat 2 & 3 until perfectly satisfied.
Hint :
A. I wouldn't suggest you to add your GUI to an existing console app, 'coz this will most likely lead to messy code and/or a messy UI.
;-)
B. Always study before trying to implement anything. You simply can't imagine how much your knowledge of what can be done
influences what you can do (and most likely what you'll end up doing).
If you want to make an user interface, you can use QTCreator or Visual Studio forms projects...
QT is an excellent way to make cross-platforms and cute interfaces... Visual Studio forms are usable only in windows platforms.
When you're working with any of these technologies you have to put "componentes" in a "window" a then code them...
I'm really curious to know which off-the-shelf WPF library this program is using for its web interface.
I'd like to use a few of the components in a small, in-house .NET program I'm writing.
Here is a couple of images showing the program in question (and if you don't know what WPF library this one is based on, please feel free to recommend your favourite).
Get a copy / trial. Look at the dll's downloaded. Third party components have very recognizable names (after all there are only some players there anyway).
I'm starting to make my first C program in awhile using GTK+. I've learned C to some extent and I've worked with PyGTK, so I have a decent understanding of both. But, I've never created GUI program with C. Though it worked, my last GUI program was a bit of a mess because the program logic was all mixed in with the GUI stuff. I've read that it's best to write the GUI and program logic in a decoupled way so that if you switch GUI libraries, it'd be rather painless.
Is this right? Let's say I'm adding an item to a visual list. Do I have a function that adds the item to a logical list and run that in a function that looks at that list and then updates the gui?
For example,
void new_item_button_handler()
{
add_item_to_array() /* Code dealing with program logic*/
/*
* Code here to look at array and update visual list using GUI commands
*/
}
What's the general process for doing this?
Any advice would be appreciated!
EDIT:
Thanks for the advice regarding MVC. Could you perhaps explain that in the context of the example I gave? There's a lot of info on MVC out there, and I'm having a hard time trying to figure out how it applies to my code example here.
I think you're looking for the Model-View-Controller design pattern.
traditionally this is solved with an MVC pattern. however if you are not disciplined, you will see business logic creeping into your view layer.
design your package structure as best you can so that everything fits neatly into a model, view, and controller packages. make sure you have well define interfaces for sharing data between packages. make every effort to design the packages in a way that each individual package will be testable and mostly usable without depending on the other 2.
i would also encourage you to look at the IOC pattern. this will help when connecting all your packages together. it will also help during testing when you need to mock up some stub classes to test 1 package independently of the other 2. IOC is the "wiring" of your application, it lets you mix and match objects.
I am planning to make a web application, using silverlight for frontend. requirement is: this frontend will be just an empty shell, and it must be language independent. it will get everything it needs to display and use from server, therefore making it language independent.
i tried to find tutorials, but there is nothing.
as far as i understand, silverlight uses xaml for all its data, so just generating it with whatever language i want shouldn't be a problem. but i don't have any silverlight experience or knowledge, so i'm not sure what is the best way to do this. for example, i don't know how will new content be generated, and what kind of structure silverlight requires.
can anyone give me some starting points?
Your requirements are rather demanding. If i can summarise:
silverlight will be the front end (or container)
you don't know what it will be showing
the content may be dynamically generated
everything, including the visual content, will be retrieved from the server
If i have misunderstood then by all means correct me or adjust your question.
Those requirements are not trivial, especially when you have no prior experience in Silverlight. Fetching data from the server is a normal behaviour in Silverlight, but fetching any generated UI content will be a slow and inefficient use of the technology platform. Silverlight is delivered via the browser, and runs on the client. If you are going to have generated UI, then you may want to consider using straight HTML instead (you can generate the contents using ASP.Net or a scripting language such as PHP). Alternatively, you can generate your required UI views from within the Silverlight app itself by either swapping in and out the appropriate pre-built piece of UI (or controls), programmatically adding new controls into the visual tree, or by loading XAML using the XamlReader class.
This answer may or may not help you much, but like i said before - put some more specific details into your question and you will get more specific answers (either add comments under your question, or post a new more specific question if you cannot edit your current one).
Edit: i have just come across this blog article from Jeff Prosise explaining the use of the INavigationContentLoader interface in Silverlight 4 to dynamically load pages from either remotely or locally. It is a detailed write-up, with a lot of code samples, it may be of use to you.
I would suggest you start at http://Silverlight.net
The "Learn" section has lots of videos that can get you started. http://www.silverlight.net/learn/