|
It’s amazing how many so called developers either don’t or can’t read documentation. I mean the state of documentation today compared to when I started out is incredible. I have a UDP thread in the C# forum where the OP was describing odd behavior and posted the sending code. I looked at it and said I had no experience with UDP but his code didn’t use SendTo and I would have expected it to just based on what I have read down through the years. So he replies with you can use Connect and Send with UDP and the thread goes back and forth a couple times until I have had enough.
So I go and build two apps, Sender/Client and code them the way I interpret the documentation and of course they just work, shocking, no really it is. Once I decided to do it the whole thing took like 20 minutes including getting snacks and drinks and chatting with folks. Meanwhile the C# thread spans 10s of hours. So I finally just reply with, I said a have had no experience so I just did it and it behaves as expected, here’s the code.
led mike
|
|
|
|
|
Hello
how to Convert Message% From Manage C++ To MSG *
i want to get message in manage C++ but with MSG don't with Message
[SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)]
virtual void WndProc(Message% m ) override
{
////////////////////// I want To Send MSG * to Proc No Message%
Form::WndProc((Message%)m);
} //this is work but dont MSG *
|
|
|
|
|
I was trying to link external library with my existing project. I got some error, where some of them are redefination and some of then are ambiguous symbol
error C2371: 'IDataObject' : redefinition; different basic type
The above error says, 'IDataObject' defines in more than one places. It might be true.
When I search MSDN I found IDataObject is declared in objidl.h and at the same time it is defined in System::Windows::Forms namespace.
I am using the VC++/ CLR project and I have windows form in my project.
The external library might be refering IDataObject from objidl.h. So compiler might find IDataObject in objidl.h and in System::Windows:Forms.
So, how I can avoid this definition problem.
Any idea, suggession or link will be helpful and appreciated.
Thank you.
|
|
|
|
|
Hi friends,
Is there any function available in c++/VC++ to convert an hex value to int? let me know if yes.
Regards,
lgatcodeproject
|
|
|
|
|
lgatcodeproject wrote: Is there any function available in c++/VC++ to convert an hex value to int? let me know if yes.
Perhaps you are looking for the C Runtime Library strtol(...) function. If you are this is the wrong forum as this forum is for C++ development using the .NET platform. For future C/C++ questions use the Visual C++ / MFC forum
led mike
|
|
|
|
|
okay!
lgatcodeproject
|
|
|
|
|
I'm using System.Net.NetworkInformation.NetworkInterface to get the information about network connections to my PC. But this class seems to be 'Read only', i.e., I can view the information about network connection. For example System.Net.NetworkInformation.NetworkInterface.OperationalStatus tells us whether network connection is Up or Down. Is there any away that I can change that status programatically? i.e, can we enable/disable the network connection programatically?
Thanks
Ram
|
|
|
|
|
Hi,
I've the following code that runs in a timer function every second. OnTimedEvent() is a timer delegate that is invoked by Windows timer every second. It uses MFC/Windows SDK. It sets the processor priority for the thread that is running this code.
void CPci1553::OnTimedEvent( Object^ source, ElapsedEventArgs^ e )
{
//set the timer thread affinity to second process and set it to higher priority
SYSTEM_INFO info;
//get the configuration information of computer
GetSystemInfo(&info);
//if the system has more than one processor, use the last processor for TOD thread
//set the thread affinity to second processor
if(info.dwNumberOfProcessors > 1)
SetThreadIdealProcessor(GetCurrentThread(),info.dwNumberOfProcessors-1);
}
I need to upgrage this code for .NET using C++/CLI. I tried to use .NET functions like "System::Environment::ProcessorCount" to processor count in on the system, "System.Diagnostics.ProcessThread.IdealProcessor" to set the processory priority for the thread, "System.Threading.Thread.CurrentThread" to get the current running thread for this code. But the problem is "System.Diagnostics.ProcessThread" is unmanaged thread and "System.Threading.Thread" is managed thread. I don't know how to mix these two. Pls. help me with this code.
Thanks
Ram
|
|
|
|
|
There isn't a one-to-one relationship between System.Threading.Threads
and System.Diagnostics.ProcessThreads.
A System.Diagnostics.ProcessThread is an actual OS thread.
A System.Threading.Thread is a logical thread. It's possible for many
System.Threading.Threads to be using the same OS thread.
You can manage affinity at either level, but doing it at the
System.Threading.Thread level doesn't mean it will have any effect whatsoever
on an OS thread, like your Win32 API code does.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
OK. If I want to go with OS thread using System.Diagnostics.ProcessThread class, I can use System::Diagnostics::ProcessThread::IdealProcessor to set the processory affinity. But, how do I access the current running thread like we get with GetCurrentThread()in WIN32?
|
|
|
|
|
Hi I'm creating an application in Windows forms. I wondering if any knows how a System::Diagnostics::Process::Start("C:\\path\\my.exe"); which opens an application in a window to place that window in my form?
|
|
|
|
|
This[^] is in C#, but it should help.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi, this is probably an absurd question, but I'm really new to working in C++/CLI, so please bare with me. I have a solution that compiles into an application (.exe). I was wondering if it was at all possible to convert the project into Custom Windows Form control, so that I can place it in a Wondows form. The application is Scite, btw. Or if anyone knows how to get a Scintilla based text editor to be a Forms Control, that would also help.
Thank you!
|
|
|
|
|
Check this[^] out.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi, i'm using windows forms and I was wondering how to add to a listBox from a comboBox. Also how to remove an item from the listBox.
<br />
private: System::Void btnConfirmCommand_Click(System::Object^ sender, System::EventArgs^ e) {<br />
<br />
this->cmbCommands->Select();<br />
this->lstCommands->Items->Add(cmbCommands);<br />
<br />
}<br />
<br />
<br />
private: System::Void btnRemoveCommand_Click(System::Object^ sender, System::EventArgs^ e) {<br />
<br />
this->lstCommands->Select();<br />
this->lstCommands->Items->Remove(lstCommands);<br />
<br />
}<br />
modified on Thursday, January 31, 2008 10:27:48 AM
|
|
|
|
|
newkid wrote: this->lstCommands->Items->Add(cmbCommands);
You need to pass in the actual string you want to add not the ComboBox control.
led mike
|
|
|
|
|
so i create a string say x, how do you set an item in the comboBox to x?
<br />
string x;<br />
<br />
this->cmbCommands->Select();<br />
cmbCommands->SelectedItem;<br />
<br />
this->lstCommands->Items->Add("x");<br />
<br />
|
|
|
|
|
Are you in school or leaning by working from a book or what? If you are using a book to start out I think you might need a different book, or you may have skipped some stuff or something. This is very very beginner level stuff and you are already on to list boxes and combo boxes without knowing it. That's probably not a good idea.
led mike
|
|
|
|
|
This should solve your problem.
<br />
<br />
if(cmbCommands->Text->Length > 0)<br />
{<br />
lstCommands->Items->Add(cmbCommands->Text);<br />
<br />
}<br />
<br />
if(lstCommands->SelectedIndex !=-1)<br />
{<br />
lstCommands->Items->RemoveAt(lstCommands->SelectedIndex);<br />
}<br />
|
|
|
|
|
rover_boy wrote: This should solve your problem.
Really? It will solve this?
newkid wrote: so i create a string say x, how do you set an item in the comboBox to x?
string x;
this->lstCommands->Items->Add("x");
I think not.
led mike
|
|
|
|
|
Thanks thats sovled the problem
|
|
|
|
|
Hello everyone,
I have a lot of MFC control classes in C++,and I want to wrap them with C++/CLI and resue them in C# Application. but I do not know how to wrap them.
Can anyone give an hand? Thanks a lot.
|
|
|
|
|
Birch Howe wrote: Can anyone give an hand?
Look at the Articles here on CodeProject on the subject C++/CLI (look in the menu bar on the side of the page under "Chapters"). There is nothing specific about wrapping MFC other than any compiler/linker settings one might need and of course the dependency issues on deployment. Otherwise you are just wrapping a Native C++ class in a managed C++/CLI class.
led mike
|
|
|
|
|
Hello,
I think Nishant Sivakumar's book "C++\CLI in action" talks about this specific topic in "6.6 Using an MFC control in a Windows Forms form" titled chapter.
I've not tried yet... but i hope this helps.
|
|
|
|
|
I have callback[delegate] in managed code being called by native code. It works fine the first time but on the next call the native code blows up. Bear with me the structure is a little twisted, but I'll try my best to explain.
Here's the general structure:
Client
|
--->ServiceInterface
|
--->NativeService
The main question is how should I be passing the callback to the native code from the ServiceInterface initialization?.
Should the delegate be pinned before passing it to the native code?
The following is not exact code but a snapshot of how the code is interacting.
// Managed code
#include "ServiceInterface.h"
ref class Client
{
public:
ServiceInterface ^mngService;
Client()
{
mngService = gcnew ServiceInterface(this);
}
void initialize()
{...}
void Task1()
{
mngService->registerCallback(Task1_Callback);
}
void Task2()
{
mngService->registerCallback(Task2_Callback);
}
static int Task1_Callback(void *pdata, MessageType event)
{
Console::WriteLine(L"Task 1 completed...");
// cast and remove listener for task 1
return 1;
}
static int Task2_Callback(void *pdata, MessageType event)
{
Console::WriteLine(L"Task 2 completed...");
// cast and remove listener for task 2
return 2;
}
};
// ServiceInterface.h
#include <nativecode.h>
public delegate int Callbackfunction(void *pdata, MessageType event);
ref class ServiceInterface
{
private:
static list<Callbackfunction> callbacklist;
NativeService *service;
static Callbackfunction ^MessageProcessor;
static GCHandle ghMasterCallback;
static IntPtr ipMasterCallback;
ServiceInterface(Object ^client)
{
service = new NativeService();
//// Thought this was the way to pass function pointer to native code,
//// but crashed on the first callback.
//MessageProcessor= gcnew Callbackfunction(&Service::MessageEngine);
//ghMasterCallback = GCHandle::Alloc(MessageProcessor);
//ipMasterCallback = Marshal::GetFunctionPointerForDelegate(MessageProcessor);
//service->RegisterEventProcessor((Callbackfunction)ipMasterCallback.ToPointer(), client(Void * Value));
// Instead this method seem to work, at least for the first callback but dies on the second callback[Task 2]
service->RegisterEventProcessor((Callbackfunction)&MessageEngine, client(Void * Value));
callbacklist = new list<Callbackfunction>;
}
void registerCallback(Callbackfunction ^callback)
{
callbacklist->push_back(callback);
}
void removeCallback(Callbackfunction ^callback)
{ // removes the given callback function}
// Registered as EventProcessor with NativeCode
// Calls delegates in managed code
int MessageEngine(void *pdata, MessageType event)
{
list <Callbackfunction>::iterator Iter;
for ( Iter = callbacklist.begin( ); Iter != callbacklist.end( ); Iter++ )
static_cast<Callbackfunction>(*Iter)(pdata,event);
}
};
// UNManaged code
// nativecode.h
enum MessageType
{
EVENT_START,...
};
typedef int (* Callbackfunction)(void *pdata, MessageType event);
class NativeService
{
private:
void *clientContext;
public:
NativeService(){...}
Initialize(){...}
// Callback function to be defined in managed interface
Callbackfunction EventProcessor;
DoWorkFunction
{
:
:
// Message generated from service
MessageType newMessage;
DispatchCallback(EventProcessor(clientContext, newMessage));
}
RegisterEventProcessor(Callbackfunction processor, void * client)
{
EventProcessor = processor;
clientContext = client;
}
};
|
|
|
|