|
I'm not sure why you'd post this on a Managed Visual C++ message board.
In Visual C++, the CRT function _outp() is declared in <conio.h>
I can't see what header files you've included in your code.
There's a Sleep() (with a capital S) Windows API
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: I'm not sure why you'd post this on a Managed Visual C++ message board.
Liar
|
|
|
|
|
|
Hi
I don't know the answer to Shaleen's question but I have a question of my own.
1. I'm also writing a program for parallel port communication in Win XP. I've used the code in http://www.codeproject.com/system/AsefPortAccess.asp as a guideline.
2. When running the program, the line "_outp(0x378, iByte);" gives an error. On debugging I tracked the error to the assembly code line "1022CC4B out dx,al" which gives the error "Unhandled exception in ParallelComm.exe (MSVCRTD.DLL): 0xC0000096: Privileged Instruction."
I'd appreciate it if someone could help me out here
mirispearl
|
|
|
|
|
hi,
when I tried to compile the following simple C++ program,
#include<iostream.h>
main()
{
cout << "Hello World!";
return 0;
}
got the error as
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/backward/iostream.h:31,
from hello.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
/tmp/cc3RakqC.o(.text+0xd): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::size() const'
/tmp/cc3RakqC.o(.text+0x60): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/cc3RakqC.o(.text+0x9d): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/cc3RakqC.o(.text+0xc8): In function `std::__verify_grouping(char const*, unsigned int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator[](unsigned int) const'
/tmp/cc3RakqC.o(.text+0x121): In function `main':
: undefined reference to `std::cout'
/tmp/cc3RakqC.o(.text+0x126): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/cc3RakqC.o(.text+0x152): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init()'
/tmp/cc3RakqC.o(.text+0x181): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init()'
/tmp/cc3RakqC.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
I am using cc hello.cpp to compile the program
When I tried with the command g++ hello.cpp,got the message
In file included from /usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/backward/iostream.h:31,
from hello.cpp:1:
/usr/lib/gcc/i386-redhat-linux/3.4.3/../../../../include/c++/3.4.3/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
After using g++ hello.cpp for compilation,I ran a.out to see the output,but I got '-bash: a.out: command not found' error.
Please help me out in compiling this.
Regards,
Vasudha
|
|
|
|
|
First of all, you are in the wrong forum. Please ask this type of question in the C++ forum not the C++/CLI (Managed C++) one. I believe you need to use: #include <iostream> rather than #include <iostream.h> , which is deprecated, as the error message suggests. Also, cout is found in the std namespace.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
There was discussion with my fried about inheritance. He argued with me that inheritance is not for reuse. He is telling that inheritance is for extendibility and specialization. But I may books it is referred that inheritance is for reuse.
So I like some experts to explain this in details.
When I go ogled I got both the answer that is some people are telling that is for reuse, while others are telling that, it is for specialization and expandability.
Thanks in advance,
Nandu
|
|
|
|
|
Hi,
it depends on your definition of reuse.
1.
if you copy-and-paste some code from app1 to app2, are you reusing it ?
2.
if you need some class, and later on you create a more specialized class using
inheritance because you actually need both classes, then you are specializing,
expanding and reusing at the same time. Here reuse means the specialized class
is inheriting existing code that it does not contain itself.
3.
if you have app1 with class1 and app2 with class2, and then discover a lot of code
if common to both class1 and class2, you may be able to come up with a new
class0 that is to contain the common parts, then have class1 and class2 inherit
from it. So you reuse the common code from class1 and class2 by removing it and
inserting it in class0. class0 being more general than both class1 and class2,
has a better probability of being reused-as-is in a later app3.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Same thought Luc Pattyn , but for the above answer his reply is why derive from that class0, instead we can create a object of class0 and call its methods in calss1 or calss2.
nandu
|
|
|
|
|
Nandu_77b wrote: He argued with me that inheritance is not for reuse
Don't argue with idiots. They will just drag you down to their level and beat you with experience.
|
|
|
|
|
led mike wrote: Don't argue with idiots. They will just drag you down to their level and beat you with experience.
And I have the scars to prove it.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Hi George,
Can you please give me some proves.
Thanks
Nandu
|
|
|
|
|
Nandu_77b wrote: Can you please give me some proves.
You mean like this[^]
If I were you I would report to my ISP that Google doesn't work. I would not put up with paying for internet access that doesn't include the most powerful internet tool today.
|
|
|
|
|
Hi All,
From the above discussion we can conclude that INHERETANCE is for both code reuse and specialization as well.
If any one don’t agree with this please ..raise the concerns.
Thanks,
Nandu.
|
|
|
|
|
Hello, i need to creat an array or matrix of short (16 bit) from matrix of integer (32 bit) where all the members of the int matrix are not bigger then short, i mean we will not have a problem. the problem is that i need to do it fast because i have a real time software and i dont want to just loop and copy from all members of array...
could anyone help?
|
|
|
|
|
Hi,
1.
you can't convert a matrix the way you want without looking at all the values.
2.
an array of shorts is smaller than an array of ints (it takes half the amount
of memory or disk space, needs half the time to transmit, etc); it is not
necessarily faster though, since all computations normally use int anyway.
3.
more contextual information might result in better answers.
What is it you want to do ?
How big if the array ? (and how many are there)
What is real-time ? How much time are you willing to spend ?
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Why are you writing real-time software in C++/CLI?
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I created a Windows Forms Application, put a TextBox and a Button on it. When I press the Button its event handler calls a function in another CPP module in my project that does the whole bunch of work. As it is doing that work I want it to send some progress text messages to the TextBox on the Form. How can I do this? This was a simple task before as I just used pointers, but with Managed C++ I just can't figure it out. Can somebody help, please?
|
|
|
|
|
Take a look at GetFunctionPointerForDelegate() in MSDN. You define a delegate in managed code, get a function pointer for it, cast it as function pointer for the native function, and then hand it off to the native code to use as a callback into your managed code.
|
|
|
|
|
Michael, thanks a lot for your reply. I did try delegates even before my desperate call for help and now I tried it again, but still no luck. Here is what I put on top of my Form1.h:
<br />
delegate void MyFormMethod (void);
typedef void (*PFUNC)(void);
<br />
PFUNC pFunc (void);
Then in the form's constructor I do this:
<br />
public:<br />
Form1(void)<br />
{<br />
InitializeComponent();<br />
<br />
MyFormMethod^ m = gcnew MyFormMethod(this, &Form1::MyMethod);
IntPtr pint = Marshal::GetFunctionPointerForDelegate (m);
PFUNC pFunc = (PFUNC)pint.ToPointer ();
}<br />
So far so good, but if I try to use pFunc () anywhere in the code the program does not link. Even if I use it in the same Form's Button handler I get an error:
error LNK2028: unresolved token (0A00000A) "void (__clrcall*__clrcall pFunc(void))(void)" (?pFunc@@$$FYMP6MXXZXZ) referenced in function "private: void __clrcall My2::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@My2@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@@Z)
There is just no simple example anywhere that I could start from. I saw the console app examples where they create a delegate in the main() function and then use it in that main() function. That works, but when I try to move the same concept into my form... There should be some obvious problem in my understanding of things, could you please point me to it?
Many thanks!
Eugene
|
|
|
|
|
I highly recommend getting Nishant Sivakumar's "C++/CLI In Action" book if you're looking for examples. He covers a lot of confusing stuff with remarkable clarity and brevity.
How are you using pFunc ? It's a pointer for the native code to use. If you want to use a native function pointer, you'd use GetDelegateForFunctionPointer() in managed code.
Also, I'm not certain, but I'm concerned about the scope of your variables. When m goes out of the scope of Form1(void) it may be garbage collected.
|
|
|
|
|
Thanks, the book I am working with now is "Pro Visual C++/CLI" by Stephen Fraser, but I will look into the book you recommend too.
I see, I guess I am trying to use pFunc() in the managed code itself. But you know, it actually works if I call pFunc() right at the end of the Form constructor. I get a warning message box that it is unsafe to call function pointers from managed code, but when I click "Continue" the pFunc() is actually called, it does its work and returns properly. However, if I call pFunc() from the Button handler of the Form or from elsewhere the project does not even build:
public:
Form1(void)
{
InitializeComponent();
MyFormMethod^ m = gcnew MyFormMethod(this, &Form1::MyMethod);
IntPtr pint = Marshal::GetFunctionPointerForDelegate (m);
PFUNC pFunc = (PFUNC)pint.ToPointer ();
<code>pFunc();
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
<code>pFunc();
}
It's a good point about m garbage collected at some point. Although it should be OK since I only needed it at the time I extracted pointer out of it. Then the pointer is stored in pFunc, which is global and should not get deallocated.
By the way, should we be even talking about calls between managed/unmanaged code here? My test app in my example is just a plain WinFormsApp "Hello World" example (should be all "managed") with a few mods: I put function foo() in my WinFormsApp.CPP with the code to access something on the form (in Form1.h), say a textBox . I press the button to call foo() and foo() writes some text, that's it. I cannot use Form1::textBox::Text = "Text" in foo() , I tried to create a new public method in my Form that does this->textBox->Text = "Text" , but the compiler says "cannot access a non-static member". OK, I make my method static but then I cannot access the textBox from it anymore: error C2597: illegal reference to non-static member 'System::Windows::Forms::Form::Text' .
Of course, I will keep reading and searching for the example that does exactly what I am trying to do, but the solution to my problem should be very simple. Maybe it is so simple that they do not explain it in the books. If someone could just tell me what I am missing...
Thanks!
Eugene
|
|
|
|
|
I'm sorry. I took "This was a simple task before as I just used pointers" to mean that you had existing native C++ code calling the C++ module that does all the work and were moving that existing code into C++/CLI.
In your case, you can define an event to update the text:
delegate void UpdateText( String^ );
ref class SomeClass
{
public:
event UpdateText^ OnUpdateText;
};
public ref class Form1 : Form
{
public:
Form1()
{
InitializeComponent();
someClass_ = gcnew SomeClass();
someClass_->OnUpdateText += gcnew UpdateText( this, &Form1::UpdateTextHandler );
}
private:
SomeClass^ someClass_;
void UpdateTextHandler( String^ text )
{
textBox->Text = text;
}
}; In the implementation of SomeClass , call OnUpdateText( "New text" ) when you want to update the text.
-- modified at 22:59 Monday 13th August, 2007
[Some corrections made to above code.]
|
|
|
|
|
Well, it did not work exactly as was written, but certainly led me to the working code, thank you very much!
However, the solution I finally got seems ugly to me:
<font color=green>
<code>public</code> delegate void UpdateText( String^ );
<font color=green>
<code>public</code> ref class SomeClass
{
public:
event UpdateText^ OnUpdateText;
};
public ref class Form1 : Form
{
public:
Form1()
{
InitializeComponent();
someClass_ = gcnew SomeClass();
someClass_->OnUpdateText += gcnew UpdateText( UpdateTextHandler );
}
private:
SomeClass^ someClass_;
void UpdateTextHandler( String^ text )
{
textBox->Text = text;
}
<font color=green>
System::Void button1_Click (System::Object^ sender, System::EventArgs^ e) {
void foo (String^ Text);
foo ("Text for textBox");
}
};
Now here is MyCode.CPP:
#include "stdafx.h"
#include "Form1.h"
using namespace EventTest;
<font color=green>
<code>public ref class MyClass: public SomeClass
{
public:
void MyClass_UpdateText (String^ Text) {
SomeClass^ EventKeeper = gcnew SomeClass;
EventKeeper->OnUpdateText (Text);
}
};</code>
void foo (String^ Text) {
MyClass^ y = gcnew MyClass();
y->MyClass_UpdateText (Text);
}
Question #1: does it really have to be that twisted-complicated or it is just me being a beginner? To update a property on a Form from outside the Form I need to create and delegate an event, that has to be a member of SomeClass. Then to fire this event we have to create a new MyClass based on SomeClass with the actual event handler code and create an instance of it. And only then we can raise this event. Wow! Did I get it right or there is an extra step here?
Question #2: If SomeClass is declared in front of Form1 then I cannot use the form designer. It says: The class Form1 can be designed, but is not the first class in the file. Visual Studio requires that designers use the first class in the file. Move the class code so that it is the first class in the file and try loading the designer again. But I cannot move it anywhere else because it must go before Form1() constructor as it uses this class, right? Is this something I just have to live with or there is a better way?
Sorry for the lengthy description but as I am getting to the bottom of this issue (it's been 2 days) I'd like other people who search for the same answer can read this thread and see something that actually works. I really appreciate the time spent on helping me, hopefully this will help a few more people!
Thanks again
Eugene
|
|
|
|
|
You are definitely doing too much regarding Question #1. You don't need to create an object every time you need to fire an event. I'm sorry my example code wasn't better. I just typed it into a text editor. I should have grabbed it from a working project.
Regarding Question #2, there's definitely a better way. I just stuck everything into one place for simplicity. I'd only confuse you more if I tried to describe a better way, so I'll make a working example in C++/CLI and send that to you.
-- modified at 22:39 Monday 13th August, 2007
To be a little clearer and more correct, here's the form class with irrelevant stuff stripped out:
#include "WorkerClass.h"
namespace WinApp1
{
public ref class Form1 : public Form
{
public:
Form1()
{
InitializeComponent();
workerClass_ = gcnew WorkerClass();
workerClass_->OnUpdateText += gcnew UpdateText( this, &Form1::UpdateTextHandler );
}
private:
TextBox^ textBox_;
Button^ button_;
WorkerClass^ workerClass_;
void button__Click( System::Object^ sender, System::EventArgs^ e )
{
workerClass_->DoSomething();
}
void UpdateTextHandler( String^ text )
{
textBox_->Text = text;
}
};
} And, in another file called WorkerClass.h, here's WorkerClass , which was SomeClass in my previous example:
namespace WinApp1
{
delegate void UpdateText( String^ );
ref class WorkerClass
{
public:
event UpdateText^ OnUpdateText;
void DoSomething()
{
++serialNumber_;
OnUpdateText( Convert::ToString( serialNumber_ ) );
}
private:
int serialNumber_;
};
} You don't need to derive your class from WorkerClass . All you need is an event of type UpdateText^ to which Form1 can attach a handler.
|
|
|
|
|