|
If your application plots the graph from a function, then you could just evaluate the function f(x) at x to get the function's value and put those in the datagrid.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
I have written a C# DLL that I intend to call from an unmanaged C++ app. I have so far followed all the rules that Microsoft explains in this article: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkcominteroppart2cservertutorial.asp[^]. My ultimate goal is to have a method in the C# DLL which will populate a string OUT parameter, and call it from C++. Something like void GetErrorString( int iErrorCode, ref string szErrorString ) . Now do not take that signature seriously - because that is what the question is! What should be the signature???? And how exactly do I call it from C++?
So far I have tried:
Attempt 1.
C# signature:
void Func2( int iCode, ref char [] szOut );
C++ call:
char szRetString[ 128 ];<br />
cpi->Func2( 10, &szRetString );
Result: Runtime error
Variation: Instead of "&szRetString" in C++, tried "szRetString". Same result.
Variation: Instead of "ref" in C#, tried without ref. Same result.
Attempt 2.
C# signature:
void Func2( int iCode, ref string szOut );
C++ call:
char szRetString[ 128 ];<br />
cpi->Func2( 10, &szRetString );
Result: Runtime error
Variation: Instead of "&szRetString" in C++, tried "szRetString". Same result.
Variation: Instead of "ref" in C#, tried without ref. Same result.
Attempt 3.
C# signature:
void Func2( int iCode, ref StringBuilder szOut );
C++ call:
char szRetString[ 128 ];<br />
cpi->Func2( 10, &szRetString );
Result: Runtime error
Variation: Instead of "&szRetString" in C++, tried "szRetString". Same result.
Variation: Instead of "ref" in C#, tried without ref. Same result.
And all the cross-variations of the above combinations as well!!!!
Can somebody please tell me where am I going wrong? My C++ project does not have UNICODE defined. But please note that I have succeeded in calling the example provided by the MSDN article (link above) - which means I am successful in sending a read - only copy of string as IN parameter into C#.
Ever wondered that microsoft examples avoid the harder part?;)
Koushik Biswas
If you would not be forgotten as soon as you are dead...
either write things worth reading or do things worth writing.
|
|
|
|
|
Strings are immutable in C#, so "ref string" might not mean much, since the target would still be unchangeable. Also strings in c# are by definition Unicode, so you will likely need to define UNICODE in your c++ project. C# strings map reasonably well to BSTRs from an interop point of view. You might try making the C++ signature "Func2(10, &BSTRmystr) and match that with the stringbuilder variant odf the C# one...
Absolute faith corrupts as absolutely as absolute power
Eric Hoffer
All that is necessary for the triumph of evil is that good men do nothing.
Edmund Burke
|
|
|
|
|
Hello,
Let's say I have a function, exp^x for example. I would like to draw a graph
of this function in the client area of my form.
The only way I can think of doing this is to write a conditional loop that
will iterate through values of x within some interval and then draw the value onto the screen scaled in some way to the clientRect.Height and clientRect.Width.
Question: What do I have to do to get the 'graph' to appear as one continuous smooth plot?
thanks
|
|
|
|
|
Create a Point for every x/y coordinate you have, put them all into an array and then call:
Graphics g = e.Graphics;
Point[] points = CalculatePoints();
g.DrawLines(Pens.Black, points);
You can also play around with the SmoothingMode property of the Graphics class. This will probably help you to make it look 'nicer'.
|
|
|
|
|
Hi, I have an application where users can do many find/replace operations, including regexes. The problem is that if the user wants to replace something with a carriage return/newline and enter \r\n it literally replaces with "\r\n", however if I try the same thing but in the code, and specify a regex to replace something with \r\n it does replace with a carriage return/newline.
Otherwise the regex works properly, for example the user can find a carriage return/newline with \r\n and they can replace with $1 for example, but it just doesn't work when you try and replace with \r\n .
thanks for any help!
|
|
|
|
|
If the user types this into the textbox it's like you would define the string like the following:
string s = @"\r\n";
or
string s = "\\r\\n";
You could replace it manually within your code:
string s = s.Replace(@"\r, "\r).Replace(@"\n", "\n");
|
|
|
|
|
|
Hi All
I have created a custom component which is just a gradient filled background. It all works well until resized as only the new area is redrawn.
How can I call repaint so that the entire component is redrawn instead of being invalidated?
Thanks
Nick James
|
|
|
|
|
Two methods:
1. Override OnResize and call Invalidate() (without parameters).
2. Put base.SetStyle(ControlStyles.ResizeRedraw, true); into your constructor.
Don't call Refresh() . It could reduce performance.
|
|
|
|
|
Thanks Robert, that worked a treat.
I knew there should be a one line answer. I've never looked at the ControlStyles objects until now.
I added the following lines:
<br />
base.SetStyle(ControlStyles.ResizeRedraw, true);<br />
this.SetStyle(ControlStyles.DoubleBuffer, true);<br />
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);<br />
this.SetStyle(ControlStyles.UserPaint, true);
So now I have double buffering with no flickering when the user resizes the control.
Once again thanks, and thanks to the Code Project for an excellent site.
|
|
|
|
|
Hi all !
How is the future of C#.net ?
is there any source ?
thanx !
s_mostafa_h
|
|
|
|
|
The future will be fine
The C# 3.0 specs are already out and Microsoft will support .NET even more than it does right now.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
"The future's so bright, I've gotta wear shades."
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
from which way , you're sure to say !
s_mostafa_h
|
|
|
|
|
i am trying to remove string with preceding and trailing spacesin C#.NET
strTemp = Regex.Replace(strTemp, @"^\s*(.*?)\s*$", "$1");
this is not working please help me.
thank you
|
|
|
|
|
strTemp = strTemp.Trim();
---
b { font-weight: normal; }
|
|
|
|
|
Thanks i try that code, but i was putting ' around my string thats why Trim() did't work for me. Thanks for ur help, i got it working
|
|
|
|
|
Hi All,
I am looking for some sample code for printing the content of the a tree view control. I was just curious if someone had any ideas.
Thanks
JS
|
|
|
|
|
I may have the wrong idea, but why not just make a richtextbox, have it paste in the contents of each node, and on each node level tab it?
|
|
|
|
|
Hi James,
That would do the trick. The only thing is that I need the treeview for some user interaction but I could use the rtb as an intermediate step.
Thanks for your feedback.
JS
|
|
|
|
|
I would like to be able to mark a webmethod as obsolete by applying the obsolete attr to the method. What i really want out of this is for the description of the webmethod to show that this is a deprecated method and not to use it. Using this with non webmethods works just fine.... any tricks?
|
|
|
|
|
And what is a webmethod?
I have never heard of such thing...
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
hi
can anyone help to solve my problem.
i have two picture boxes one on top of other.the picture box behibd the top one shows live video from web cam . i want the picture box on top to be transparent so that i can view the video in the second picturebox through the transaprent one for c# application.
thanks ramya
|
|
|
|
|
Check out MSDN Library on "ControlStyles" flag and "SupportsTransparentBackColor" and "Opaque" style. By using these styles and providing a background color with an "alpha" value you can make it transparent. All you need is to play with the alpha level of the System.Drawing.Color structure.
Bluehunter
|
|
|
|