|
It's far more common these days to use a generic list, such as System::Collections::Generic::List.
List<bounce> ^ myList = gcnew List<bounce>();
Removing and inserting is easier this way.
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
|
|
|
|
|
Hello, I have another problem:
I would like to use ArrayList for collecting of unknown number of System::Drawing::Point structures. But I´m not able to use it in some GDI+ drawing functions feg. Graphics::DrawCurve(...). It forces me to use cli::array<point>, it is totally ugly, I ended up with something like this:
ArrayList^ arr = gcnew ArrayList;
arr->Add(Point(0, 0));
arr->Add(Point(25, 25));
arr->Add(Point(50, 75));
arr->Add(Point(75, 100));
.
.
arr->Add(Point(225, 325));
array<Point>^ pt = gcnew array<Point>(arr->Count);
for(int i = 0; i < arr->Count; i++)
pt[i] = (Point)arr[i];
g->DrawCurve(pen, pt);
It works, but... Is there a better way to do something like this? I'm sure I'm wrong, but I learn C++/CLI about an hour . There are no such problems if I use GDI+ in Win32 API, MFC...
|
|
|
|
|
Use a list and it's 'ToArray' method:
List<point>^ arr = gcnew List<point>();
g->DrawCurve(pen, arr.ToArray());
David Anton
Convert between VB, C#, C++, & Java
www.tangiblesoftwaresolutions.com
|
|
|
|
|
Thank you for a fast reply, it helped.
Actually I have found ToArray() function previously, I used it (but with ArrayList) in trials with both C# and C++/CLI, but it doesn't compile in C++/CLI, I got error C2664. In C# I was able to cast it, it does compile and work, not so in C++.
Btw., it still copies one array into another as I did, it looks much more clean, but again not very efficient...
I used to write same app in C# and C++/CLI for learning, to see, which .NET code will look better for me. I use native C/C++/ASM long time professionaly, I work as a lead programmer on a big, well known engineering computational SW package, written mainly in native C++. It has an extensive GUI (our boss is GUI guy ), which we would like to port to some C family .NET language, maybe with WPF.
|
|
|
|
|
hi
can anyone can help me i'm trying to insert my dataset or datatable into
sqlite.net
and I don't have any clue
can anyone create some sample ??? with c++ clr form
thanks
|
|
|
|
|
Im trying to use WriteFile() to communicate with a driver, the information its sending is to be text from a Windows Forms textbox. I've tried so much to get it to work properly but it only seems to work if I do the following for WriteFile():
WriteFile(hFile, "this is the only way it works", sizeof("this is the only way it works");, &dwReturn, NULL);
Im pretty lost and I would appreciate any help!
Heres what my code looks like:
System::String ^str = this->Address->Text;
LPCVOID lpBuffer = str;
WriteFile(hFile, lpBuffer, sizeof(lpBuffer), &dwReturn, NULL);
CloseHandle(hFile);
and the compiler output:
1>c:\users\matt_zimmerer_testos\desktop\zmdalpha1.0\gui\zmdinterface\Form1.h(170) : error C2440: 'initializing' : cannot convert from 'System::String ^' to 'LPCVOID'
EDIT: minor grammar error fixed
modified on Saturday, January 2, 2010 5:06 PM
|
|
|
|
|
System::String is a managed type and needs to be converted to a character array before you can cast it to a simple pointer. Take a look at the System::String[^] class, for more information.
|
|
|
|
|
Hi,
i am looking for help in implementing a thesaurus application for a data structure project, but have trouble in finding the best data structure to represent the thesaurus, also if anybody could direct me in how to start the coding in C++ or C# would be a great help.
1. i have so far considered trees and linked lists as a possible solution, the tree for storing the words and the linked list for returning the set of synonyms but i do not know how to store the words in the tree for best searching and how to link up the tree with the linked list..
so any help or pointers would be a great help
|
|
|
|
|
helawae wrote: best data structure to represent the thesaurus,
Are you trying to represent the whole thesaurus in memory?
helawae wrote: i have so far considered trees and linked lists as a possible solution, the tree for storing the words and the linked list for returning the set of synonyms but i do not know how to store the words in the tree for best searching and how to link up the tree with the linked list..
Tree and linked lists seems to be good choice. Each node represents a term and contains a list of related terms. This can nest up to any level. However, keeping the whole thesaurus in memory and searching in it is quite inefficient. I'd suggest to keep the data in a database and query against it when you need a lookup. Load the term and related terms into the above said data structure and return. You can load each level of this tree on demand. So you will not waste any memory by storing data that you don't need.
helawae wrote: direct me in how to start the coding in C++ or C# would be a great help.
Take a look at file based databases like SqlLite . Create relational tables and keep the data inside it. Probably two tables, one is the master list of all terms and second one is the relationships. When you need to do a lookup, join both tables and get the data.
Hope that helps
Best wishes,
Navaneeth
|
|
|
|
|
hey thanks for the last reply, it was helpful but there are somethings i still do not understand(sorry!)
1. When you say "keeping the whole thesaurus in memory and searching in it is quite inefficient. I'd suggest to keep the data in a database and query against it when you need a lookup. Load the term and related terms into the above said data structure and return"
if searching in memory is inefficient and keeping the data in a database and query against it whenever i need a look up say for example i have one table with the root words(words that are stored in the tree nodes) and another table storing the synonyms(the words maintained in the linked list) and an associated foreign key representing the words in the first table is stored with each words in the second table then why do i need to return the result of the query to the above data structure why can i not simply display the results of the query to the user directly!
2.What is meant when you say "You can load each level of this tree on demand".
I thought of using two structs like
Struct RootTree{
RootTree* Node;
string word;// the actual words stored in the tree
SynList * pointer;// a pointer to the linked list maintaining the //synonyms
}
Struct SynList(
SynList* Nod;
string syns;
synList* pointer;// a pointer to the next Nod in the linked list
)
Now how do i nest this to several levels and where is the actual search implemented in the database or in the structs!
thank you again!
|
|
|
|
|
helawae wrote: why can i not simply display the results of the query to the user directly!
Possible. But by populating the data structure helps you to do caching and return results from the cache when user searches for the same term again. Do what makes best sense for your problem. But don't ever try to keep the whole data in memory.
helawae wrote: What is meant when you say "You can load each level of this tree on demand".
Ignore that. You should be good with the other things what I explained. Implement demand loading only when it requires.
Best wishes,
Navaneeth
|
|
|
|
|
hey thanks for the whole help!It has been really useful. i have solved the problem and the thesaurus is finished! i used a trie structure instead of the linked list and tree, like u have pointed out i have kept the whole data in the database and retrieved information from it when only the user types in the words. thanks again for all the help!
|
|
|
|
|
Glad to hear that.
Best wishes,
Navaneeth
|
|
|
|
|
hi ,
I'm New In C++ FORM crl Programing
I Want to Register Data to registry
I check Sample Code in MSDN
like this :
RegistryKey ^ regkey = Registry::LocalMachine->CreateSubKey("SOFTWARE\MYSOFTWARE\DATA");
And I got no error and 2 warning
11>------ Build started: Project: MULTINET_EXPLORER, Configuration: Debug Win32 ------
1>Compiling...
1>MULTINET_EXPLORER.cpp
1>d:\multinet explorer\multinet_explorer\Form1.h(222) : warning C4129: 'M' : unrecognized character escape sequence
1>d:\multinet explorer\multinet_explorer\Form1.h(222) : warning C4129: 'M' : unrecognized character escape sequence
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://d:\MULTiNET EXPLORER\MULTINET_EXPLORER\Debug\BuildLog.htm"
1>MULTINET_EXPLORER - 0 error(s), 2 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
but when the program runing it always gon error message
like this
An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The parameter is incorrect.
how can I solve this Problem ???
can anyone help me ???
|
|
|
|
|
Hi,
in C-like languages string literals treat backslash as a special character; the character following it determines the exact meaning (e.g. \t represents a TAB). To get a simple backslash, you should double it: "SOFTWARE\\MYSOFTWARE\\DATA"
I would suggest you buy and study a book on C++/CLI to get the fundamentals right.
|
|
|
|
|
Hello
Dear friends
I am stuck with this problem of combobox.It is proyect of Visual c++,i have two comboboxes ,my task is to select one item from one combobox ,and the item corresponding to this in the other combobox will select automatically.
Merry christmas and Happy new year
waiting for your kind help
|
|
|
|
|
Assuming you are using C++/CLI. Handle the first combo box's SelectedIndexChanged[^] event and populate the second one accordingly.
Best wishes,
Navaneeth
|
|
|
|
|
i have done a bit of reading in client/server programming in c#. i am familiar enough with this process to ask the following question:
how do i transmit structure objects through tcp/ip instead of just strings?
my app is a networked game with chat capabilities. so instead of just transmitting text, i would like to imploy a data structure or class structure that will have two fields: i. packet type ii. the data for the packet type
and i would transmit this when needed during the execution of the application, and decode the data object at the receiving end and place it where it belongs.
im not looking for code, just some ideas and search statements i can feed to google so i will; have a better understanding.
ive read about serialisation/de serialisation, is that he way to go?
thanks.
|
|
|
|
|
See serialization and deserialization of objects.
I use BinaryFormatter for this job.
|
|
|
|
|
i just read the following:
The Binary Formatter
The Binary formatter provides binary encoding for compact serialization either for storage or for socket-based network streams. The BinaryFormatter class is generally not appropriate when data is meant to be passed through a firewall.
--------------------
is Xml Serialization good for going through firewalls?
|
|
|
|
|
ikurtz wrote: The BinaryFormatter class is generally not appropriate when data is meant to be passed through a firewall.
I don't see that in the documentation for the BinaryFormatter class[^]
If you're using sockets, you already have an issue with firewalls.
If you can connect the sockets, then the data you put over the wire
isn't an issue - socket data is always binary. The binary formatter
is for converting your objects to/from binary (binary serialization).
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
thats exactly what i thought (after some thought!). because the data is embedded it should not make a difference.
well one comes across all kinds of statements made on the web. one has to be able to use ones judgement also.
|
|
|
|
|
As others said, you can use binary serialization to send data over the wire. But take a look at projects like Protocol Buffers[^] also. There is a .NET port available and it makes data transmission easy and it does serialization and deserialization for you.
Best wishes,
Navaneeth
|
|
|
|
|
I've written a managed class that handles the serial communication to a laser using ascii text. My problem is if my GUI makes too many calls to the functions in the laser communication class I get the wrong responses back from the laser. They are valid responses but it appears as if the response from the first call is being replaced by the response from the second call. I've attempted to control the usage of the serial port by using 'Mutex.WaitOne' but that doesn't seem to have an affect. All the calls to the laser are being generated by Windows' messages within the GUI. Does anyone know of a way to control the flow of calls to the laser class? I'm using Visual Studio 2008 and Managed C++.
Thanks,
George
George
|
|
|
|
|
Why don't you try sending one command and waiting for the response before sending the next command?
|
|
|
|