|
Sorry, I guess there is no simple way to do this other than :
St = gcnew System::String(str.c_str());
I must get a clever new signature for 2011.
|
|
|
|
|
Fair enough. That's what I'd done, but... am I not re-allocating memory without freeing it first?? (I have to do it for a dozen of strings!)
|
|
|
|
|
piul wrote: am I not re-allocating memory without freeing it first?
It depends on the actual structure of your code. I think a more pertinent question would be: why are you using both std::string and System::String when you only really need one of them, probably the latter. For example code such as:
std::string str("Some string");
System::String ^ st = gcnew(str.c_str());
serves no real purpose, in that the std::string is totally redundant.
I must get a clever new signature for 2011.
|
|
|
|
|
what about
St = gcnew String(str);
or
using namespace System::Runtime::InteropServices;
...
...
St = Marshal::PtrToStringAnsi((IntPtr)str);
|
|
|
|
|
Hi!
I've set the Text to my label from an XML file. I need to set a chinese word to a label. Here is my XML file contents:
<?xml version="1.0" encoding="UTF-8" ?>
<Remember>游戏目的是使两手牌的点数越比庄家接近</Remember>
The chinese word is for test purpose only(may not be meaningful word). Here is my code for reading this tag and setting the text to a label.
XmlDocument ^ Config = gcnew XmlDocument;
if(System::IO::File::Exists("Config.xml"))
{
Config->Load("Config.xml");
}
XPathNavigator ^ nav = Config->CreateNavigator();
XPathNodeIterator ^ iter;
iter = nav->Select("download/Remember");
while(iter->MoveNext())
{
System::String ^ ConfigText = iter->Current->Value;
ConfigText->Trim();
}
System::Runtime::InteropServices::Marshal::StringToHGlobalUni(ConfigText);
m_pRemember->Text = ConfigText;
While I execute the program only boxes are displayed in place of the chinese characters. If I open the XML file in a browser, the chinese characters are displayed. What else to do to display the chinese language?
|
|
|
|
|
Where are you displaying the text and seeing the boxes? To the console? To a TextBox or TextBlock?
If they are going to the console, then it probably makes sense that you'd see boxes as the console font is probably not set properly to a font with those characters. Use the system menu to change the font to a unicode font and try again if that's the case.
If it's to a textbox, again, check the typeface you're using. The browser is probably dynamically loading the font glyphs it needs and painting with those.
John
|
|
|
|
|
Hi!
How to set Full Control & Write Unlock to a file from C++/CLI? The reason why I want this is:
I'm creating a log in form. While clicking a button, I'm writing the log in information to a file(to implement "Remember Me" functionality). While creating installer for this application, this works fine under Win XP. But did not work with Windows 7. There I've to manually set Full Control to the file. Users of my app won't like this. I used the following code to set Access control:
path = L"RememberMe.ini"; System::IO::File::SetAccessControl(path,System::Security::AccessControl::FileSecurity::WriteUnlock());
But this results in the following error:
error C3767: 'System::Security::AccessControl::ObjectSecurity::WriteUnlock': candidate function(s) not accessible
How to set access control from C++/CLI? or Can any one suggest an alternative solution to my problem? I'm using Visual Studio 2008 Deployment Project to write setup file.
modified on Friday, March 4, 2011 1:59 AM
|
|
|
|
|
pix_programmer wrote: error C3767: 'System::Security::AccessControl::ObjectSecurity::WriteUnlock': candidate function(s) not accessible
You are trying to access a protected method. WriteUnlock() is a protected method and won't be accessible from outside the class.
pix_programmer wrote: While creating installer for this application, this works fine under Win XP. But did not work with Windows 7. There I've to manually set Full Control to the file.
From Vista onwards, you need to utilize the program data folders to write information like this. You will have full write access to these folders.
pix_programmer wrote: How to set access control from C++/CLI
Look at the MSDN documentation[^] for SetAccessControl() method.
Best wishes,
Navaneeth
|
|
|
|
|
Hi all,
I'm working on a user control which is basicly a customized edit control (HexEditBox).
It has a context menu which is activated by the right mouse click, as per normal.
All is working fine with the control, but has a visual aspect that I'm not happy with.
When the context menu is activated the caret is hidden from the control.
For most of the menu items this is irrelevant, but for the paste option the user looses
visual indication where the paste will occur.
It is anyway possible the prevent the context menu from hiding the controls caret?
Thanks in advance .. Milton
|
|
|
|
|
|
I have a C# method declared as:
public static bool MethodName(double [] d1,....)
and am try to call it from a C++ mixed mode method. I have tried to to so as follows:
array<double ^,="" 1=""> ^d = gcnew array<double ^,="" 1="">(2);
d[0] = gcnew double
d[1] = gcnew double
d[0] = 1.0;
d[1] = 2.0;
classname::MethodName(d);
I get a compler error saying cannot convert param 1 from cli::array<type, dimmension=""> ^ to cli::array<Type, dimmension> ^
Does anyone have any ideas on how to correctly pass an arry from C++ to c#?
|
|
|
|
|
The array does not indicate the type of object in the array. So, I would allocate it like this:
array<double>^ d = gcnew array<double>(2);
d[0] = 1.0;
d[1] = 2.0;
MethodTakingDoubleArray(d);
John
|
|
|
|
|
Thanks. I actually just figured it out myself also. Do you by any chance know how to pass a double from C++ to C# as an out parameter?
|
|
|
|
|
Sure, that should be no problem. I just tried this.
C++/CLI side:
double val = 1.0;
CSharpObj->ChangeInCSharp(val);
Debug::WriteLine(val);
C# side:
public void ChangeInCSharp(out double changeme)
{
changeme = 4.0;
}
John
|
|
|
|
|
Thank you. Now, can you explain why that works to me? I am a very seasoned native C++ and C# developer, but am pretty green to the CLI stuff. an out parameter would normally be passed by reference, but the way that this is being called seems to be by value.
|
|
|
|
|
It's all in the metadata of the method signature written by the C# compiler. When C++/CLI compiler resolves the call, it sees the IL Metadata indicating that the parameter is 'out'. So, the C++/CLI compiler knows to generate calling code with the value passed by reference. I haven't looked at the generated IL but it's also possible that the double is boxed when passed as an out parameter.
John
|
|
|
|
|
Thank you. I love "automagic" code.
|
|
|
|
|
This bothered me a little at first too but then it was pointed out that it's not too different than standard C++ pass-by-reference.
int x = 5;
DoSomething(x);
Without examining the declaration of DoSomething() there's no indication at the calling site whether it's pass by value or by reference. The usual hidden C++ magic. Of course, intellisense helps some unless you're using C++/CLI...oh wait we are I use Visual Assist which helps sometimes.
John
|
|
|
|
|
Hi all, I am trying to get assembly sersion of my app and display on aboutform for user to know what version of software they are running.
thanks
|
|
|
|
|
You already posted this question in the C# forum, and received a number of answers. If you have supplementary questions then post then in the original thread.
I must get a clever new signature for 2011.
|
|
|
|
|
yes you are right. I got that working too. but there is a differences between C++/CLI and C# version of the code. In C# (VS2010) you have form called AboutBox which is prebuild with all of the information. In C++/CLI you do not have it. I am sorry if I confuesd you.
thanks,
|
|
|
|
|
jashimu wrote: In C# (VS2010) you have form called AboutBox which is prebuild with all of the information. In C++/CLI you do not have it.
That is nothing to do with the question you are asking.
I must get a clever new signature for 2011.
|
|
|
|
|
Hi!
I've to get the OS Name. I'm using the following code:
OSVERSIONINFOEX *osName = new OSVERSIONINFOEX();
System::Console::Write(osName->dwMinorVersion.ToString());
It only prints "0". I need the output as a Text like "Windows XP". I want to check whether Windows 7 or Vista is installed on a particular machine? How to do this using C++/CLI?
modified on Wednesday, March 2, 2011 8:11 AM
|
|
|
|
|
pix_programmer wrote: it only prints "0".
That's what you told it to do.
I would suggest you consult the details here[^] on MSDN for the different values that explain which version of the operating system you are running on.
I must get a clever new signature for 2011.
|
|
|
|
|
Hi!
I've used the following code to check whether Windows 7 is installed in a particular system.
OSVERSIONINFOEX *osName = new OSVERSIONINFOEX();
if ( osName->dwMajorVersion == 6 )
{
if( osName->dwMinorVersion == 0 )
{
if( osName->wProductType == VER_NT_WORKSTATION )
{
System::Console::Write("Windows Vista is installed in this computer");
}
else
{
System::Console::Write("Windows Server 2008 is installed in this computer");
}
}
if ( osName->dwMinorVersion == 1 )
{
if( osName->wProductType == VER_NT_WORKSTATION )
{
System::Console::Write("Windows 7 is installed in this computer");
}
else
{
System::Console::Write("Windows Server 2008 R2 is installed in this computer");
}
}
}
else
System::Console::Write("Windows XP is installed in this computer");
But it always prints "Windows XP is installed in this computer" in a Windows 7 System also. How to find the OS Name in a System?
|
|
|
|