|
array size change plus the proper copy nails it.
Thanks very much!
|
|
|
|
|
Hi Mark,
Is there a way to do the reverse of this?
That is, one HGLOBAL to store different images, where it normally is one HGLOBAL relating to one image.
Thanks for the valuable help!
|
|
|
|
|
Hi Developers.
i am going to wrap lib(static library ) file in c++. one function return HGLOBAL DIB. how can i access Byte Array or Bitmap Image from this and pass this Byte Array or bitmap to My C# Project.
please help me.
thanks in advance.
Here is function that return HGLOBAL DIB Type.
<pre lang="c++"> HGLOBAL m_hDib;
int retval = XRaySensorIsImageAvailable();
if ( 0 < retval )
{
if (m_hDib ) ::GlobalFree(m_hDib);
m_hDib = XRaySensorGetDIB();
}
|
|
|
|
|
Hi
How can i get the screen width and height in Managed C++/CLI? I have used
Screen^ screen = gcnew Screen::PrimaryScreen;
But its not working.
Thanks
|
|
|
|
|
Within the Screen class, PrimaryScreen is a property, not a constructor. So you don't need gcnew
FYI1: "its not working" is not informative; if there is an error or exception, best is to show us the message.
FYI2: all this is explained in the documentation. Maybe it would be wise to study an introductory book when getting acquainted to a new technology or language.
|
|
|
|
|
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.
|
|
|
|