|
moniqui wrote: What is a ref class?
In C++/CLI, it's a managed C++ class, that is, the contents of the class are exposed to other .NET languages natively, it uses .NET garbage collection, and so on. C++/CLI is new to Visual Studio 2005; if you're using Visual Studio 2003, there's managed extensions for C++, in which case you'd use the __gc keyword instead of the ref keyword. Go to the C++/CLI forum if you have more questions about C++/CLI syntax and how to wrap a native library. Basically, when write a ref class in C++/CLI, any other .NET language can immediately call into that class, no P/Invoke or interop code required; you'd use it like any other normal type.
moniqui wrote: Do I need to create a .def file?
Not from the C++/CLI project, no. For the native class you're wrapping, I'm not sure, I recommend going into the C++/CLI forum for a better answer.
moniqui wrote: Where you said "mynative->Start()", is mynative the name of my dll (so it would be MITT->Start() )? I tried that and the compiler said it couldn't resolve MITT, so I'm not sure how to make this C++ class aware of the dll.
mynative was just your C++ class instance that contained the Start method. If the Start method is not defined in a class (i.e. it's global) then you wouldn't have a mynative reference.
moniqui wrote: I'm not sure how to make this C++ class aware of the dll.
I recommend you read this article[^] on wrapping native libaries using C++/CLI.
Often times, if you just need to call one or two functions, the easiest way is through P/Invoke with [DllImport]. But if you're calling lots of functions, structures, or if the native C++ library contains its functionality inside of classes, you're best bet is with C++/CLI.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi Judah,
I wanted to thank you so much for your help. I finally got my wrapper working and can now call functions from my C# application. You're replies really got me on the right track.
Thanks again,
Doreen
|
|
|
|
|
|
You've probably already read some of these, but there are tons of articles on this subject (with examples) at The Code Project: clickety[^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
I have a user control that I have created as a way to plot a function. To make it flexible I defined a delegate that actually represents the function so I can use the control for different functions:
public delegate double Function(double x, double y);
In my control I add a property for the function:
<code>
private Function function;
[Browsable(false)]
public Function Function
{
get { return function; }
set
{
function = value;
}
}
So far so good, I also add a default constructor that specifies a default method to use for the function. I can create a form, add my control to it and run it and it works. The problem is if I any of the properties of the control in the designer, the designer thoughtfully adds this line to the form class:
<code>
this.functionPlot1.Function = ((Function)(resources.GetObject("functionPlot1.Function")));
And this causes a problem in the designer because the GetObject always seems to return null which results in the designer giving me the slightly comical message:
Object of type 'Function' cannot be converted to type 'Function'
Does anybody know what's going on here and how to fix it. I'm not that bothered if I can't see the function being plotting in the designer (but it would be nice if I could), but I'd like to be able to see the rest of the form, but this error stops that. Removing the offending line from the InitalizeComponents method fixes the problem temporarily, but it keeps coming back whenever I change anything.
Thanks.
|
|
|
|
|
How about defining an "example" function which is displayed when being designed?
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Ed.Poore wrote: How about defining an "example" function which is displayed when being designed?
I thought that was what my default constructor was doing and it does work when you initially drag the control on to a form, but if you change any of the properties of the control it adds that line to the InitializeComponents method that seem to cause all the problems.
|
|
|
|
|
I just had a thought, take a look at the DesignerSerializationVisibility with a value Hidden . If you apply this to your property (hopefully) the designer will not generate code for that property.
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Ed.Poore wrote: DesignerSerializationVisibility with a value Hidden
That fixed it! Excellent, thank you.
|
|
|
|
|
Now if only I can fix my designer problems...
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
Hi!
I have the silliest problem - how do I test a connection string? That is, I have a server name, username and password, and database name. How can I test that specified database exists on specified server with the specified sa account?
My first thought was to build a SqlConnection object, try to open it, and if it throws an exception, that means that it 'failed the test'... But there must be some other way to do this, without throwing exceptions... right?
Thanks,
Aleksandra
|
|
|
|
|
When creating (if you do) the connection string in VS there's a button somewhere which says "Test Connection"
Although it probably does what you were thinking of doing anyway
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
Ed, I have to test the connection programatically... I know that there is a button Test connection when you create a connection from VS... Let me explain: I have a form with the following textboxes: server name, username, password, database. When the user enters that data, I have to check that connection - that it really exists... My question is this: is there some other way (some built-in mechanism or something) of doing that than just creating a conenction string, creating a connection object, and waiting to see whether the open() method will throw an exception...
|
|
|
|
|
I think the only way is to trap any exceptions thrown by the Open method, I don't know and cannot see of any other way.
As of how to accomplish this I wouldn't have a clue at the moment and I'm too lazy to google it
|
|
|
|
|
The only other way I can think of is open a connection the server and query the system tables for the database in question. This is of course not a very good option as it requires a higher level of credentials and the storage of two connection strings.
only two letters away from being an asset
|
|
|
|
|
Well, I'll try something Thanks for the reply
|
|
|
|
|
I have created a C# windows forms app.
On a certain click event I perform a console.writeline("Message Text").
The program buils fine, and runs without an error, but I don't get to see any output in a console window.
What must I do to see the output?
|
|
|
|
|
Do you use Visual Studio as your IDE ?
When you create a new Console Application, then you will get an empty Main method.
Just type : Console.WriteLine("Message Text");
It will show "Message Text" in ConsoleApplication.
|
|
|
|
|
there is an output window (in the menu -> view -> Output).
It should come in there somewhere. (note that other stuff comes in there is well.)
you could do this to filter a bit:
<br />
console.writeline("");<br />
console.writeline("Message Text");<br />
console.writeline("");<br /> which will write an empty line before and after your text.
Good luck.
I've found a living worth working for, but I haven't found work worth living for.
<marquee>
|
|
|
|
|
|
You can change the executable to compile as a Console App, nothing stops you from displaying Windows Forms. The only difference is, is that a Console is displayed if not run from a console. If this is only temporary for debugging purposes then you can change it back to a "Windows Forms" project when building for release.
You can also run it from the command-line without having to compile it as a Console Application and that will display the information (basically the Output window mentioned above does exactly this).
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9
Ed
|
|
|
|
|
I have a stored procedure that returns XML using FOR XML AUTO ELEMENTS, but there is no root element in the returned value.
I feel this may be the source of some errors im getting when trying to load the returned value into an XMLDataDocument.
Whats the best way to get a "root" element to ecapsulate the data?
Is there a way to make it return the results with a root? or a simeple way to add one to the datadocument in preperation before placing the returned value into it?
Thanks.
|
|
|
|
|
You might be able to create a XmlDocument with a base root and then set the roots innerXml to your xmldata.
Something like:
<br />
XmlDocument xmlDoc = new XmlDocument();<br />
<br />
xmlDoc.LoadXml("<root></root>");<br />
<br />
XmlNode root = xmlDoc.DocumentElement;<br />
<br />
root.InnerXml = your_xml_data;<br />
Not sure if this will work on first try. Havent got a compiler here but I've
set node.InnerXml successfully before.
Hope it works for you.
-Larantz-
For those about to code, we salute you.
|
|
|
|
|
Python has library 'difflib' which can be used to find coincidence percent between two sequences (strings). I am looking for the way to do the same (compare 2 strings) within .net platform.
So what is the name for an algorithm I am looking for? And where to look for it?
|
|
|
|
|
How can I print to the printer some text and increment any time I print
more text.
my code:
private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
ePrint.Graphics.PageUnit = System.Drawing.GraphicsUnit.Millimeter;
// this go to metoda and return an object PrintPageEventArgs e
MiddleTable mTable = new MiddleTable(e);
mTable.PrintMiddleTable();
TopTable tTable = new TopTable(e)
tTable.PrintMiddleTable();
}
/////////////////
This is the code that will be printing in any page
I want to put him (e) in an obj - because it will be not change.
but when I print I whant to take this obj and add to him another text
I want that the code will not repeat on top will not repeat.
|
|
|
|