|
picazo wrote: Can you give me an example of how you would do this if the stream is to contain well-formatted xml
No, I will show an example of how things work, I will not do your work for you by providing you an example of how I "would" do it.
System::Xml::XmlDocument^ doc = gcnew System::Xml::XmlDocument();
System::IO::StringReader^ stream = gcnew System::IO::StringReader("<halp><halpme value=\"22\"/></halpme>");
doc->Load(stream);
System::String^ managedStr = doc->DocumentElement->Name;
System::String^ sval =
((System::Xml::XmlElement^)doc->DocumentElement->FirstChild)->GetAttribute("value");
int nval = System::Convert::ToInt32( sval);
_variant_t variant(nval);
std::cout << nval << std::endl;
std::cout << (int)variant << std::endl;
led mike
|
|
|
|
|
Hello,
I have the following unmanaged method:
<code>
BSTR UnmanagedClass::UnmanagedMethod( BSTR x, VARIANT y, BSTR z )
{
...
}
</code>
I am wrapping that method with the following C++/CLI method:
<code>
String^ ManagedClass::ManagedMethod( String^ x, String^ y, String^ z )
{
CComBSTR bstrX, bstrZ;
bstrX.Attach( ( BSTR )( void * )Marshal::StringToBSTR( x ) );
bstrZ.Attach( ( BSTR )( void * )Marshal::StringToBSTR( z ) );
????
return gcnew String( unmanaged->UnmanagedMethod( bstrX, ???, bstrZ ) );
}
</code>
The C++/CLI wrapper method will be accessed from C# as follows:
<code>
string x="some value", y="another value", z="a third value";
managed.ManagedMethod( x, y, z );
</code>
The problem I am having is converting the managed string handle (String^ y) to an unmanaged VARIANT parameter. I would like to be able to solve this problem without having to modify the unmanaged C++ code. Does anyone have any suggestions or ideas on how to do this?
Thanks in advance,
-----------------
Genaro
|
|
|
|
|
picazo wrote: Marshal::StringToBSTR
Returns an IntPtr. You can't just cast that to a BSTR you have to use a method like ToInt32().
led mike
|
|
|
|
|
led mike wrote: You can't just cast that to a BSTR you have to use a method like ToInt32().
ToPointer would be a better method to use there.
|
|
|
|
|
Nishant Sivakumar wrote: would be a better method to use
Sure but my level of apathy for people writing production code that can't blow their own nose is fairly high today.
I feel like starting a new CodeProject account with the user name "HellNo" for replying to all the "can you provide the code" lovelies. Or maybe I shoudl write a programming book titled "Copy Paste for Idiots"... wait...
Chapter One
Copy the following code and paste it into your code file at the appropriate location:
<code>int n = 11;</code>
Now modify the code until it produces the desired results. There finished... now all I need is to send it off to a publisher.
led mike
|
|
|
|
|
You could do a String^ -> BSTR -> VARIANT.
|
|
|
|
|
could you provide some sample code of how to do this? I thought of doing that, but I couldn't get it to work.
Thanks,
-----------------
Genaro
|
|
|
|
|
picazo wrote: could you provide some sample code of how to do this? I thought of doing that, but I couldn't get it to work.
Since you've already written code to convert String^ to BSTR, I presume your problem is with converting that to a VARIANT. To do that, you can use _variant_t which has a constructor that takes a BSTR, and use that. You can pass _variant_t anywhere a VARIANT is expected.
|
|
|
|
|
Hey Guys,
I have a simple DLL file that performs an smtp email function for one of my applications. The problem with the DLL is - it sends an OK dialog box to the user once the email has successfully been sent. I was wondering if it were simple enough for you to remove the OK dialog box from the DLL.
If successful the OK dialog box should not appear after the email has been sent.
Can a DLL be changed like this, or do I have to create a new one altogether?
Thank you,
Stephen
Big Steve
Independant programmer for small business. Client management solutions
(888) 263-2690
|
|
|
|
|
It depends if you have the source code or not, I suspect not.
If the functionality of the DLL is not too large, then I would just rewrite it - it would be much quicker than trying to hack the DLL.
|
|
|
|
|
I have posted this under Visual Studio too as i was unsure of the correct fourm.
I have a Crystal Report 10 report which i need to use in my app. I use Managed solution for this. There are no compiler or linker problems. I am not able to display this report on the screen but am able to print the report. I tried all member methods - Visible, Show, BringToFront, set_Size etc. Am i missing something.?
Here is the code snippet for your ref:
crReportDocument = new ReportDocument();
// MessageBox("Report Document Instance Created", "New Reports");
crReportDocument->Load("BATCHSQL.RPT");
// MessageBox("File Loaded to Report Document Instance ", "New Reports");
//Setup the connection information structure to be used
//to log onto the datasource for the report.
crConnectionInfo = new ConnectionInfo();
// MessageBox("Connection Info set", "New Reports");
//Get the table information from the report
crDatabase = crReportDocument->Database;
crTables = crDatabase->Tables;
// MessageBox("Start Looping through all tables in the REPORT", "New Reports");
//Loop through all tables in the report and apply the connection information for each table.
// MessageBox("Show the Report", "New Reports");
//Set the viewer to the report object to be previewed.
crViewer = new CrystalReportViewer();
crViewer->ReportSource = crReportDocument;
// MessageBox("View the Report", "New Reports");
crViewer->Location = System::Drawing::Point(60, 60);
crViewer->Size = System::Drawing::Size(750, 750);
crViewer->Show();
crViewer->BringToFront();
crViewer->Visible = TRUE ;
crViewer->RefreshReport();
crViewer->Zoom(200);
crViewer->DisplayToolbar = TRUE ;
crViewer->DisplayBackgroundEdge = TRUE;
// crViewer->PrintReport(); ---- This works
MessageBox("Refreshing of the Report Complete", "New Reports");
Any suggestions?
Thanks,
Madhu

|
|
|
|
|
Hello,
I was using extern functions like:
<br />
extern "C" <br />
{ <br />
__declspec (dllimport) int TextExtern(int sizel);<br />
<br />
}
in MFC, when I try to use this with CLI it takes such a long time to load this function that it is imposible to use this function. Just in case this extern function TextExtern is writed in FORTRAN
Can anybody help me??
Thanks,
Best regards
|
|
|
|
|
http://users.volja.net/bsaksida/co.zip
if you look for ListViewFlickerFree, you can see the function ValidateRect has ben used from user32.dll
|
|
|
|
|
Hi i've been struggling for two days now, the Client Server application I wrote runs perfect when my pc runs the server and the other pc connect to it. but if i change the host ip on the client program and run the server on any other pc I get the the
SocketException : No connection could be made the target machine activly refused it
I've tried every thing even removed the firewall's on all the comuters
can any one help me...?
thanx in advance
|
|
|
|
|
Are you positive no firewalls are blocking the listen port? Are the port settings correct?
Is the server succesfully binding and listening on the correct port?
Also are there any permissions required for the user context the server runs in on other machines
(just a wild guess/thought)?
|
|
|
|
|
Hi all. How come i get the error that i _beginthread is a undeclared identifier ? When i clearly have #include <process.h> ????
This is strange. Im using the VC++ 6 compiler and MS 2003 SDK - i hope these arnt the problems. Thanx in advance.
|
|
|
|
|
You've defined _WIN32, _X86_ (or the appropriate processor define), and included
#include <process.h>
?
|
|
|
|
|
Yes, i dont know why what i typed was a bunch of question marks. But it was #include < process.h >
|
|
|
|
|
hmmm does #include <windows.h> need to be before the process.h include?
Other than that all I can think of is old header files (it compiles fine for me on VS 2003).
Mark
|
|
|
|
|
1 more thought - you are compiling for multithread right (/MT)?
|
|
|
|
|
OK. So I'm trying to create a custom control in a C++/CLI project. I create it, build it, it gets added to the Toolbox, everything is happy -- until I try to add the control to a Windows form. As soon as I drag the custom control from the toolbox to the form, I get the message "Failed to load toolbox item <insert name here>. It will be removed from the toolbox."
So I took a "back-to-basics" approach and tried to create a user control that merely encapsulates a textbox. Nothing else added. Just a plain old text box. I get the same $@#$@#%!#% message.
So at this point I figure either I'm just stupid or else there's something seriously wrong with my installation of Visual Studio (2005 Professional). Can someone point me to a good step-by-step article on creating custom user controls specifically in C++/CLI? Or does anyone have an idea why I'm getting this message?
Thanks.
-- modified at 11:18 Wednesday 10th January, 2007
|
|
|
|
|
http://users.volja.net/bsaksida/co.zip
this is my project, If you woud look for ListViewFlickerFree, you can see how to create custom control
|
|
|
|
|
Thanks. I've downloaded it and I'll take a look.
|
|
|
|
|
Bsaksida,
Just wanted to follow up with you. Thanks for that sample project. At first glance, it appeared I was doing everything correctly, but a little deeper digging revealed the problem: My project is built with the /clr option rather than /clr:pure. Once I moved my custom control into a separate DLL project built with the /clr:pure switch, I was able to bring that control into forms in the main project with no problem.
Thanks again,
xpnctoc
|
|
|
|
|
The reason i put in dll, was because sometimes a IDE desing bisplayed errors instead design if it wasn't in dll.
|
|
|
|