|
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?
|
|
|
|
|
I'm not surprised, since you have not initialised your OSVERSIONINFOEX structure with any values. Take a look here[^] for details on what you are supposed to do.
I must get a clever new signature for 2011.
|
|
|
|
|
I have a Database Class which gets created on the CLR heap using gcnew. The problem is that the database connection is made in the constructor of the database class. What I need to do is deallocate the database object early if the connection to the database is lost and then recreate the object on the CLR heap. My question is can memory allocated with gcnew be deallocated before the garbage collector deallocates it using the delete operator?
|
|
|
|
|
John Robert Wilk wrote: My question is can memory allocated with gcnew be deallocated before the garbage collector deallocates it using the delete operator No. delete on a managed object won't remove the instance from CLI heap. All it does is call the destructor of the object. GC will reclaim the memory later.
You can cleanup the resources that you have used, like connection object or any other native handles deterministically. But the object will be deallocated only by garbage collector. On a garbage collected environment, you don't have to worry about cleaning up the memory allocated. All you have to ensure is no strong references exists to the object that will prevent GC from collecting.
For cleaning the resources, C++/CLI provides methods like "Stack semantics". In which the compiler implements IDisposable on the type and create code to call Dispose() method when the scope ends. You can write your cleanup code inside the Dispose() method. This is the recommended way of cleaning up managed objects. For native objects, you have to call delete on them.
John Robert Wilk wrote: The problem is that the database connection is made in the constructor of the database class Usual pattern for database access is, opening connection, executing query and closing the connection. ADO.NET has connection pooling built in and connection instances are created from there. Unless you have a good reason for initializing the connection on the constructor, the pattern explained should be followed.
Best wishes,
Navaneeth
|
|
|
|
|
|
Hi!
Is there an equivalent for MSXML.XMLHTTPRequest(VB) in C++/CLI? I've to send an XML Text to a server. How to do this using C++/CLI?
|
|
|
|
|
You can use the WebRequest[^] class.
Best wishes,
Navaneeth
|
|
|
|
|
Hi!
I used the following code. It only prints "OK". But I want to send an XML text to the server and also downlod from the server. This is the code:
<br />
WebRequest^ request = WebRequest::Create( "https://live.play368.com/cgibin/EClientIntegration" );<br />
request->Credentials = CredentialCache::DefaultCredentials;<br />
HttpWebResponse^ response = dynamic_cast<HttpWebResponse^>(request->GetResponse());<br />
Console::WriteLine( response->StatusDescription );<br />
System::String^ Dsc = response->StatusDescription;<br />
Stream^ dataStream = response->GetResponseStream();<br />
StreamReader^ reader = gcnew StreamReader( dataStream );<br />
String^ responseFromServer = reader->ReadToEnd();<br />
Console::WriteLine( responseFromServer );<br />
reader->Close();<br />
dataStream->Close();<br />
response->Close();<br />
What else need to be done to send XML text to the server and download from server?
|
|
|
|
|
Hi
If i use /clr mode to compile a code that has somthing like the following:
int x = 3;
char ch='A';
int arr[]="Hi";
array<int>^ ManArr1={44};
array<int>^ ManArr2= gcnew array<int> {44};
my questions now:
Would the type int be mapped to System::Int32 ?? and what about char ch ? Are they considerd as native or managed type? Where will be executed! through MSIL or not!!
We see that int arr[] is a native array, does that mean it will be executed out of MSIL?
The last question ,, For both the managed array ManArr1 & ManArr2 what is the difference between the two initialization ??
|
|
|
|
|
Good question!
anti.AS wrote: Would the type int be mapped to System::Int32
Yes. By default compiler treat it as managed integer. And what type of interger is implementation defined. On a 32 bit machine you could get System.Int32 and Int64 on 64 bit machines. Now consider the following example
int x = 3;
std::cout << x; std::cout expects a native integer and you are passing a managed one. So the compiler does the conversion for you.
anti.AS wrote: and what about char ch ?
This will be compiled as System.SByte .
anti.AS wrote: We see that int arr[] is a native array
int arr[]="Hi"; is an invalid statement. But in general, this is treated as a managed CLI array.
anti.AS wrote: The last question Wink ,, For both the managed array ManArr1 & ManArr2 what is the difference between the two initialization ??
Nothing. First one is a syntactic sugar.
Hope that helps
Best wishes,
Navaneeth
|
|
|
|
|
Thank u N a v a n e e t h... great information ...
btw the native array will be considered as unverifiable unlike the managed one.
|
|
|
|
|
Hi!
My XML file contains the following:
<?xml version="1.0" encoding="UTF-8"?>
<download>
<English>
<Updated_date>16/11/2010</Updated_date>
<Filename>Update_Eng</Filename>
</English>
<Updateexe>
<Updated_date>16/11/2010</Updated_date>
<Filename>Update</Filename>
</Updateexe>
</download>
I've to read from the program(C++/CLI), the value of the tag <Updated_date> which is inside the tag <Updateexe> . How to do this in C++/CLI?
|
|
|
|
|
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
|
|
|
|