|
Easy at it's:
int monitor_height=Screen::PrimaryScreen->Bounds.Height;
int monitor_width=Screen::PrimaryScreen->Bounds.Width;
|
|
|
|
|
I just recently posted a question very similar to this(System::String ^ to LPCVOID conversion?), it was answered but I still must be missing something.
In this case I need a LPCWSTR. What I've tried should be evident in the following:
......
char* pProcName = (char*)(void*)Marshal::StringToHGlobalAnsi(this->ProcName->Text);
LPCWSTR pProcName2 = (LPCWSTR)(void*)Marshal::StringToHGlobalAnsi(this->ProcName->Text);
LPCWSTR test2 = (LPCWSTR) pProcName;
HWND windowHandle = FindWindowW(NULL, (LPCWSTR) pProcName);
if (windowHandle)
MessageBox::Show("SUCCESS");
........
I guess one option is to convert a char* to wchar_t*?
If somehow I could make the conversion correctly, uhg. I really just need someone who knows whats up to point it out to me lol...
|
|
|
|
|
According to the MSDN Documentation[^] StringToHGlobalAnsi() returns a char* , i.e. a pointer to ASCII characters. In order to use this as wide characters you will need to do a string conversion, you cannot just cast it and expect it to work. Use mbtowc() or similar to convert from ASCII to wide characters.
|
|
|
|
|
Yea, I didnt expect it to work. But when you have no other ideas... lol thanks man! Ill give it a go!
|
|
|
|
|
Mattzimmerer wrote: Yea, I didnt expect it to work.
That suggests you would be well advised to spend some time learning what casts are all about. Remember that all the answers are somewhere in MSDN. I know it's not the easiest site to navigate, but the new Bing search is pretty good; it's where I found your answer!
|
|
|
|
|
Mattzimmerer wrote: I guess one option is to convert a char* to wchar_t*?
Why use StringToHGlobalAnsi if you don't want an ANSI string?
Maybe try StringToHGlobalUni.
And don't forget to free the allocated memory when you're done with it!
Since you're wanting wide chars, you also can use PtrToStringChars
(from vcclr.h).
Mattzimmerer wrote: need someone who knows whats up to point it out to me
The documentation knows what's up!
A bunch of interop examples[^] including How to: Access Characters in a System::String[^]
Calling Native Functions from Managed Code[^]
Mark Salsbery
Microsoft MVP - Visual C++
modified on Thursday, January 7, 2010 3:42 PM
|
|
|
|
|
Okay, you guys were a ton of help, but there is still something I am missing. Why dont I just show you what I am trying to do:
I am trying to get a name from a windows forms textbox converted so that I can use it in FindWindowW() so that I can send a PID out to a driver
this code is pretty messy atm, I usually clean it up after I get the proper way to do something. (imo lol)
char* pProcName = (char*)(void*)Marshal::StringToHGlobalUni(this->ProcName->Text);
wchar_t ProcNameWSTR, *pProcNameWSTR = &ProcNameWSTR;
const wchar_t tester[11] = L"Calculator";
int lengthmbc = mbtowc(pProcNameWSTR,pProcName,sizeof pProcName);
unsigned long Returned;
input bInput;
bInput.bytestoread;
bInput.processid;
bInput.startaddress;
HWND windowHandle = FindWindowW(NULL, pProcNameWSTR);
HWND windowHandle2 = FindWindowW(NULL, (LPCWSTR) &tester);
if (windowHandle)
MessageBox::Show("pProcNameWSTR success");
if (windowHandle2)
MessageBox::Show("tester wchar_t success");
DWORD* processID = new DWORD;
GetWindowThreadProcessId(windowHandle, processID);
DeviceIoControl(
hFile,
IOCTL_MZ_READMEMORY,
(LPVOID) &bInput,
sizeof bInput,
NULL,
0,
&Returned,
(LPOVERLAPPED) NULL);
the problem is that I cannot get the contents of ProcNameWSTR to match my tester[11] (the first if check fails and the second succeeds) any insight?
|
|
|
|
|
Mattzimmerer wrote: I cannot get the contents of ProcNameWSTR to match my tester[11]
ProcNameWSTR is a single wchar_t, so isn't very useful here.
Plus you don't even use it anywhere.
Marshal::StringToHGlobalUni returns a const pointer to a wchar_t
string, so casting it to a char* then converting it to a wchar_t
string isnt' going to work.
Try:
const wchar_t *pProcNameWSTR = (const wchar_t *)(void *)Marshal::StringToHGlobalUni(this->ProcName->Text);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
worked great thank you. You know, I tried something like this, I just didnt make it a const, perhaps thats the reason it didnt work... Either that or I threw in some ANSII.. o well thanks man!
|
|
|
|
|
HI
I have DataTable n there is 5 column I had created
I want to get 5 column name and column data type from my datatable to create slq query
"Create Table mytable ([from datatable column name and type 1 to 5 ])"
how to do it ???
thanks
modified on Thursday, January 7, 2010 12:24 AM
|
|
|
|
|
First of all this doesn't sound like a good question
all you are asking is really simple to do, too simple to ask in this forum. Maybe it would be good for you to study an introductory book to this language
i didn't get you real problem but here some hint....
// to get the column number
dataGridView1->Columns->GetColumnCount
// to get the colum name (from column number i)
dataGridView1->Columns[i]->Name
// to get the column value type (from column number i)
dataGridView1->Columns[i]->ValueType
|
|
|
|
|
Hi,
Suppose I have a class named "Bounce". How can i declare array of objects in another class using managed c++?
Thanks to all
modified on Wednesday, January 6, 2010 7:09 AM
|
|
|
|
|
Did you try anything at all?
What is your book telling you?
I would try something similar to:
array < String ^ > ^ tab=gcnew array < String ^ > (200);
|
|
|
|
|
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!
|
|
|
|