|
Hi, I'm fairly new to C++ and I have a tricky problem with a program I am writing.
I have a loop in place to it keeps showing the data, but I would like a way for the user to be able to stop that.
I have got a snippet of code to pause a program, and want to see if i can use it for this.
void pause()
{
std::string response;
std::getline(std::cin, response);
goto (whatever);
}
Basically, as you can tell, when the user presses enter, the program goes to another point. or at least I think it does.
Any help would be much obliged.
|
|
|
|
|
You need to post your question in the Visual C++ forum. You only get C++/CLI (.NET Framework) answers here!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
|
I really hope I'm not asking a question that has already been answered, I've searched and couldn't find an adequate answer so thought I'd ask and hope that those that understand this technology much better than me can help me out.
The problem: I have a program written in MFC, I want to remove a portion of it and wrap it into a .dll, including an object with over 200 properties and forms so that this common code can be accessed from the program it's currently in as well as newer programs being written in C#. Basically this DLL will allow a user to change many properties of an object and I want to pass that object back and forth between the C# programs and the MFC DLL.
Ideally I'd like to be able to create the object in the C# program, fill its properties, pass the object to the MFC DLL, allow user to edit properties, and pass back to C# program.
Is there a clean way to pass the class object or reference to it in one call without having to pass each property individually?
Thank you for any and all help!
|
|
|
|
|
MFC is natvie C++. Managed code is not. Using C++/CLI you can use both native and managed code
Native C++ (DLL) Managed Assembly (DLL)
\ /
\ /
C++/CLI Assembly (DLL)
Does that help
[modified] oops... I am lost without my CPHog.... Shog where are you man!
modified on Monday, December 10, 2007 11:41:20 AM
|
|
|
|
|
Please tell me how can we get signals or input from non computer devices into our program ?
|
|
|
|
|
r.srinivas wrote: non computer devices
You mean like a refrigerator?
|
|
|
|
|
Another naive poster gets hit with a cold one.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
can anybody tell me why the size of an empty class is 1.and i also want to know why we cant create an object for an abstract class.
Thanks in advance
|
|
|
|
|
C++ requires freestanding empty objects to have non-zero size. Most compilers automatically insert a char into "empty" objects to satisfy this. However, if your empty class is a base class then it won't add any size to the derived class object.
See: http://msdn2.microsoft.com/en-us/library/f42z47h2(VS.80).aspx[^]
You cannot create an object directly from an abstract class since it contains virtual method(s) without implementation(s).
"We make a living by what we get, we make a life by what we give." --Winston Churchill
modified on Monday, December 10, 2007 3:25:41 PM
|
|
|
|
|
Giving them the smallest possible non-zero size makes sure different objects
result in different pointer/reference values, which is what you hope to get isn't it?
|
|
|
|
|
philiptabraham wrote: i also want to know why we cant create an object for an abstract class
If you could, the class wouldn't be abstract.
It doesn't make sense to create an object of a class that
has virtual functions that are NULL.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
modified on Monday, December 10, 2007 3:15:35 PM
|
|
|
|
|
Mark Salsbery wrote: It doesn't make sense to create an object of a class that
doesn't have a complete implementation.
You can make a class non-copyable by declaring a private copy constructor (and assignment operator) without an implementation!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
right. badly worded - I changed it a bit. It took a long time
for CP to let me edit it (or reply to you ).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello!
Being new to C++/CLI I'm trying to create a MVC design pattern as a start. Sadly I'm stuck with event management. Here is my code so far:
Controller.h
<br />
#pragma once <br />
#include "Model.h" <br />
#include "View.h" <br />
<br />
public ref class Controller <br />
{ <br />
private: Model^ mainModel; <br />
private: View^ mainView; <br />
<br />
public: Controller(void) { <br />
mainModel = gcnew Model(); <br />
mainView = gcnew View(this); <br />
Application::Run(mainView); <br />
} <br />
public: System::Void Btn_Open_Click(System::Object^ sender, System::EventArgs^ e) {<br />
}<br />
};<br />
View.h
<br />
#pragma once <br />
ref class Controller; <br />
<br />
public ref class View : public System::Windows::Forms::Form <br />
{ <br />
private: Controller^ mainController; <br />
public: View(Controller^ con) { <br />
mainController = con; <br />
InitializeComponent(); <br />
} <br />
InitializeComponent() { <br />
... <br />
this->Btn_Open->Click += gcnew System::EventHandler(this, &mainController::Btn_Open_Click);<br />
...<br />
} <br />
With MCV the controller is responsible for event managment. That's why I choose to create the View with a reference to the controller.
But now I'm stuck with the EventHandler. The code above compiles fine when the last line is commented out. Of course, then there is no event handler.
So what is the correct way to do this? I just want the EventHandler in the View class to call a method in another class. How to do that?
Thanks for your help and suggestions!
|
|
|
|
|
Windows Forms is based partially on MVC design pattern but it is not a pure implementation of it. Thus, you are doomed in implementing MVC with it as your base.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
atzplzw wrote: With MCV the controller is responsible for event managment.
Other patterns can be introduced into the MVC design like a Command Pattern. Strictly speaking your controller class does NOT have to be directly hooked to the event of the user interface control.
Also have you seen this[^]?
|
|
|
|
|
|
Hi,
there is an "as" operator that returns either a new reference of the indicated type,
or a null value. Example:
public: Int32 __gc* Compare(Object __gc* object1, Object __gc* object2)
{
ProcessModule __gc* module1 = (object1 as ProcessModule);
ProcessModule __gc* module2 = (object2 as ProcessModule);
return String::Compare(module1->FileName, module2->FileName, true);
}
BTW: the above is Reflector output of an assembly based on C# code.
|
|
|
|
|
C++/CLI does not have an "as" operator like C#. You have to use dynamic_cast or static_cast.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi George,
indeed, I have no reference to the "as" keyword in C++, except for the fact
that Reflector uses it.
MSDN itself shows how to use casts to simulate C#'s as , as you indicated.
|
|
|
|
|
You can use dynamic_cast:
if (dynamic_cast<TextBox^>(control) != nullptr)
{
}
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
We're interested in subclassing a window in order to handle window messages (specifically mouse click and movement).
Our current approach is to derive a listener class from NativeWindow, assign it the handle to the window in question, and then set up a message handler to handle the incoming messages.
The behavior we’re seeing is that only a very few windows messages come down to our listener class. (Mainly WM_NCHITTTEST).
Any ideas?
|
|
|
|
|
Hi fellas
I have a program that is currently wrote in Managed C++ within the MS Visual Studio 2005 environment i was wondering if there is anyway i can migrate it to C#.NET without having to re-code it?
Any help would be majorly appricated fellas
thanks
|
|
|
|
|
Our C++ to C# Converter utility will get you part of the way there (there will be some adjustments you'll have to make, but the conversion quality is pretty good for Managed C++ or C++/CLI).
David Anton
http://www.tangiblesoftwaresolutions.com
C++ to C# Converter
C++ to VB Converter
C++ to Java Converter
C++ to C++/CLI Converter
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: converts C# to C++/CLI and VB to C++/CLI
|
|
|
|