|
Wrapping native objects means, you create a managed class in C++/CLI and hide your hdf_call_vars_t struct inside this managed class. Your library will only deal with this managed object and at the C# side you only have to deal with this managed object. This approach hides all the complexities of using native structs and simplifies your library's interface.
Here is working example of wrapping native object in a managed object.
using namespace System;
namespace Example {
struct hdf_call_vars_t {
int foo;
};
public ref class HdfCallVars
{
private:
hdf_call_vars_t* native;
public:
HdfCallVars()
{
native = new hdf_call_vars_t;
}
property int Foo
{
int get()
{
return native->foo;
}
void set(int value)
{
native->foo = value;
}
}
};
public ref class YourLibrary {
public:
int ReadFile(String^ file_path, HdfCallVars^ ret_vals)
{
return ret_vals->Foo;
}
};
} To use this library from a C# application,
using System;
using Example;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
HdfCallVars vars = new HdfCallVars();
vars.Foo = 10;
YourLibrary library = new YourLibrary();
int status = library.ReadFile("filepath", vars);
Console.WriteLine(status);
Console.Read();
}
}
}
Hope that helps.
Best wishes,
Navaneeth
|
|
|
|
|
Thank you so very much for taking the time to answer in such detail, Navaneeth! I learned a lot from your code. I do have a question though. Since my hdf_call_vars_t is a complex structure containing members whiuch are instances of other structs, how do I treat those? For example, it has a member 'struct channel_vars p_data.' A channel_vars type struct instance contains in it ints, doubles, enums and a void * . I'll of course create get set accessors for Channel_vars as you have shown for the int foo in your example.But do I need to make Channel Vars a wrapper class also?
thank you,
saroj
|
|
|
|
|
bonosa wrote: But do I need to make Channel Vars a wrapper class also? If that is something which user has to create, you need to make it a managed class. All your internal structures don't need to be wrapped because you handle the creation of those inside your main managed object.
Best wishes,
Navaneeth
|
|
|
|
|
Thanks Navaneeth, that almost compiled!
Now I have a problem!
int atClass1::read_file
(String^ file_path,
HdfCallVars % ret_vals)
I did the above as you advised.
However ret_vals has to be fed to an HDF5 function which needs a void* as one of it's arguments.
So I am stuck at the following line of code not knowing what to do:
io_err = H5Literate (group_id, H5_INDEX_NAME, H5_ITER_NATIVE,
&i, get_data, (void*)&ret_vals);
the compiler doesn't like (void*)&ret_vals....
What to do?
thanks,
saroj
|
|
|
|
|
bonosa wrote:
the compiler doesn't like (void*)&ret_vals.... Add a method to HdfCallVars so that it can give you the underlying native struct.
Best wishes,
Navaneeth
|
|
|
|
|
I wrote a blog post which covers the topic in detail. Take a look at this[^].
Best wishes,
Navaneeth
|
|
|
|
|
Navaneeth, your Main is written in C++ right? My main is in C#
thanks!
|
|
|
|
|
I've had a personal project in mind lately. Part of it will include user-created fields/field types. Think of it as an inventory control system. Each object will have common properties but I want the user to be allowed to create so many custom fields for each item type. As far as storing the custom fields, I know how I will achieve that aspect of it.
What I would like to know is how I should go about generating a dynamic view for those custom fields. I considered a "table" (DataGridView) at first. But I decided I would like to go with something more user friendly. It doesn't necessarily need to be a user-defined layout. But how can I present it in such a way that it's a Label control and then a TextBox control? My thought on it so far is to possibly use a TableLayoutPanel and add the controls for each custom field as necessary. Would this be an efficient solution or is there a cleaner solution?
If something like a TableLayoutPanel is the right tool for this, that's fine. I don't mind going that route. I just wanted to get some feedback from others before I continue.
I'm using VS2010 and C# 4.0.
Thanks a bunch!
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
|
Thank you, Orjan, for the suggestion. I hadn't thought about the PropertyGrid control. I'll look at the links more in depth here in a little bit. Currently I'm at work and have some things to get done throughout the day. But thanks for the info, I'll keep that in mind.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
For a simple report runner I wrote a few years back I cobbled up a Form with Labels, TextBoxes, DateTimePickers, etc. on the fly based on the parameters of the report (Crystal or my own).
|
|
|
|
|
I used below code to start service.
var sc = new System.ServiceProcess.ServiceController("ELSRegressionService");
if (sc.Status.ToString().Equals("Stopped"))
sc.Start();
Its working fine, when logged in with Administrator credentials. If I login with other user credentials, it throws exception, "Cannot open Servicexxx service on computer 'COMPUTER_NAME'"
I would like to ask for credentials before the user tries to start service. So please guide me to check for credentials to start windows service programmatically. Thanks in advance
|
|
|
|
|
NarVish wrote: if (sc.Status.ToString().Equals("Stopped")) Correct way to do the check is
if (sc.Status == ServiceControllerStatus.Stopped) {
sc.Start();
}
NarVish wrote: I would like to ask for credentials before the user tries to start service. Read about Application manifest and UAC[^].
If you need administrator privilege only for starting the service, you could delay request for elevation till you need it. This can be done by starting a new process and setting ProcessStartInfo.Verb[^] to runas . This new process can execute the code to start/stop the service. You need the new process because you can't change elevation levels of the current process while it is running.
Best wishes,
Navaneeth
|
|
|
|
|
If you're going to be asking for a username and password, what's the problem?? It's two labels and two textboxes on a small form and showing it!
|
|
|
|
|
i have datagridview whose datasource is assigned to datatable and 2 buttons.
click on up button should move my row up.
and click on down button should move row down.
it gives error.
"Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."
|
|
|
|
|
That is not an error, it is an explanation, which tells you why you cannot change the position of the rows in the grid; because they are bound 1 to 1 with rows in the data source.
|
|
|
|
|
|
hey guys !
its really a dim point for me that can we write some codes to control a robot? or write some code for a external hardware?
|
|
|
|
|
You can write code with C# to control external devices, as long as they use any one of a number of standard protocols.
|
|
|
|
|
Yes you can. But you need to know how many axes the robot has and how to move the axes. If you bought the robot from a third party then they will be giving you the interface lib to communicate with the robot. some vendors sell C++ interface some have .Net libraries.
|
|
|
|
|
hi
I I made a game called snakes and ladders. I want this game to become object-oriented and how do I write?
modified 13-Feb-13 11:59am.
|
|
|
|
|
I doubt any one here go to your link and download the files from a unknown link. It's better you to update your query with some more details about the current design of your game so that others can see it and suggest a better method for you.
|
|
|
|
|
ok
for example this function are for change picture
this function in from1 :
public void tas_pic()
{
int rand = tas.taas();
for (int i = 1; i <= 6; i++)
{
PictureBox picbox = ((PictureBox)this.Controls["pb" + i.ToString()]);
picbox.Visible = false;
}
PictureBox picboxtas = ((PictureBox)this.Controls["pb" + rand.ToString()]);
picboxtas.Visible = true;
}
-------------------------------------------------
i cant move to a class as method and use this method in form1
What should I do?
|
|
|
|
|
First, the code you wrote is perfectly suitable for procedural as well as for object oriented programming. The differences between those are one abstraction layer above that.
Second: form. You were asked to improve your question. Do so instead of posting a new message. There's an "Edit" link beneath your message that's only visible to you when your'e logged in.
Please wrap code snippets in <pre lang="c#">YourCodeHere</pre> so it is better readable.
Ciao,
luker
|
|
|
|
|
saber_ershadi wrote: I want this game to become object-oriented and how do I write? By studying some books and tutorials. Google will find many samples for you.
|
|
|
|