|
Aamir Butt wrote: I have a .NET Control which I want to host in a CDialog. It's quite easy by including afxwinforms.h and having a member variable like this:
CWinFormsControl<mycontrol::controlclass> m_myControl
But the problem is that if I do something like this I have to include afxwinforms.h in my header file. I am including this header file in other classes and I dont want to enable clr for those classes.
Is there any workaround to this. I have tried something like having a CWnd* as a member variable and casting it to CWinFormsControl in .cpp but type-casting for CWinFormsControl doesnt work.
You could try a #ifdef _MANAGED block to declare the CWinFormsControl member.
Regards,
Nish
|
|
|
|
|
Wouldn't that change the class layout depending on who's including it?
For example, if I include the header in a .cpp that is compiled native, the class layout does not contain the managed memeber.
If I include the header in a .cpp that is compiled /clr, the class layout contains the managed memeber...
This means they are essentially two different classes with the same name...
The linker should emit an error in that scenario and not allow it... I haven't tried it though, so I might be wrong.
gmileka
|
|
|
|
|
georgeraafat wrote: Wouldn't that change the class layout depending on who's including it?
Yes, it would. A workaround would be to use a CWinFormsControl* member if it's managed compilation, and a dummy void* if it's unmanaged compilation. Thus the class layout is unchanged.
Regards,
Nish
|
|
|
|
|
Yes, this one looks good. Let me try it and then I will let you know if it works or not. Thanks for the reply.
"Writing specifications is like writing a novel. Writing code is like writing poetry."
|
|
|
|
|
Hi,
I couldnt use System namespace inside the MFC ActiveX control page. It says name space with this name doesnt exist. What should i do to use all the class like Convert etc...
|
|
|
|
|
sivaprakashshanmugam wrote: Hi,
I couldnt use System namespace inside the MFC ActiveX control page. It says name space with this name doesnt exist. What should i do to use all the class like Convert etc...
Please ask this in the Visual C++ forum. Sorry my bad! Didn't read your post properly.
To use the namespace and its classes, you need a reference to the containing assembly.
Regards,
Nish
Last modified: Thursday, May 25, 2006 2:32:19 PM --
|
|
|
|
|
I am trying to implement a simple smtp client server model to send and recieve messages to users on a lan where the users information and their message is stored in the sql database where this information is vaalidated once a request is sent by the client
i need to implement this in socket programming.Any experts please suggest
|
|
|
|
|
vaninathan wrote: I am trying to implement a simple smtp client server model to send and recieve messages to users on a lan where the users information and their message is stored in the sql database where this information is vaalidated once a request is sent by the client
i need to implement this in socket programming.Any experts please suggest
Please ask this in the Visual C++ forum.
Regards,
Nish
|
|
|
|
|
Hi,
I am using Visual Studio 2005 to develop an MDI application in C++/CLI. The application contains both child windows and non-child tool windows.
The child window(s) has a menu that integrates with the main application menu. The problem is that when a non-child tool window is active then I must click the menu (in the main application window) twice to activate it; once to activate the application (parent) window and a second time to activate the menu. If a child window is active then the menu operates with just one click. In the old version of my progam, which was developed in managed C++ under Visual Studio 2003, only one click was required to activate the main menu when a tool window was active.
This behaviour of my application is annoying and unprofessional. I was wondering if anybody had any ideas on how to fix this or what is causing it? Thanks!
zenzero
|
|
|
|
|
I guess that nobody has any ideas? Is this a bug in .net 2.0 or am I just being dumb?
May be I should try posting on the C# forum?
Any advice would be greatly appreciated.
|
|
|
|
|
Hi,
I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object" occasionally when adding a new element to a vector. By occasionally I mean that the exact same code works fine most of the time, throwing the error around 1% of the time. Based on sample data that I'm feeding the program, the errors occur on the exact same data every execution, but I don't see anything wrong with the offending data or the code. Can someone help? Even if you only have a vague idea of something I can look into, please let me know.
Here's the relevant code snippet:
// if a headline occurs after a normal paragraph, split the block there
for (int i = thisDoc->blocks.size() - 1; i >= 0; i--)
{
block* curBlock = &thisDoc->blocks[i];
if (curBlock->type == blockType::text)
{
// search through all the paragraphs (from end to start)
bool lastWasHeadline = false;
for (int j = curBlock->paragraphs.size() - 1; j >= 0; j--)
{
// is this paragraph a headline?
if (curBlock->paragraphs[j].type == paragraphType::headline)
lastWasHeadline = true;
else
{
// did we just leave a headline?
if (lastWasHeadline)
{
// split the remainder of the block into a new block
block newBlock;
newBlock.type = blockType::text;
for (int k = curBlock->paragraphs.size() - 1; k > j; k--)
{
newBlock.paragraphs.insert(newBlock.paragraphs.begin(), curBlock->paragraphs[k]);
curBlock->removeParagraph(k);
}
//!!!!!!!!!!!!!!!!!!ERROR!!!!!!!!!!!!!!!!!!
//Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
thisDoc->addBlock(newBlock);
//!!!!!!!!!!!!!!!!!!ERROR!!!!!!!!!!!!!!!!!!
}
lastWasHeadline = false;
}
}
}
}
From the class header (to show you what my struct declarations look like):
__nogc struct block
{
rectangle bounds;
rectangle adjacent;
rectangle gutterDist;
int type;
vector<paragraph> paragraphs;
block()
{
bounds.left = bounds.right = bounds.top = bounds.bottom = 0;
adjacent.left = adjacent.right = adjacent.top = adjacent.bottom = -1;
gutterDist.left = gutterDist.right = gutterDist.top = gutterDist.bottom = 2147483647;
type = blockType::undecided;
paragraphs.clear();
}
~block() {paragraphs.clear();}
void addParagraph(paragraph newParagraph)
{
// if this is the first line to be added to the paragraph
if (paragraphs.size() == 0)
{
bounds.left = newParagraph.bounds.left;
bounds.right = newParagraph.bounds.right;
bounds.top = newParagraph.bounds.top;
bounds.bottom = newParagraph.bounds.bottom;
}
else
{
if (newParagraph.bounds.left < bounds.left)
bounds.left = newParagraph.bounds.left;
if (newParagraph.bounds.right > bounds.right)
bounds.right = newParagraph.bounds.right;
if (newParagraph.bounds.top < bounds.top)
bounds.top = newParagraph.bounds.top;
if (newParagraph.bounds.bottom > bounds.bottom)
bounds.bottom = newParagraph.bounds.bottom;
}
paragraphs.push_back(newParagraph);
}
void removeParagraph(int index)
{
paragraphs.erase(paragraphs.begin() + index);
}
};
__nogc struct page
{
int width, height, resolution;
vector<block> blocks;
double avgLineHeight; // calculated in reFormat(...)
page()
{
width = height = resolution = 0;
blocks.clear();
}
~page() {blocks.clear();}
void addBlock(block newBlock) {blocks.push_back(newBlock);}
void removeBlock(int index)
{
blocks.erase(blocks.begin() + index);
}
};
// all necessary internal variables
page __nogc* thisDoc;
|
|
|
|
|
Hi,
I am trying to access some methods from user defined class it doesnt allow me to do, it says SetValue() is not a member of Class1
Here is the code
Class1 *obj = new Class1 () ;
obj->SetValue ();
Do I need to set any properties specifically to access this method.
|
|
|
|
|
Are you using pure native C++ ? If yes, your question is in the wrong forum (this forum is for managed C++).
For your problem, did you check if this method was in the class and if you didn't misspelled it ?
Post the header of the class, it can be usefull.
Cédric Moonen
Software developer
Charting control
|
|
|
|
|
Hi,
when using Clipboard.SetDataObject()in my source code, I got the error 'Clipboard': undeclared identifier.
If I add the lines below,
using namespace System::Reflection;
Clipboard = new Clipboard();
Clipboard.SetDataObject(...);
I got 'System is not a class or namespace name' and other errors.
Any advise???
Thank you in advance
|
|
|
|
|
You need to reference System.Windows.Forms.dll and "using namespace System::Windows::Forms". Also, make sure you have a "using namespace System" in your code.
-- modified at 15:35 Tuesday 23rd May, 2006
|
|
|
|
|
Hi Jackson,
Thank you for your answer.
Actually I was compiling my src code using .Net 2003. When I added the lines-
using namespace System::Windows::Forms;
using namespace System;
I got other compiling errors C2653, which says 'System is not a class or namespace name.
To reference System.Windows.Forms.dll, I just need to specify its path correctly, right?
Robert
|
|
|
|
|
Unless your GAC is messed up, you can have the following place before any actual code:
#using <mscorlib.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Windows::Forms;
Geo
-- modified at 9:15 Wednesday 24th May, 2006
|
|
|
|
|
I am writing a game using Visual C++ (Windows Forms Applications). But I find some difficulty in playing music while the game is started.
Could anybody answer me which function should I use and how to ??
|
|
|
|
|
Whats wrong with the following, actually my VC++.Net application is not calling MFC ActiveX method it says "Object Reference Error", i can able to compile successfully.
System::Byte abData[] = new System::Byte[nLength];
brFileContent->Read (abData,0,2); //brFileContent is Binary Reader
Byte *pbManagedData = &(abData[0]); // Get starting point of Array (I can able to see Data and address here
axSimpleAdditionAtx1 ->FinalBy (pbManagedData); // Calling Activex
+++++++++++++++++++++++
Method signature in ActiveX which is not getting called..
void VRMControl::FinalBy (BYTE* ByteValue, LONG Length) // Prototype
{
}
|
|
|
|
|
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
|
|
|
|