|
Hi,
I am using following code to read the file and put it in memory in VC++.
brFileContent->Read (abData,0,length); // Reading Bytes
Byte __pin *pbManagedData = &(abData[0]); // Get starting point of Array
axSimpleAdditionAtx1 ->SendBy(pbManagedData,3); // Send it to MFC AX
I need to read this memory pointer in MFC ActiveX how can do it; I am using following method to receive the pointer and length from Application
void VRMControl::SendBy(BYTE* ByteValue, LONG Length)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: Add your dispatch handler code here
}
From the ByteValue variable i want to read my data; please help me out.
|
|
|
|
|
I am trying to create something along the lines this type of C++ code:
Point* myPoints = new Point[200];
I have C++ code which contains a series of points and I would like to convert them to System::Drawing::Point. I can get a single point to work:
System::Drawing::Point* thePoints = __nogc new System::Drawing::Point(1,2);
but am unable to compile when using an array of points. I have tried several different iterations using the following line of code. I've tried various versions of __gc and __nogc. I've tried System::Drawing::Point[] instead of '*'.
System::Drawing::Point* thePoints = new System::Drawing::Point[200];
Any help will be greatly appreciated. Other parts of my code work. I am able to display my C# Form from C++ just fine.
|
|
|
|
|
Try this:
Point* myPoints[] = new Point*[200];
|
|
|
|
|
Thanks for the idea. I got the following compiler error:
error C3159: 'Point' : array of pointers to value type cannot be declared
But your advice led me to the right answer. This worked:
System::Drawing::Point thePoints[] = new System::Drawing::Point[200];
As a result, I am now able to create my set of points in C++ and then have my C# Form aware of these as shown below. The method LookAtThePoints is simply a way I can quickly look at the point data and be sure what I created was successful in the C# Form.
<br />
System::Drawing::Point thePoints[] = new System::Drawing::Point[200];<br />
for (int i = 0; i < 200; i++)<br />
{<br />
thePoints[i] = System::Drawing::Point(i, i);<br />
}<br />
SimplePanel::Form1* theForm = new SimplePanel::Form1();<br />
theForm->rawPoints = thePoints;<br />
theForm->LookAtThePoints();<br />
I am doing this because we currently have an MFC application which converts laser data to 2D/GDI points. I want to start using C# Forms, so I am looking at ways I can begin creating new Views/Windows with C# and maintain our MFC app.
Thanks again for the help. It got me on the right path.
|
|
|
|
|
I need to override 'virtual void Dispose(bool disposing)' in a class packed in library that I can't recompile, just to prevent it from clearing some resources, however I can't seem to find a way to do it in C++/CLI. I get the 'error C2605: 'Dispose' : this method is reserved within a managed class'.
I'm currently using C# wrapper .dll just to solve this - 'virtual override void Dispose(bool disposing) {}' - and consume it from my C++/CLI project, but there must be a better way?
|
|
|
|
|
In C++/CLI, the dispose pattern is:
ref class Base
{
public:
Base(void)
{
}
~Base(void)
{
// Release managed resources
this->!Base();
}
protected:
!Base(void)
{
// Release unmanaged resources
}
};
So, the methods Dispose() and Dispose(bool disposing) aren't available at compile-time. Also, I believe you cannot override a virtual dtor!
-- modified at 21:45 Saturday 20th May, 2006
|
|
|
|
|
If you're doing somthing like the following in C#:
public class test
{
protected override void Dispose(bool disposing)
{
if (disposing)
{
// do A
}
// do B
}
}
Then the C++/CLI equivalent is this:
public ref class test
{
public:
~test()
{
DisposeObject(true);
}
private protected:
!test()
{
DisposeObject(false);
}
private:
void DisposeObject(bool disposing)
{
if (disposing)
{
// do A
}
// do B
}
};
Our Instant C++ C# to C++ converter maintains the original 'Dispose' method, but renames it and makes it private - called only from the new CLI destructor and finalizer. This is to make conversion easier to understand, but you could dispense with the Dispose altogether and code that logic within the destructor and finalizer directly.
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter and VB to C++ converter
Instant J#: VB to J# converter
Clear VB: Cleans up VB.NET code
Clear C#: Cleans up C# code
|
|
|
|
|
Thanks for the answers, but it doesn't exactly solve my problem:
If you take the 'test' class you specified and compile it as a C# lib .dll, and then inherit it in the C++/CLI project, how do you override the original 'test::Dispose(bool disposing)'?
It looks like there's no way to do it from C++/CLI? From the C#, you just override it.
I guess that in pure C++ something like that would not be possible at all - overriding the virtual method called from parent's destructor will still cause call to the original parent's method (or maybe compile-time error or something like that, depending on the complier)?
But I guessed that since it's possible in C#, it should be possible in C++/CLI, am I wrong somewhere?
For example, if you want to force BinaryWriter/Reader not to close the underlying stream when it's disposed, how would you do it from C++/CLI?
|
|
|
|
|
Filip Strugar wrote: But I guessed that since it's possible in C#, it should be possible in C++/CLI, am I wrong somewhere?
C# and C++/CLI are distinct languages. You can write whole ASP.NET applications with C# but not with C++/CLI. You can embedded unmanaged code in C++/CLI but not with C#.
I don't think you can override the dispose pattern in C++/CLI due to the employment of deterministic finalization in managed code.
|
|
|
|
|
Yes - after doing some research on this, it appears that it's not even possible to override the original Dispose(bool) method for a base class, due to 'Dispose' being reserved.
It's strange that this is not allowed. Even a C# class derived from a C++/CLI base class will allow overriding the implicit Dispose(bool) method generated internally by the C++/CLI class having a destructor (since a C++/CLI class will implicitly implement the IDisposable interface when containing a destructor).
If anyone knows of a way to do this (or a reason it cannot be allowed), I'd be very interested.
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C# to C++ converter and VB to C++ converter
Instant J#: VB to J# converter
Clear VB: Cleans up VB.NET code
Clear C#: Cleans up C# code
|
|
|
|
|
I have several static libraries in native c++. I am working on a new project that will use these libraries. Since this is a new project I was thinking of using C++/CLI for creating GUI using WinForms and use functionality from native static libraries. So I created a new Windows Form Application and declared an instance of a class defined [from one of the library] in the Form1.h file. It builds fine but gives a runtime exception. Then I compiled that library with /clr switch and now application runs fine.
So my question is if I want to use native static libraries from c++/cli, should I recompile all libraries with /clr switch? Or am I missing something very obvious.
thanks
-Saurabh
|
|
|
|
|
What is the runtime exception? Who is throwing it?
You should not need to rebuild all your static libraries with /clr. You only need the /clr switch for the interop files - those the bridge the native and the managed world.
gmileka
|
|
|
|
|
While I'm posting possible problems I've found...
When a struct (or class for that matter) with an Int32 ^ is deserialized an exception is thrown.
Again: Is this a "feature" that I just haven't seen documented anywhere, or an actual issue?
----CODE----
using namespace System;
using namespace System::IO;
using namespace System::Runtime::Serialization::Formatters::Binary;
[Serializable]
public ref struct TestStruct {
Int32^ i;
};
[Serializable]
public ref struct TestStruct2 {
int i;
};
int main(array<System::String ^> ^args)
{
//MemoryStream to do use for serializing
MemoryStream^ ms = gcnew MemoryStream();
//Binary Format
BinaryFormatter^ bf = gcnew BinaryFormatter();
//Create the structure
TestStruct ^t = gcnew TestStruct();
//Initialize the data
t->i = 42;
//Serialize the string
bf->Serialize(ms,t);
//GO back to the beginning of the stream to deserialize
ms->Seek(0,SeekOrigin::Begin);
try {
Object^ o = bf->Deserialize(ms);
System::Console::WriteLine("o is {0}",o);
} catch(System::Runtime::Serialization::SerializationException^ e) {
System::Console::WriteLine("Caught an exception while trying to deserialize TestStruct!");
System::Console::WriteLine(e->Message);
}
/* Generates Exception:
Type: System.Runtime.Serialization.SerializationException
Additional information: Binary stream '42' does not contain a valid
BinaryHeader. Possible causes are invalid stream or object version
change between serialization and deserialization.
Note the 42. If t->i is set to a different value, this changes.
*/
//Reset for second test
ms = gcnew MemoryStream();
bf = gcnew BinaryFormatter();
TestStruct2 ^t2 = gcnew TestStruct2();
t2->i = 42;
bf->Serialize(ms,t2);
ms->Seek(0,SeekOrigin::Begin);
try {
Object^ o = bf->Deserialize(ms);
System::Console::WriteLine("o is {0}",o);
} catch(System::Runtime::Serialization::SerializationException^ e) {
System::Console::WriteLine("Caught an exception while trying to deserialize TestStruct2!");
System::Console::WriteLine(e->Message);
}
/* No Exception Generated */
return 0;
}
----CODE END----
|
|
|
|
|
I think you need to change the defintion of TestStruct i from
Int32^ i;
to
Int32 i;
for this to work.
gmileka
|
|
|
|
|
Yes, while I agree that that does work, what I really want to know is WHY cant I use Int32^ when things like String^ work just fine.
I think there should be some documentation somehwere that says "You can't serialize certain references.. <insert list of "bad" references>" somewhere.
Myabe there already is, but i can't find it.
|
|
|
|
|
Code is self explanitory. Adding braces around the for each block fixes it, but this shouldn't be required. Unless of course you can point me to something that says this is expected behaviour.
Jody Steele
-----CODE START-----
using namespace System;
using namespace System::Collections;
int main(array<System::String ^> ^args)
{
//Define a test array
ArrayList test;
//Populate it with some data
test.Add(3);
test.Add(4);
test.Add(13);
test.Add(42);
//Works as expected: WriteLine not called
if (false)
Console::WriteLine("Test");
//Works as expected: for not entered
if (false)
for(int i=0;i<test.Count;i++) {
Console::Write("for ");
Console::WriteLine(test[i]);
}
//UNEXPECTED: for each loop is entered!
if (false)
for each (int i in test) {
Console::Write("for each ");
Console::WriteLine(i);
}
}
-----CODE END-----
|
|
|
|
|
Just in case my message about what fixes it wasn't clear:
Bad:
----CODE----
if (false)
for each (int i in test) {
Console::Write("for each ");
Console::WriteLine(i);
}
----CODE END----
Good:
----CODE----
if (false) {
for each (int i in test) {
Console::Write("for each ");
Console::WriteLine(i);
}
}
----CODE END----
But yeah... Original question still stands: Is this a "feature" or a genuine bug?
|
|
|
|
|
Definitely looks like a bug to me.
Regards,
Nish
|
|
|
|
|
Hi Friends,
Is it possible to write a parser which will find all the variable names from any program( or language specific)...and then can we change the variable name in all the files by changing variable name at just only one place
Renjith
|
|
|
|
|
IS the "Replace in files" commands in VC not sufficient for that ? Do you want to do it programmatically ?
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
All I need to do is to send a structure via SerialPort Control which needs in return an array of Bytes, and then convert it back on the other side!
Can anyone help me here
I am getting pretty desperate here
Thanks
|
|
|
|
|
Hello,
you might want to give the BinaryFormatter class a try. It allows you to serialize and deserialize objects to and from a stream. As far as i know you could then retrieve the buffer from it or even write the stream to the serial port.
You will find it in this namespace:
System::Runtime::Serialization::Formatters::Binary;
Anyway, I cannot guarantee that it will actually work, because i haven't had the time yet to test it by my own.
Best regards Tobias
|
|
|
|
|
Hi all around there!
I´ve some Problems whith comiling a managed c++ programm written in vs2003 under vs2005 whith compiler-otion /clr:oldSyntax.
error c3767 occures at line: >CmbChnl1->Events->Dispose(); or CmbChnl1->get_Events()->Dispose();
and many other lines with the Dispose()-Function.
I found out something in the msdn, but it helps not very much.
It tells me that my system-own types are in .Net V2 private now.
Sorry, it's my first SW written in .Net and it's not written by myself.
Thank's a lot for helping!
|
|
|
|
|
C++/CLI does not allow you to call Dispose() anymore. You have to use delete to dispose. For example:
delete CmbChnl1->Events;
|
|
|
|
|
That doesnt fix the Problem, i got the same error-code now, (c3767: Function is not accessable) and after that a fatal error.
I try to disable all events of a form while actualizing the Data in Comboboxes.
construction:
public __gc class TransFreqView : public ModulView //public System::Windows::Forms::Form
{
public: TransFreqView()
{
GenerateComboArray();
InitializeComponent();
GenerateComboBoxes();
__mcTemp__3 = new ArrayList();
}
.....
public: void GenerateComboBoxes(void)
{
CmbChnl1->Items->AddRange(__mcTemp__1);
.....
public: System::Windows::Forms::ComboBox * CmbChnl1;
.....
public: System::Void CmbChnl1_SelectionChangeCommitted(System::Object * sender, System::EventArgs * e);
...
cpp-File:
void TransFreqView::UpdateView(void)
{
CmbChnlSetAll->Events->Dispose(); // old: CmbChnl1->get_Events()->Dispose();
....
Thanks a lot for help!
|
|
|
|