|
It worked, thank you very much.
|
|
|
|
|
Hello,
I am trying to save an image stream into a .bmp file or a jpeg file. I an trying to use the .NET classes in the System::Drawing namespaces.
I have some code like the following
<code>
char* buf = new char[bufSize];
dev->Grab(buf);
Byte b[] = new Byte[bufSize];
MemoryStream *ms = new MemoryStream( b );
for(int i=0; i<bufSize; i++)
{
b[i]=buf[i];
}
Bitmap *b = new Bitamp( ms );
b->Save(S"C:\\test.jpg", ImageFormat::Jpeg);
</code>
Every time i run the code the following line
Bitmap *b = new Bitamp( ms );
throws a ArgumentException:Invalid Parameter used exception.
Does any one Know Why, could it be that the Bitmap class understands that the stream is not a valid image yet because the stream only contains the row bytes... any help please...
|
|
|
|
|
Hello,
I'm confusing with pinning pointers. In the language specification of MC++ you can read about pinning pointers:
"Pinning a sub-object defined in a managed object has the effect of pinning the entire object."
So I tried to find out if this really works, because I want be sure of it when I am using pinning pointers to convert a managed char[] char c _gc[] to an unmanaged null-terminated-char pointer.
Because a char array wouln't show, when it is destroyed, I wrote a class 'O', which does so:
__gc class O
{
int m_i;
public:
O(int i) : m_i(i)
{
Console::WriteLine(String::Concat("constructor O ", m_i.ToString()));
}
~O()
{
Console::WriteLine(String::Concat("destructor O ", m_i.ToString()));
m_i=0;
}
};
Then I wrote a class 'C', containing an array of 'O' which will be pinned. And this should pin the whole object.
'C' shows when it is created or destroeyed, too.
__gc class C
{
public:
O *o[];
C()
{
Console::WriteLine("contructor C");
o = new O* [4];
for(int i=0; i<4; i++)
o[i] = new O(i+1);
}
~C()
{
Console::WriteLine("destructor C");
}
};
And now the testprog. I create an instance of 'C' an pin an element of its member 'o'.
After that I remove the reference to 'c' and invoke the GC. Non of the allocated objects (the 'C' - instance itself or the array of 'O') shold be destroued.
Because I pinned a subobject of the array - so the array mus be pinned, and the array is a (now pinned) subobject of the 'C' - Class - so 'c' must be pinned, too ..
int main()
{
C *c = new C();
Console::WriteLine("O __pin*p = c->o[0]");
O __pin*p = c->o[0];
Console::WriteLine("c = 0");
c = 0;
GC::Collect();
GC::WaitForPendingFinalizers();
Console::WriteLine("p = 0");
p = 0;
GC::Collect();
GC::WaitForPendingFinalizers();
Console::WriteLine("END _ OF _ CODE");
return 0;
}
I compiled with VS.NET 2003 an got the following output:
contructor C
constructor O 1
constructor O 2
constructor O 3
constructor O 4
O __pin*p = c->o[0]
c = 0
destructor O 4
destructor C
destructor O 3
destructor O 2
p = 0
destructor O 1
END _ OF _ CODE
This shows, that any element was destroyed, except the element of the 'O'-array, I was pointing to. But this is not pinning! :-/
At least the whole array of 'O' should still remain after GC.
I wonder if I misunderstud anything related to pinning or if I did something wrong ...
By the way, I tested pining before with a common Int32 - member variable of an __gc class (let me call it 'G'). After pinning this Int32-member and removing the reference to the containing object (the instance of 'G'), the whole object still remains after GC. So it seems pinning works when pinning a __value - type.
Is it possible that my problem causes in the same behavior why I shouldn't use the operator == to check two System::String for Equality?
(see http://www.winterdom.com/mcppfaq/archives/000124.html[^])
System::String *str1 = S"Test";
System::String *str2 = new String("Test");
System::Console::WriteLine( (str1 == str2).ToString() );
System::Console::WriteLine( (str1->Equals(str2)).ToString() );
So what's going on there? Can anybody give me an explanation?
Do pinning pointers really pin objects or is there a bug?
Thanks in advance.
|
|
|
|
|
I certainly don't know this, just guessing.
>> O *__pin*p = &c->o[0];
You are not pinning a member of the class right? you are pinning an element of the array Try pinning the variable "o" and see what happens.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
Yes of course, it seems so. with *__pin*p I have a __gc pointer - and so I have an other reference to the object.
But if I pin the variable 'o' directly, I got the compiler error C2440.
I removed the part with the 'pointer to pointer' section, because it is superfluous for my question.
Thanks.
|
|
|
|
|
I'm trying to subclass a .NET control (panel actually) in Visual C++ 2005 Express. Its been about 2 years since I worked with C++ (stupid java (school), and lovely C# have spoiled me) and I have never really done much with managed C++ or CLI. I can't get any of the new class wizards to work so I have to do it by hand. I just don't know how CLI classes are formed or how to do inheritance with CLI, I can figure out the rest from there. Thanks if you can help.
Matt Newman
What is your malfunction? - Dangeresque, too?
|
|
|
|
|
here's a quick example i knocked together for you ...
#pragma once
namespace managed_cplus
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public __gc class sClass : public System::Windows::Forms::NativeWindow
{
public: Form* frm;
public:
sClass(System::IntPtr handle)
{
this->AssignHandle(handle);
frm = dynamic_cast<Form*>(Form::get_ActiveForm());
}
protected:
void WndProc(Message* m)
{
NativeWindow::WndProc(m);
frm->Text = m->Msg.ToString();
}
};
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;
private: System::Windows::Forms::Panel * panel1;
private:
System::ComponentModel::Container * components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->panel1 = new System::Windows::Forms::Panel();
this->SuspendLayout();
this->button1->Location = System::Drawing::Point(28, 13);
this->button1->Name = S"button1";
this->button1->TabIndex = 0;
this->button1->Text = S"button1";
this->button1->Click += new System::EventHandler(this, &Form1::button1_Click);
this->panel1->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->panel1->Location = System::Drawing::Point(116, 26);
this->panel1->Name = S"panel1";
this->panel1->TabIndex = 1;
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(716, 444);
this->Controls->Add(this->panel1);
this->Controls->Add(this->button1);
this->Name = S"Form1";
this->Text = S"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
sClass* sc = new sClass(panel1->Handle);
}
};
}
hope it helps.
<font color="blue">Csharp</font> me = (<font color="blue">Csharp</font>)Dynamic_Sysop; <font color="#008000">// My Signature.</font><br><font color="#008000">$twins</font> = <font color="#008000">me.twins</font>(<font color="#800080">"Taylor"</font> , <font color="#800080">"Delta"</font>); <font color="#C0C0C0">// My twin daughters.</font><br>echo <font color="#008000">$twins</font>;
|
|
|
|
|
Ok, I think I've found my mistake. Thanks alot!
Matt Newman
What is your malfunction? - Dangeresque, too?
|
|
|
|
|
Hi all,
I'm trying to do the following :
std::queue <MyManagedClass *> m_qSomeName;
but I get the following compile error
...\Vc7\include\deque(59): error C2847: cannot apply sizeof to managed type 'TestApp1::MyManagedClass'
ok.. so I changed MyManagedClass to a non Managed Class, and now I get a different compile error:
...\TestApp1\MyServer.h(29): error C3633: cannot define 'm_qSomeName' as a member of managed 'TestApp1::MyServer'
Now I'm just trying things out, but is it not possible to use the std::queue template class in managed c++? what about other STL classes?
<EDIT>
Before anyone says, why aren't you using .NET queue/list classes. I'm geniunely curious why I am not able to use STL
</EDIT>
Thanx
|
|
|
|
|
I have not tried to store managed object pointers in STL collections, I can imagine there could be many perils in that even if it was supported.
I have used STL vector in a "mixed mode" exe project in VS 2003
std::vector<LPCTSTR> strV;
So STL will compile and execute within a mixed mode project. But as you can see I was not mixing STL and Managed types.
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
thanx for your reply Palbano,
yeh i've been able to use standard objects in an stl vector but not managed ones. oh well. i can just live with out it. would have been nice to know though
thanx
If there's one thing I've learned, it's that life is one crushing defeat after another until you just wish Flanders was dead. - Homer Simpson
|
|
|
|
|
|
Hi everybody,
I have a question about using list on c++.. I have learnt c++ 10 years ago, but I cant remember anything..
A close friend of mine send me this paper, which u can see it at the weblink below, to explain it to him.. but I could not understand what happens...
can anyone explain me whats goin on with this code, that is under "Besser" title..
http://www11.brinkster.com/nurteknik/Seite%2094.jpg
Thanks alot..
Togi
Tolga YARAMIS
|
|
|
|
|
|
|
Hi Guys,
I wish to get an alternative of CObject and Clist classes in MFC so that i can use it in my code for the Linux Platform.
Looking for Non-MFC CObject and CList Classes.
Can any one suggest me !
Thanks !
|
|
|
|
|
Try std::vector or std::list instead.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Try checking out the VFC library. It has both and makes porting to linux easy. It is in beta state but it is quite stable. It is on sourceforge. It has gui, threads, resources, and file io, and more. Web address http:\\vcf.sourceforge.net
|
|
|
|
|
Hi Guys,
I wish to get an alternative of CObject and Clist classes in MFC so that i can use it in my code for the Linux Platform.
Can any one suggest me !
Thanks !
|
|
|
|
|
If all you want is the functionality provided in those classes then for CList you could just use the STL list class. If you just want an MFC-like framework then your best bet is to try wxWidgets or Qt, both of which are cross-platform. I've not used either but presumambly they will have collection classes.
Kevin
|
|
|
|
|
Hi,
can you help me to add a System Menu (Minimize, Restore, Close icons on right corner up of a Window) into a rebar with inside a custom menu?
All application developed with C++ and Win 32 (without MFC).
Thanks.
Nando.
|
|
|
|
|
Hi,
I am using unmanaged c code from managed c++ 7 code.
I need to convert a managed c++ 7 code function pointer to a user defined fucntion pointer type which is defined in c code. For instance
I have
int CWrapper::functionA(int a, double b);
and I want to type cast it into MyFunctionPtr. where MyFunctionPtr is defined in unmanaged c code as
typedef int (*MyFunctionPtr)();
If this functionA was a c function then this typecast is valid and tested but if I do it from managed c++ 7 code, I get a linking error
Can some one help me in correcting this type cast?
Thanks
Bilal Farooq
|
|
|
|
|
Herb Sutter - Is C++ Relevant on Modern Environments?
http://www.accu.org/conference/presentations/[^]
Herb's answer...
Q: Which .NET language should you use?
Microsoft’s answer, in our Whidbey release:
• C++ is the recommended path to .NET and Longhorn.
• If you have an existing C++ code base:
Keep using C++.
• If you want to make frequent use of native code/libs:
Use C++. It’s far simpler (seamless) and faster.
• If you want to write brand-new pure-.NET apps that
rarely or never interop with native code:
Use whatever language you’re already comfortable with,
and pick based on language features. The .NET features
and Frameworks library are available equally through all
languages.
Kevin
Kevin
|
|
|
|
|
Herb says good things
And I think we actually support generics better than C# does for whidbey, but don't quote me on it.
|
|
|
|
|
I can comfirm that.
With VisualStudio 2005 (Whidbey) they will ship a whole new Version of C++, called C++/CLI.
I've seen a presentation of it at the TechEd last weekend and was simply blown away.
You get all the well known controll of C++ and all the features of C# ... like gc, ref, interfaces.
TechED Bloggers
- Newro
|
|
|
|