|
Rolf Kristensen wrote: I guess it will require even more code on the generic user-control to wrap around the custom WinForm so it reacts properly to its events.
It will require a fair bit of work, but once you do it, then your end clients won't have to repeat all that extra work each time they write a plugin/add-on. Since I've never had to do that I can't think of any immediate ideas off the top of my head. If I do get some time, I may try and work on a simple prototype (at least that way I can establish if it's practically doable or not). Alternatively, if you start on something and hit a hurdle, it'd be great if you can continue discussing it here.
|
|
|
|
|
Attempting to dig into C++/CLI by wrapping VLC with it. You'd know the very fist thing I run across is conversions between arrays in C++/CLI and C++.
Are there any 'conversion' libraries/utilities out there??
Thanks,
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Ed K wrote: Conversion between array<String^>^ and const char *const* and back
You don't need any library functions to do this. It's simple enough to write.
Converting String^ to char*
String^ str = "Hello world!";
IntPtr p = Marshal::StringToHGlobalAnsi(str);
char *nativeString = static_cast<char*>(p.ToPointer());
Marshal::FreeHGlobal(p);
Converting char* to String^
const char* native = "hello world";
String^ managed = gcnew String(f); Now you know the basic conversions and it will be easy to create const char *const* from a managed string array.
Best wishes,
Navaneeth
|
|
|
|
|
If you are using .Net 3.5 or newer, you can use the marshalling library:
http://msdn.microsoft.com/en-us/library/bb384865.aspx[^]
For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally. You will still need to loop over the array elements though.
|
|
|
|
|
ian__lindsay wrote: For your example, the marshal_context methods are probably most appropriate, then you can leave RAII to clear up the HGlobal stuff internally.
Correct. Beauty of stack semantics!
Best wishes,
Navaneeth
|
|
|
|
|
N a v a n e e t h wrote: It's simple enough to write.
Really? why does C++ need another type of string for each new string? after all, a string is a string.
|
|
|
|
|
Luc Pattyn wrote: why does C++ need another type of string for each new string? after all, a string is a string.
Not sure I got you
Best wishes,
Navaneeth
|
|
|
|
|
It seems C++ offers more string types than I have strings in a typical app. Just wondering why that is.
|
|
|
|
|
Luc Pattyn wrote: It seems C++ offers more string types than I have strings in a typical app. Just wondering why that is.
Ok. I guess you are talking about the various string types shown in the marshal_context MSDN page. std::string is the only string type that C++ standard provides. Rest everything is non-standard. When it comes to C++/CLI, System::String^ is the standard string type. CString is Microsoft's implementation for MFC.
Best wishes,
Navaneeth
|
|
|
|
|
#include "apue.h"
Did you have the head file?
Or Did you have the book source code?
It is The 2nd Edition better , but the 1st edition maybe suitably.
Thx.
|
|
|
|
|
Try a Google search, as far as I recall there is a website for the book's source code. Although it is some years since I last looked.
It's time for a new signature.
|
|
|
|
|
Thinks your good answer very much.
|
|
|
|
|
Hi everyone,
Ho do I exchange info between two forms. I have done in C# but do not know how to do it C++/CLI
I have a click even where I want to populate another form for user input then close it but use those info
that was provided by the user.
thanks
|
|
|
|
|
jashimu wrote: I have done in C# but do not know how to do it C++/CLI
What you did in C#, you can do in C++/CLI too. They both offer the same object-orientation and the same set of Framework classes.
|
|
|
|
|
Hi Luc Pattyn, This is simple in C# but I don't see anything like this.
private void button1_Click(object sender, EventArgs e)
{
Form2 form2 = new Form2();
form2.Show();
}
thanks for your reply.
|
|
|
|
|
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?
|
|
|
|