|
I am using Managed C++ (VS .NET 2003 SP1), so I can't use any of the new features in C++/CLI (VS 2005).
I have a function that needs to take in a const reference to a native class, e.g.,
void MyManagedClass::f(const UnmanagedClass& u); If I just call it straight, like (inside another member function of MyManagedClass ):
UnmanagedClass u;
f(u); then it works OK. However, I would like to call this function in another thread. I have something like this, but it doesn't work:
__delegate System::Void ThreadDelegate(const UnmanagedClass&);
UnmanagedClass u;
ThreadDelegate* td = new ThreadDelegate*(this, f);
Object* args[] = new Object*[1];
args[0] = &u;
Invoke(td, args);
The problem is passing the parameter to the delegate. I would rather not have to write a managed wrapper for my unmanaged class if it can easily be avoided. Is there any way to do what I want? I have tried putting in __nogc in various parts of the array declaration but I can't get it to compile.
--
Marcus Kwok
|
|
|
|
|
Hi All,
I have a design question and I am looking for a best way to implement it.
Say I have a method which returns a string e.g.
string str = MyMethod();
MyMethod returns a string from one of the predefined strings. Based on the return value I need to execute certain sequence of methods. I do not want to implement it using an ugly if-else statements, so what is my best bet to implement it. I am looking for something like auto dispatching based on return values. Also the number of predefined strings can go up in future, so I do not really want to touch the code everytime a new string is added.
I have thought of associative array's based solution. The array will store the string to method mapping and based on the return value the correct method will be invoked. But I am not sure if this is an elegant solution.
Can someone please guide me on how to go about for an elegant solution.
Thanks and Regards.
|
|
|
|
|
switch (str)
{
case "test1"
break;
default:
break;
}
|
|
|
|
|
Hi Bsaksida,
You cannot use strings in case statement, even if you could, you will still need to modify the code if new strings are added. What I am looking for is an independed dispatch engine.
Thanks.
|
|
|
|
|
It sounds like you are asking about a "plug-in" implementation.
psychedelic_fur wrote: the correct method will be invoked.
Well that approach would be similar to the old C function pointer technique. OO concepts introduced "interfaces" which are preferable from a design standpoint. It is also referred to as Design by Contract[^]
Anyway a simplified version of this for a "plug in" implementation could go like this:
Design one or more interfaces (see Design by Contract). Each plug-in (class) will implement one or more of these interfaces. Along with the interfaces you design a "configuration" scheme for giving the application the required information about new classes that have been installed. Then you can leverage the System.Reflection classes to dynamically instantiate an object from it's text name (basically). Using this approach you can add new classes to an application by installing a new assembly and adding the requisite information to the applications configuration file.
led mike
|
|
|
|
|
Hi, i would like to know how to go about reading and writing config files in C++/CLI.
After clicking on 'open' in the menustrip, i would like to open a config file, and after editing its contents, i would like to know how to save it.
|
|
|
|
|
http://users.volja.net/bsaksida/alt.zip[^]
Whis is my finished project, and was newer published. You can use it to translate lng files. (Design for ArtMoney) You can use it as you see fit.
point of Intrest:
Public: OpenLNG(..) //In this function it opens a file.
public: SaveTranslation(..) //in this function it saves a file
ps: This project was compiled under VS2003
|
|
|
|
|
do you know of the method in .NET 2005 that can help me work on config files?
in the config files, i need to pass string through..
basically, i need to write and read config files to store values in string.
PS:i dont know how to use your codes as i dont understand them, thanks for attaching them. (:
|
|
|
|
|
Diffrence with VS2005 and VS2003 is only syntax. But callining a function or property is same order.
1. When you says config file. Did you first think how it will look it:
examples 1:
1="this var"
example 2:
options "variable"
example 3:
Font:Arial
When you have your basic syntax for config file, then you have to write reader code, witch will split into VariableName and VariableItself
|
|
|
|
|
let say for example, if i want to write a config file to store string, how do i go abt doing that? and how do i read config files after writing them?
im totally new to config files and C++, and i need guidance in understanding them, bear with me pls.
|
|
|
|
|
String ^file = gcnew String ("c:\\config.txt");
FileStream ^fs = gcnew FileStream(file, FileMode::OpenOrCreate, FileAccess::Write);
StreamWriter ^sw = gcnew StreamWriter(fs);
sw->WriteLine("Line1");
sw->WriteLine("Line2");
sw->WriteLine("Line3");
sw->WriteLine();
sw->WriteLine("Line5");
sw->Close();
fs->Close();
fs = gcnew FileStream(file, FileMode::Open, FileAccess::Read);
StreamReader ^sr = gcnew StreamReader(fs);
while (!sr->EndOfStream)
{
MessageBox::Show(sr->ReadLine());
}
sr->Close();
fs->Close();
|
|
|
|
|
mactick wrote: i would like to know how to go about reading and writing config files in C++/CLI.
They hide that information in the documentation[^]
led mike
|
|
|
|
|
ok i am beginner in c programming language can you help with c i have assignment but i cant do it
if you want help me please email me :alisher2005@hotmail.com
|
|
|
|
|
I think you should begin with finding out how message boards work.
First thing is to find the right message board, in this case you are in the wrong one.
This message board is only for C++/cli.
Second thing is that you never ever ask someone to do your homework.
With this said I think you should google a c tutorial or buy a book.
Good luck.
|
|
|
|
|
|
Can I serialize a class object in Dialog based application, if yes, can anybody let me know how to do that one. If not, then how to do it in an alternate way?
Thanks in advance,
Sunil Jampa.
|
|
|
|
|
This is wrong forum for this question. Use VC++ fourm instead.
And have look at this[^] before asking doubts.
|
|
|
|
|
with this example i always get -1 as output.
ListView::ColumnHeaderCollection ^test = lstListUsers->Columns;
Int32 test1 = test->IndexOfKey("ID");
i Want to get index number for Specific Column. Can somebody help me with it?
Thanks in advance
|
|
|
|
|
Can you post the code you're using to create the headers in the control?
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
Josh Gray wrote: Can you post the code you're using to create the headers in the control?
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_ID)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_ID_DISPLAY_NAME, 50);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_ID)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_USERNAME)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_USERNAME_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_USERNAME)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_PASSWORD)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_PASSWORD_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_PASSWORD)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_FIRSTNAME)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_FIRSTNAME_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_FIRSTNAME)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_LASTNAME)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_LASTNAME_DISPLAY_NAME, 100);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_LASTNAME)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_CITY)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_CITY_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_CITY)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_ADDRESS)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_ADDRESS_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_ADDRESS)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_PHONENUMBER)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_PHONENUMBER_DISPLAY_NAME, 110);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_PHONENUMBER)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_EMAIL)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_EMAIL_DISPLAY_NAME, 150);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_EMAIL)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_JOINDATE)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_JOINDATE_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_JOINDATE)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_LOGINLEVEL)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_LOGINLEVEL_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_LOGINLEVEL)
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_GMT)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_GMT_DISPLAY_NAME, 80);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_GMT
#if defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_COMMENT)
lstListUsers->Columns->Add(TABLE_USERS_COLUMN_COMMENT_DISPLAY_NAME, 150);
#endif //defined(USER_POWER_TABLE_USERS_ENABLE_COLUMN_COMMENT)
|
|
|
|
|
Yuk,
Why are you inserting the column using a #define for the name but then not using the same #define as the key to find the column?
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
Before i posted in this forum, that was my first choice, but all i tried, put out just -1.
I wan't this index number, when i click on it and then click delete, i woud know, witch cell to read. I am using alot of #define for enormous setting. Some coud be disabled. If i can't find by ID, will try by Username or email. (Only 3 options that can be unique). ps i have almost all Columns enabled, except Comment.
|
|
|
|
|
Try to create a very small test program that has the same problem without all the #defines and post the code
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|
|
listView1->Dock = DockStyle::Fill;
listView1->View = View::Details;
listView1->FullRowSelect = true;
listView1->Columns->Add("Col1", 100);
listView1->Columns->Add("Col2", 100);
ListViewItem ^lvItem = gcnew ListViewItem();
ListViewItem::ListViewSubItem ^lvSub1 = gcnew ListViewItem::ListViewSubItem();
lvItem->Text = "Cell1";
lvSub1->Text = "Cell2";
lvItem->SubItems->Add(lvSub1);
listView1->Items->Add(lvItem);
ListView::ColumnHeaderCollection ^test = listView1->Columns;
Int32 test1 = test->IndexOfKey("ID");
MessageBox::Show(test1.ToString());
And it is still same. I get -1
|
|
|
|
|
Because your columns are called "Col1" and "Col2" not "ID"
System.IO.Path.IsPathRooted() does not behave as I would expect
|
|
|
|