|
Use XPathNavigator to select the node(s) you're interested in.
Example:
XPathDocument^ document = gcnew XPathDocument("C:\\temp\\test.xml");
XPathNavigator^ navigator = document->CreateNavigator();
XPathNodeIterator^ nodes = navigator->Select("*/Updateexe/Updated_date");
while (nodes->MoveNext())
{
Console::WriteLine(nodes->Current->ToString());
}
John
|
|
|
|
|
Hi, I need to use a generic and they're obviously different than C++ templates but I'm a bit stumped. Do you know if there's a better way to do this?
Imagine a base class "MyWindowBase" and a bunch of derived classes. I need to grab instances of the template type from a master list.
generic<class WindowType> where WindowType : MyWindowBase
System::Collections::IList^ WindowManager::getAllWindowsOfType()
{
List<WindowType>^ results = gcnew List<WindowType>();
for each (WindowBase^ w in mWindowList) {
try {
WindowType asWT = cli::safe_cast<WindowType>(w);
results->Add(asWT);
}
catch (System::InvalidCastException^)
{}
}
return results;
}
Example usage:
for each(ReportWindow^ report in WindowManager::Instance->getAllWindowsOfType<ReportWindow^>())
{
}
This works but the safe_cast has a smell because it throws an exception if the cast is not allowed.
I'd prefer to use dynamic_cast instead with a nullptr check but that doesn't seem to be allowed. Could I somehow check the typeid instead? Still feeling my way around these generics a bit.
John
|
|
|
|
|
|
Thanks Philippe! You've confirmed my suspicion and thanks for the stackoverflow link - don't know why that didn't show up in my searches...
John
|
|
|
|
|
Hi!
I've to write code to establish a client/server communication in C++. What are the steps involved? Can any body give me some sample code?
|
|
|
|
|
Please pick ONE forum to ask your question. Posting the same question in more than one place only annoys people and makes them less likely to help you.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Hi All,
Every body know this question answer please send me the reply?
In visual studio 6.0 .Debugging operation performed press F10 it takes to the next step into host information(means takes assembley) in windows 7 64-bit environment.
Thanks.
|
|
|
|
|
Hi!
I want the advice of the community on using usual static_cast instead of cli::safe_cast. Which one is preferable?
|
|
|
|
|
As far as I know, safe_cast is more like dynamic_cast (which you can also use on managed types). safe_cast and dynamic_cast are for casting between handles to polymorphic types within a class hierarchy (much as you would do in C++ with pointers). The difference is that safe_cast throws an exception when the cast is not possible rather than returning nullptr. This means you don't have to write code that checks to see whether the cast succeded, just handle the exception, meaning potentially less cluttered code.
|
|
|
|
|
Just wondering how and if you can pre-select multiple files as the dialog opens? Do you place a list of them in the Initial Filename area, as I've tried this already the answer seems to be, No.
Am I missing something?
Basically I'd like a user to be able to select multiple files, I then do some checking of the filenames and if one of these checks comes back false, I want to reload this dialog with the files that the user had previously selected.
Any help would be greatly appreciated
Hayden
CFileDialog dlg(FALSE,NULL,"",OFN_ENABLESIZING|OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT,"All Files(*.*)|*.*||");
const int nBufferSize = 128*1024;
TCHAR *szNewBuffer = new TCHAR[nBufferSize];
memset(szNewBuffer, 0, sizeof(TCHAR) * nBufferSize);
dlg.m_ofn.lpstrFile = szNewBuffer;
dlg.m_ofn.nMaxFile = nBufferSize - 1;
if (dlg.DoModal() == IDOK)
{
POSITION pos = dlg.GetStartPosition();
CString fullpath;
CString filenametemp;
CString filename;
int nLastSlashPos;
filePaths = "";
fileNameList = "";
while (pos)
{
fullpath = dlg.GetNextPathName(pos);
nLastSlashPos = fullpath.ReverseFind('\\');
if(nLastSlashPos >= 0)
{
filename = fullpath.Mid(nLastSlashPos+1);
}
if (filePaths != "")
{
filePaths = filePaths + "|";
fileNameList = fileNameList + " ";
}
filePaths = filePaths + fullpath;
fileNameList = fileNameList + '"' + filename + '"';
}
}
|
|
|
|
|
Hi!
I've a file called test.ini. The contents of this file is:
PreviousCheck =true
LID =ratha
PWD =rtrrules
I've to read the file and assign each value after the equal(=) sign to three System::String^ variables. I don't want the text preceding the equal sign(i.e PreviousCheck =,LID = and PWD = all I don't want). How to do this in C++/CLI?
|
|
|
|
|
Firstly, what you are doing is better suited to the app.config key/value approach. But to answer the question investigate the 'Split' method on the String^ class in C++/CLI to achieve what you want.
Ger
|
|
|
|
|
Hi!
I used the following code to get a line from the file(and then I will split it into parts).
System::IO::StreamReader reader("test.ini", System::IO::FileMode::Open);
System::String^ line = reader.ReadLine();
But I got the following error:
error C2664: 'System::IO::StreamReader::StreamReader(System::IO::Stream ^,bool)' : cannot convert parameter 1 from 'const char [17]' to 'System::IO::Stream ^'
Reason: cannot convert from 'const char *' to 'System::IO::Stream ^'
No user-defined-conversion operator available, or
Cannot convert an unmanaged type to a managed type
How to get rid of this error?
|
|
|
|
|
I suggest putting "Test.INI" in a variable defined as String^ e.g.
String^ FileName;
FileName = String::Format("Test.INI");
Finally when you are splitting your input strings define the index character as wchar_t
Ger
|
|
|
|
|
T.RATHA KRISHNAN wrote: How to get rid of this error?
I think this is a subtle one; you have provided a char* in parameter 1 of the constructor, but no such constructor exists. You need to use a String object as the path parameter for the compiler to select the correct constructor. You can find all the gory details here[^] on MSDN.
I must get a clever new signature for 2011.
|
|
|
|
|
This seems to work:
#include "stdafx.h"
using namespace System;
int main(array<String ^> ^args)
{
array<String^>^ lines = System::IO::File::ReadAllLines("C:\\temp\\test.ini", System::Text::Encoding::UTF8);
Console::WriteLine("Key\t\tValue");
for each (String^ line in lines)
{
if (String::IsNullOrWhiteSpace(line))
continue;
int offset = line->LastIndexOf("=");
if (offset >= 0)
{
String^ key = line->Substring(0, offset)->Trim();
String^ value = line->Substring(offset+1)->Trim();
Console::WriteLine(key + "\t\t" + value);
}
}
return 0;
}
John
|
|
|
|
|
Hi all!
I have big experience in the unmanaged C++. And have almost no experience in all these NET things. So, I started a project using managed C++ yesterday. Looks, like it will put me to the grave...
For the context. I'm writing a plugin for ClearCanvas application. My plugin already have some classes that are inherited from the classes in the ClearCanvas SDK. Plugin is loading and working well.
Now imagine the situation.
I define a new class that inherits the simple interface. The inheritance model is:
IDisposable->IRenderingSurface->MyClass
IRenderingSurface is just a simple interface that declares 4 properties without implementation of them.
So I implement my class like this:
ref class VolumeRenderingSurface :
public ClearCanvas::ImageViewer::Rendering::IRenderingSurface
{
public:
VolumeRenderingSurface(System::IntPtr windowID, int width, int height);
~VolumeRenderingSurface();
property System::IntPtr WindowID
{
virtual System::IntPtr get() {return m_windowID;}
virtual void set(System::IntPtr id) {m_windowID = id;}
}
property System::IntPtr ContextID
{
virtual System::IntPtr get() {return m_contextID;}
virtual void set(System::IntPtr id) {m_contextID = id;}
}
property System::Drawing::Rectangle ClientRectangle
{
virtual System::Drawing::Rectangle get() {return m_clientRectangle;}
virtual void set(const System::Drawing::Rectangle rect) {m_clientRectangle = rect;}
}
property System::Drawing::Rectangle ClipRectangle
{
virtual System::Drawing::Rectangle get() {return m_clipRectangle;}
virtual void set(const System::Drawing::Rectangle rect) {m_clipRectangle = rect;}
}
private:
System::IntPtr m_windowID;
System::IntPtr m_contextID;
System::Drawing::Rectangle m_clientRectangle;
System::Drawing::Rectangle m_clipRectangle;
};
The constructor and destructor are defined but empty. I even DONT use this class anywhere, just define it.
And I try it. Everything is compiled without warnings, but when ClearCanvas attempts to load plugin - it fails.
"first chance exception of type 'System.BadImageFormatException' occurred in mscorlib.dll"
Well, next point. If I comment the inheritance from interface it works!
In my project, I have few classes that are inherited exactly the same (I mean IDisposable->ISomeSimpleInterface->SomeClass) and they work!
What a hell!?
Here is the code for IRenderingSurface interface, it's in C#. Nothing interesting:
public interface IRenderingSurface : IDisposable
{
IntPtr WindowID
{
get;
set;
}
IntPtr ContextID
{
get;
set;
}
Rectangle ClientRectangle
{
get;
set;
}
Rectangle ClipRectangle
{
get;
set;
}
}
Thank you.
|
|
|
|
|
Wow, I found a problem. Although this is my (no big) mistake, the result is just unexpected.
virtual void set(const System::Drawing::Rectangle rect) {m_clientRectangle = rect;}
Should be replaced with:
virtual void set(System::Drawing::Rectangle rect) {m_clientRectangle = rect;}
No const! Well I know const doesnt mean here anything. I've tried to use const reference from the very beginning. Then it failed to compile, I removed reference, but forgot to remove const.
As a result - 5 hours wasted because of const that actualy doesnt mean anything!
Fairy .NET
|
|
|
|
|
When I add memnber functions in Visual Studio (C++) I always direct them to the .cpp file. However when I add form events, it insists on putting both the declaration and function body in the .h.
Now in VS 2008, when I move the function code to the .cpp file, the IDE looses track of it. How do I configure it to go there automatically?
Ger
|
|
|
|
|
Adding a member function in VC++ Express 2010 - Do I have to do this by hand? When I right click on the Class, in the browser, the Add option is not on the menu function.
Ger
|
|
|
|
|
Hi
Do we have ability to write inline assembly code in managed C++/CLI
Thanks in advance!
|
|
|
|
|
If you want to mix the asm into C++/CLI code you'd either need to use #pragma unmanaged or put the inline asm in a function within a separate file compiled without /clr.
A .cpp file built with /clr which includes inline assembly will get an error like this:
1> ..\myfile.cpp(205): error C2711: 'CMyApp::Test' : this functon cannot be compiled as managed, consider using #pragma unmanaged
1> Inline native assembly not supported in managed code
John
|
|
|
|
|
Hi guys
In C++/CLI what is the difference between using the concept of IJW (It Just Works) and using pragma directive as following:
#pragma managed(push,off)
UnmanagedFunc(){
…native code …
}
#pragma managed(pop)
Does IJW is enabled automatically (so just need to write our native code) or we need to do something to make it works..??
In other mean, what is the advantage of IJW over using pragma directive or the other way around??
|
|
|
|
|
IJW is just a term they used back in 2003/2004 to talk about how the managed-unmanaged transitions and marshaling were smoothly handled for you by the compiler. No one uses the term these days, and instead people just say C++ interop to refer to anything where mixed-mode code comes into play.
#pragma unmanaged is a pre-compiler directive that tells the compiler that any code in that block must be compiled natively (meaning no msil at all). It's mostly used to ensure that frequently used code is compiled for better performance (which usually implies native code generation).
|
|
|
|
|
Thanx Nish
If I use standard C function inside CPP/CLI code .. like for example:
ManagedFunction(){
..... Managed Code .....
..... Managed Code .....
printf("I am standard C function!\n");
..... Managed Code .....
..... Managed Code .....
}
Does MSIL do something with the printf() function! (Notice that i did NOT use #pragma umanaged directive!)
If MSIL will do nothing with printf() so (as i think) printf() will be compiled as native??So why I need to use #pragma umanaged directive.
|
|
|
|