|
As I said, you can do exactly the same in C++/CLI.
If you don't know the correct syntax, study a book on the language.
If you tried and failed, show us your code and the compiler's reaction to it.
If all else fails, use a conversion tool to convert your C# source file into C++/CLI
(or build a C# program, then use .NET Reflector to show you the equivalent source code in the language of your choice; C++/CLI is called MC++ inside Reflector)
|
|
|
|
|
|
jashimu wrote: I have done in C#
How you did it on C#? The basic idea is to pass the necessary information from one from to other through the constructor or public methods on the other form.
Best wishes,
Navaneeth
|
|
|
|
|
Hi All,
I am using windows media player activex control using c++ builder. It is working fine to play the url but when I adjust the height and width from the code this is adjust to the old position which i use onto the form.
for example I adjust the activex player width 720 and height 576
now I adjust the player width and height from the code like
WindowsMediaPlayer1->Width = 320;
WindowsMediaPlayer1->Height =240;
but it will resize to old width height.
how i resolve this problem.
|
|
|
|
|
Hello,
I would like to know "How to instantiate winforms in MFC dynamically, [CWinFormsControl, CWinFormsView etc are template classes which needs compile time declarations for managed controls to be instantiated]". Is there any approach to insiantiate managed controls[winforms] to be instantiated in native code. Please can someone help me.
Thanks,
|
|
|
|
|
Believe that CWinFormsView constructor only need the typeid of the .NET usercontrol. This can be provided at runtime.
|
|
|
|
|
Hi!
I click on a button and a popup(style) dialog appears. I then call a runmodalloop function which recieves a certain amount of data and after it finishes the main window refreshes and shows the data. What i would like to do is, have access to the main window while the runmodallloop is active ( dialog runs in the background). I tried with starting a new thread, and putting the function in it but it won't give me access. Afterwards i made the dialog as a child and set the main wnd as the parent.And after the child finished with the modal loop the program frooze.
Code:
CWinThread *pThread2 = AfxBeginThread(CMainWnd::GetData, &dialog,0,CREATE_SUSPENDED);
pThread2->Run();
UINT CMainWnd::GetData(LPVOID lpDialog)
{
ASSERT( lpDeliverWizard);
CDialog *dialog1 = (CDialog *) lpDialog;
CWnd * hwnd = dialog1->GetOwner();
dialog1->SetParent(hwnd);
dialog1->RunModalLoop();
return 0;
}
Any suggestions?
|
|
|
|
|
spedy666 wrote: Any suggestions?
This isn't .NET code. Don't post unmanaged code in a forum about managed C++/CLI!
|
|
|
|
|
Hey Folks
I'm writing a little telnet client, after a few days
i had it working for receiving, but it refuses to send.
Someone has a idea what is going wrong or what i'm overlooking?
here are 2 send parts one normal and one asynchrone
Normal:
array<Byte>^ SendMessage = Encoding::ASCII->GetBytes("DATA TO SEND");
Sock->Send(SendMessage, SendMessage->Length, SocketFlags::None);
Asynchrone:
public: void SendMessage(String^ UserMessage)
{
if (Sock == null || Sock->Connected == false)
{
text_output->Text += "\nERROR: First connect before sending data.\n";
return;
}
try
{
array<Byte>^ SendMessage = Encoding::ASCII->GetBytes("DATA TO SEND");
Sock->BeginSend(SendMessage, 0, SendMessage->Length, SocketFlags::None, gcnew AsyncCallback(this, namesp_class::SendData), Sock);
}
catch (...)
{
text_output->Text += "ERROR: Could not send message.\n";
}
}
public: void SendData (IAsyncResult^ ar)
{
Socket^ s = (Socket^)ar->AsyncState;
int send = s->EndSend(ar);
}
If anyone is interested here's the rest
Socket^ Sock;
array<Byte>^ InputBuffer;
public: void Telnet_Load()
{
Delegate_AddMessage = gcnew AddMessage (this, namesp_class::OutputMessage);
this->output_textbox->TextChanged += gcnew System::EventHandler(this, namesp_class::output_textbox_TextChanged);
}
public: void Read(String^ Host, int Port)
{
Cursor = Cursors::WaitCursor;
try
{
if (Sock != null && Sock->Connected == true)
{
Sock->Shutdown(SocketShutdown::Both);
sleep(10);
Sock->Close();
}
Sock = gcnew Socket(AddressFamily::InterNetwork, SocketType::Stream, ProtocolType::Tcp);
IPEndPoint^ ip = gcnew IPEndPoint (IPAddress::Parse(Host), Port);
Sock->Blocking = false;
AsyncCallback^ onconnect = gcnew AsyncCallback(this, namesp_class::OnConnect);
Sock->BeginConnect(ip, onconnect, Sock);
}
catch (...)
{
Invoke (Delegate_AddMessage, "ERROR: Could not connect to remote machine.\n");
}
Cursor = Cursors::Arrow;
}
public: void OnConnect(IAsyncResult^ ar)
{
Socket^ s = (Socket^)ar->AsyncState;
try
{
if (s->Connected == true)
{
Invoke (Delegate_AddMessage, "Connected.\n");
SetupReceiveCallback(s);
}
else
{
Invoke (Delegate_AddMessage, "ERROR: Could not connect to remote machine.\n");
}
}
catch (...)
{
Invoke (Delegate_AddMessage, "ERROR: Unknow error during connect.\n");
}
}
public: void SetupReceiveCallback(Socket^ s)
{
InputBuffer = gcnew array<Byte>(InputBufferSize);
try
{
AsyncCallback^ Receive = gcnew AsyncCallback(this, namesp_class::OnReceivedData);
s->BeginReceive(InputBuffer, 0, InputBuffer->Length, SocketFlags::None, Receive, s);
}
catch(...)
{
Invoke (Delegate_AddMessage, "ERROR: Setup receive callback failed.\n");
}
}
public: void OnReceivedData(IAsyncResult^ ar)
{
Socket^ s = (Socket^)ar->AsyncState;
try
{
int bytes = s->EndReceive(ar);
if (bytes > 0)
{
String^ receivedmessage = Encoding::ASCII->GetString(InputBuffer, 0, bytes);
receivedmessage = "> " + receivedmessage + "\n";
array<Object^>^ stringarray = {receivedmessage};
Invoke (Delegate_AddMessage, stringarray);
SetupReceiveCallback(s);
}
}
catch (...)
{
Invoke (Delegate_AddMessage, "ERROR: error during data receive.\n");
}
}
public: void CloseConnection()
{
if (Sock != null && Sock->Connected == true)
{
Sock->Shutdown(SocketShutdown::Both);
sleep(10);
Sock->Close();
}
}
public: void OutputMessage (String^ Message)
{
String^ FirstChar = Message[0].ToString();
if (FirstChar == ">")
{
output_textbox->SelectionColor = Received_Message_Color;
output_textbox->SelectedText += Message;
}
else
{
output_textbox->SelectionColor = Program_Message_Color;
output_textbox->SelectedText += Message;
}
}
public: void output_textbox_TextChanged(System::Object^ sender, System::EventArgs^ e)
{
output_textbox->Focus();
output_textbox->SelectionLength = 0;
output_textbox->SelectionStart = output_textbox->TextLength;
output_textbox->ScrollToCaret();
}
modified on Sunday, August 29, 2010 10:29 AM
|
|
|
|
|
the synchronous one seems almost correct, as the doc[^] says:
public int Send(
byte[] buffer,
int size,
SocketFlags socketFlags
)
Are you sure the async one fails?
|
|
|
|
|
Hey Luc
I'm sorry i see the mistake in the code, i deleted the code when i wrote the async
but for here put the sync one back to show what i tried but made the mistake.
when i put:
Sock->Send(SendMessage, SendMessage->Length, SocketFlags::None);
Like it was then it still won't work.
i send the data but get no reply from the server.
i put the source in a rar it's on http://www.rikterveen.nl/Telnet.rar
modified on Wednesday, September 1, 2010 8:05 AM
|
|
|
|
|
We have an activex control where C++/CLI components interact with WPF controls; instance of WPF controls wrapped in gcroot<> in the C++/CLI components. Problem started when we hosted the activex control in IE, where calls starting from unmanaged zone always get into the default appdomain whereas WPF controls get created in the the 'localhost' or 'web page' specific appdomain. I want to know if there is a possibility to get the unmanaged calls start from the 'web page' appdomain.
Thanks & Regards
Venkatesh
modified on Friday, August 27, 2010 7:21 AM
|
|
|
|
|
Hi everyone, I am having some deficulty delete dataGridView rows From My DataGridView.
I tried following:
for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
{
this->s_dataGridView->Rows->RemoveAt(j);
}
and
int j = this->s_dataGridView->RowCount;
while(j<=0)
{
this->s_dataGridView->Rows->RemoveAt(j);
rowCount --;
}
it seems like not working.
Yes I found My own Solution
this is how it works when the entire row collection is needed to delete;
for each (System::Windows::Forms::DataGridViewRow^ row in this->securityCodedataGridView->Rows)
{
this->securityCodedataGridView->Rows->Remove(row);
}
modified on Monday, August 23, 2010 11:28 AM
|
|
|
|
|
Explanation:
for(int j =0;j<this->s_dataGridView->Rows->Count;j++)
{
this->s_dataGridView->Rows->RemoveAt(j);
}
for(int j =0;j<this->s_dataGridView->Rows->Count-1;j++)
{
this->s_dataGridView->Rows->RemoveAt(j);
}
and again
int j = this->s_dataGridView->RowCount;
while(j<=0)
{
this->s_dataGridView->Rows->RemoveAt(j);
rowCount --;
}
int j = this->s_dataGridView->RowCount-1;
while(j>=0)
{
this->s_dataGridView->Rows->RemoveAt(j);
j--;
}
|
|
|
|
|
Hi barbetto80, Thanks so much for your help. Sometimes little mistake can go very wrong.
Now it is working.
thanks again
|
|
|
|
|
the logical approach:
while(RowCount!=0) Rows.RemoveAt(0);
the smart approach:
Rows.Clear();
|
|
|
|
|
I am talking to a MS Access database using C++/CLI. All is well untill I try to retrieve Date data: When the day is single digit, it refuses to see it (but doesn't throw an error) . My query goes:
String^ query = "SELECT * FROM MyTable WHERE (aNumberField = " + aValue +
"AND aDateField = #" + aDate + "#) ORDER BY aNumberField";
'aDate' in the above is a string in the format dd/mm/yyyy
This format is also enforced in the Date field of the MS Access database.
I also physically add a zero at the start of any one digit day field, so the string looks like "05/12/2010" instead of "5/12/2010". But that doesn't help. Remember that the above works fine with 2-digit day fields, i.e. a date like "15/12/2010" works fine.
|
|
|
|
|
I would never do it that way. Unless you have set some CultureInfo stuff for the thread, it will use an implicit ToString() that applies the datetime formatting rules your user has set out through "Regional Settings". However user-defined settings should apply to the GUI only, not to formatting in files or databases.
You really should fix the datetime formatting by explicit code, so I recommend something along these lines:
String^ query = "... #" + aDate.ToString("dd/MM/yyyy") + "#...";
|
|
|
|
|
Thanks Luc. Yes, I tried many solutions along that line, such as:
System::DateTime^ tUpdated = DateTime::Parse(myDateString, System::Globalization::CultureInfo::CreateSpecificCulture("en-AU")->DateTimeFormat);
String^ thisString = String::Concat("#",tUpdated->ToShortDateString(),"#");
When debugging, the resulting string shows properly formatted. I'm starting to think maybe I need to rebuild the Access Database.
modified on Monday, August 23, 2010 10:34 PM
|
|
|
|
|
Dirkus Maximus wrote: tUpdated->ToShortDateString
That does not make any sense. ToLongDate() and ToShortDate() adhere to your user's preferences, hence are not the right tool for database operations.
I am not familiar with a "MS Access Short Date" type, I only know of "date/time" type, which matches perfectly with a DateTime in my experience. Here is a bit of C# code I have used a lot; one could do the same things in C++/CLI:
public static DateTime GetDateTime(DataRow row, string fieldName) {
object field=row[fieldName];
if (field is DBNull) return DateTime.MinValue;
return (DateTime)field;
}
|
|
|
|
|
Thanks again Luc, that is good information. But I understand that, in the end, you can only query a database using a text string. I can narrow my problem down to the following:
I do a query
"SELECT someDate FROM myTable WHERE someField = 34"
and I get a return from the DB
I confirm, using a GetType(), that it is of type DateTime
I do a 'ToString()' and that returns
06/07/2010 12:00:00 AM
Now I query the Database with
"SELECT * FROM MyTable WHERE someDate = #06/07/2010 12:00:00 AM#"
It doesn't return anything.
While if do another query with a 2-digit day field, such as #16/07/2010 12:00:00 AM#, it works.
*** Update ***
The following work-around worked:
"SELECT someDate FROM myTable WHERE (someDate >= #6/07/2010#) AND (someDate <= #7/07/2010#)"
Any suggestions why this works and the previous one didn't?
modified on Tuesday, August 24, 2010 3:56 AM
|
|
|
|
|
The proper way to handle dates and times would be to use SqlParameter, unfortunately that does not work for Access, so yes you need to convert DateTime values to string literals.
Dirkus Maximus wrote: I do a 'ToString()' and that returns 06/07/2010 12:00:00 AM
You seem to still not understand the concept of regional settings; ToString() shows the data formatted like the user (you) said he wanted it, see the Control Panel ("Regional Settings" or "Dates and Times"); it is unrelated to the format your database requires.
I found some more C# code that should be useful:
public static string Date(DateTime date) {
return date.ToString("#yyyy-MM-dd#");
}
Do you see how it enforces a format independent of the user's Control Panel settings? (and different from what you think it should be).
And I use it like this:
string query="... WHERE myDateField = "+Date(myDateTime)+"...";
|
|
|
|
|
Hi Luc
Luc Pattyn wrote: ToString() shows the data formatted like the user (you) said he wanted it, see the Control Panel ("Regional Settings" or "Dates and Times")
Now I got you (little did I know).
Turned out I forgot that MS Access uses the JET engine. That's what happens when you leave a gap between researching what database to use and the actual implementation. At http://technet.microsoft.com/en-us/library/cc966377.aspx, I found the following:
Note that this date literal must always be expressed in MM/DD/YY order. To avoid the ambiguity of the meaning of stored queries, Microsoft Jet doesn't follow the international date format settings specified in the user's Control Panel.
So, given my example given earlier, all I needed to do was:
"SELECT * FROM MyTable WHERE someDate = #7/6/10#"
As I understand now, it would be better to work with DateTime types in the implementation, and convert them to properly formatted Strings in queries. Anyway, many thanks for all your effort.
|
|
|
|
|
Dirkus Maximus wrote: Microsoft Jet doesn't follow the international date format settings specified in the user's Control Panel.
That is correct, it holds true for each and every database; databases don't care about human users and their formatting preferences. After all, their data needs to be portable across the world.
Dirkus Maximus wrote: Note that this date literal must always be expressed in MM/DD/YY order.
That is a surprise to me. I have always used yyyy-MM-dd and that has served me well, probably because it is unambiguous and easy to understand, so I suspect the MSDN statement is overly strict, in real life JET seems to accept more than one format.
What remains is your now puzzling statement a date like "15/12/2010" works fine at the end of your very first message in this thread. It clearly follows dd/MM/yyyy which is yet another format, and yet you said it worked well. I don't have an official reference, however some pages (such as this[^] one) claim JET is quite forgiving, but when in doubt looks for m/d/y.
|
|
|
|
|
Hi Dirkus,
I now have expanded a pre-existing article [^]of mine on DateTime, by adding the essentials of what we discussed today. Maybe it is of further interest to you.
|
|
|
|
|