|
Hi !
I have to create a small prototype for a future application that my company wish to develop. A couple of years ago i've learn C++ but for the last 5 years or so i've been programming only in .net (VB, C#) and Java so my knowledge of C++ seems a bit far away So this is why i need your help.
Right now one of the function of our prototype is to "create" a bridge between c++, .net and Java application. One of our supplier send us a Com Dll (C# code) which allow us to interact with their software. Using their myClass.tlb file i've imported the file in the C++ code. This file contain some class.
In one of their class (clCommunication) there is a method call "Get_Message()" and also an Event call "NewMessage". When the Get_Message method is called it trigger the NewMessage Event.
So what i what to know is how to handle the NewMessage event in the c++ code. When the NewMessage will be triggered i want to call a c++ function. I've already done this in .net and in Java but i cannot find the solution in C++.In VB i've done something like:
Function myFunction() Handle aCom.NewMessage. ( When NewMessage will be invoke myFunction will be called)
In C# i have done the same thing using the += operator but in C++ i cannot find out how do to it.
I don't know if this could help but i've noticed that when i create an instance of the class clcommunication there is 3 properties available "add_NewMessage","remove_NewMessage","raw_NewMessage". I guess that i should use them to make what i need but i have no idea where to start.
So let's says that i have a function called "Dothis()" in my c++ code. What did i need to do to automatically triggered this function when a instance of clCommunication will triggered "NewMessage".
Thanks !!!
|
|
|
|
|
I'm using Visual C++ 2008 Professional with a CLR project of Windows Form Application. This program is a stopwatch and I'd like to be able to set a global mouse hook so that when the user clicks anywhere on the screen after pressing a specific button, it will start the timer. How is this possible? I'm not sure what code would be needed to help me, but I will post anything that is needed.
Thanks for your time,
Jordan
|
|
|
|
|
I am just curious as to the best practice for suspending a thread. We have a thread that every once in awhile is required to do something. I am currently using SuspendThread on the CWinThread object. When the thread needs to do work, I Resume the thread. That seems to work well and does not eat up any CPU. But I am just wondering if a better way is to WaitForSingleObject and use an Event to resume the thread.
Using SuspendThread works and is certainly easy to implement, but am just curious which way may provide a better design.
Thanks for the insight.
Note: We were originally ending the thread when it was done with its job, but ran into some other problems. This thread calls into something else which uses OpenMP for multi-threading. When our C++ client thread ended, the OMP threads did not seem to get removed so we kept accumulating OMP threads until we eventually get an error saying too many OMP threads.
|
|
|
|
|
StevenS_Dev wrote: But I am just wondering if a better way is to WaitForSingleObject and use an Event to resume the thread.
Yes, that's probably a much better approach because you are in full control about what is happening. When you call SuspendThread, you have absolutely no idea where the thread will be stopped. Perhaps right in the middle of something important. With the other approach, you fully complete the task, then swith in a 'wait state' (waiting for the event to be signaled).
|
|
|
|
|
|
Thanks for the answers. That is what I figured, but wanted real data to support it.
|
|
|
|
|
Don't use SuspendThread[^]. You're been lucky so far but I wouldn't count on that continuing. See this article on why you should never suspend a thread[^]. The documentation for SuspendThread[^] also points out the dangers of using it as you are:
This function is primarily designed for use by debuggers. It is not intended to be used for thread synchronization. Calling SuspendThread on a thread that owns a synchronization object, such as a mutex or critical section, can lead to a deadlock if the calling thread tries to obtain a synchronization object owned by a suspended thread. To avoid this situation, a thread within an application that is not a debugger should signal the other thread to suspend itself. The target thread must be designed to watch for this signal and respond appropriately.
|
|
|
|
|
Hi,
I am working on a desktop search engine.
As a part of this project i need to create catalog in indexing service. To cteate this i need to have the Indexing Service Administration API.
Where can i get them. Should i need to buy them?
or I can get them for free? if so where can i get them?
I had the dll "ciodm.dll" on my machine but with out the .tld i can't use it in my project.
Some one, please help me in finding out what i can do/ where i can get the API's so that i can complete my project.
Thanks
krish99
|
|
|
|
|
We have an application written in VC 6, that works well on Windows 2000, but when running on XP the modeless status diaglog that displays the progrees of the operation doesn't seem to refresh or return to top after the operator returns from a screen saver.
The status bars continue to updte as far as we can tell, but the application appears to lose focus of the modeless dialog until the operation is complete. When the operation finishes, THEN the status screen displays with all status bars compete at 100%, and a the Afxmessege Box appears.
How can I get the application to return focus to the status screen when returning from the screen saver?
Anyone have any suggestions?
Snaggles
|
|
|
|
|
|
Try to set the modeless as top window with SetForegroundWindow()
you can also WM_NEXTDLGCTL message it is sent to a dialog box procedure to set the keyboard focus to a different control in the dialog box.
Vikas Amin
My First Article on CP" Virtual Serial Port "[^]
modified on Thursday, July 24, 2008 5:33 PM
|
|
|
|
|
Hi,
I have an application(MFC), it needs to send some data (XML 20/25kb) to some online entity(some online script or service) and that online entity will parse the XML query some Database and return results to the MFC application.
i just need to know what is the idea scenario under these circumstances should i use some script or service or query the database directly
please suggest
Thanks
C++ where friends have access to your private members !
|
|
|
|
|
|
Hello there, some one help me ?
How can i configure my Visual Studio 8 to solve the problem indicated by the above message ?
C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\atlbase.h(4575) : error C3861: '_beginthreadex': identifier not found
tanks for help ...
Ps: Sorry by my english, i´m Brasilian
|
|
|
|
|
You don't need to configure anything, just include the appropriate header file: procces.h (as described in the documentation[^] ).
|
|
|
|
|
See here. You are not including the process.h file.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
|
I am using a thread for which I am sending the below mentioned structure as parameter. pls advice
error C2440: '=' : cannot convert from 'const class abcDomain::Scope *const ' to 'class abcDomain::Scope *'
.h
declaration
virtual bool searchABCByAttributes()const;
typedef struct THREADSTRUCT_SCOPE
{
Scope *_this;
}THREADSTRUCT_SCOPE;
.CPP
bool Scope::searchABCByAttributes()
{
THREADSTRUCT_SCOPE *_param= new THREADSTRUCT_SCOPE;
_param->_this = this;
....
|
|
|
|
|
Your function is declared as constant, so it means that the this pointer is const too. And you are trying to assign it to a non-const variable, which is illegal. So, remove the constness of the function and it should be fine.
|
|
|
|
|
Missed a const in the definition of Scope::searchABCByAttributes() ?
.h
declaration
virtual bool searchABCByAttributes()const;
.CPP
bool Scope::searchABCByAttributes()
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Sorry it is my mistake, pls find below the correct one. I want keep the const, is there any work around...
.hdeclaration
virtual bool searchABCByAttributes()const;
.CPP
bool Scope::searchABCByAttributes()const
|
|
|
|
|
There's a solution but it is really ugly: you can remove the constness of the this pointer by using a const_cast. But it doesn't make any sense because you declared your function as const. Why would you do that if you remove the constness inside it ?
Another point: why are you putting the this pointer inside a structure if you only pass that pointer ? Why don't you pass it directly to your thread function ?
|
|
|
|
|
I am putting it inside sturct, Becase I want to pass it as parameter to Thread along with other attributes
|
|
|
|
|
The basic problem is you are assigning a const pointer to a non-const pointer . Well, if you want to keep the consts in the function signature, then possible get arounds are
1) Make the Scope *_this; as const. The only problem is since its a const member, you've to initialize it by constructor. So your code snippet will change like this -
typedef struct THREADSTRUCT_SCOPE
{
THREADSTRUCT_SCOPE( const Scope* ptr )
: _this( ptr )
{}
const Scope *_this;
}THREADSTRUCT_SCOPE;
And allocate it like this,
bool Scope::searchABCByAttributes()
{
THREADSTRUCT_SCOPE *_param= new THREADSTRUCT_SCOPE( this );
...
}
1) You can also use cstyle casting or const_cast to remove the constness. But its not recommended. It can be done as follows. Just FYI.
_param->_this = (Scope*)this;
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
but now I had #error WINDOWS.H already included. MFC apps must not #include <windows.h>
|
|
|
|