|
because i need to distribution memory to write something,
if memory is not enough, tip to user
|
|
|
|
|
Try this[^]. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
im making a program that has a button on the dialog. When pressed, it pops up another dialog.It is a math calculator program. This specific button calculates square root. I need to have the thing go in a child window(modal dialog) because i have other formula buttons to add...
So i go in the class wizard, create a dialog of the CDIALOG BASE ....then i try to add a message handel.....
then on my main dialog, i add the code
CDialog aboutDlg(IDD_ABOUTBOX);
// Create and show the dialog box
INT_PTR nRet = -1;
nRet = aboutDlg.DoModal();
// Handle the return value from DoModal
switch ( nRet )
{
case -1:
AfxMessageBox("Dialog box could not be created!");
break;
case IDABORT:
// Do something
break;
case ID_SOMETHING:
MessageBox("hello", "bonjour(s)", MB_OK);
break;
case IDCANCEL:
// Do something
break;
default:
// Do something
break;
};
i know DOMODAL IS RESTRICTED in a few perimters but someone told me to create a class and make message handles...than override domodal with my code...nothing happens....message box does not appear
....i just lost though..nothing is working at all..please give me detials or a tutorial on how to create a class derived from CDIALOG than add message handles.
|
|
|
|
|
in that case can you give code of your DOMODAL function?
if you want a simple work around then you can store that square root value in some global or class variable and then use it in parent dialog. But if you want to go with domodal then share that code.
Thanks.
|
|
|
|
|
The code you've shown has little, if anything, to do with the question you've asked.
acce55 wrote: please give me detials or a tutorial on how to create a class derived from CDIALOG...
If you have already designed the dialog template, open ClassWizard (Ctrl+W). It should prompt you for creating a class or selecting an existing class. Selecting the former should bring up a New Class dialog with the Base class and Dialog ID already filled in.
The steps in VS200x are different. I do not have that version in front of me to provide details."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hello,
I have downloaded the last 0.2.8version of log4cpp from source forge, but I have to build the sources because they dont provide the binaries.
There's a MSVC6 folder in the distrib, but I only have visual studio .net 2003 (VC7).
I tried to build it anyway, but ran into build errors. I would appreciate if someone can help here..
This is what I did:
1. start msvs.net 2003.
2. File->Open project->...->log4cpp-0.2.8->msvc6->msv6.dsw
3. I got the following msg box:
"The project 'log4cpp.dsp' must be converted to the current Visual C++ project format. After it has been converted, you will not be able to edit this project in previous versions of Visual Studio."
4. I said "yes to All"
5. Build->build log4cpp
6. This is the o/p from log file:
log4cpp-0.2.8\src\PatternLayout.cpp(134): error C2593: 'operator <<' is ambiguous
log4cpp-0.2.8\src\OstringStream.cpp(78): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
7. line 134 of PatterLayout.cpp is: message << t;
8. Line 78 of Ostring.cpp is :
*this << vstrprintf(format, args);
Any help?
Thanks a lot.
-R
|
|
|
|
|
The C2679 error message makes it sound to me like you need to add in a #include of <string> - VC6 implicitly included that header when you included iostream, whereas VC2003 doesn't, IIRC. Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
CodeProject MVP for 2010 - who'd'a thunk it!
|
|
|
|
|
Well the reversed class looks something like it:
struct random_class {
char *something;
void __thiscall classfunction (void *this);
};
So i wanna hook it like this
void (__thiscall* classfunction)(void *this );
void __thiscall myclassfunction(void *this )
{
return classfunction(this->something);
}
But i get 8 errors it says syntax error : missing ';' before 'this' Did i use it correctly or wrongly i didnt find on google any function that uses param as void*this???
|
|
|
|
|
Try calling your parameter sonething other than "this". this has a special meaning (meaning: a pointer to this object) in C++.
|
|
|
|
|
hi
I don't understand Completely what you say,but the word "this" is the key word of C/C++. so it isn't declare as a variable. as follow,there is a example.I hope it is help for you.
#include "stdafx.h"
typedef void classfunction (void *w);
struct random_class {
char *something;
classfunction *myfunction;
};
classfunction * myclassfunction(void *w )
{
return ((struct random_class *)w)->myfunction;
}
void printfAint(void *w)
{
printf("%d\n",*(int*)w);
}
int main(int argc, char* argv[])
{
int i=10,j=20;
random_class r;
r.myfunction=printfAint;
r.myfunction(&i);
r.myfunction(&j);
return 0;
}
|
|
|
|
|
zhq00001 wrote: the word "this" is the key word of C/C++. so it isn't declare as a variable
In your first example it is, its declared as a parameter which is a variable:
void (__thiscall* classfunction)(void *this );
void __thiscall myclassfunction(void *this )
{
return classfunction(this->something);
}
I'm saying try changing it to:
void (__thiscall* classfunction)(void *pParam );
void __thiscall myclassfunction(void *pParam )
{
return classfunction(pParam->something);
}
|
|
|
|
|
The calling convention __thiscall[^] is for member functions. You can't apply it to regular global functions as you're attempting. Also, for member functions __thiscall is assumed and in general including it adds little but clutter.Steve
|
|
|
|
|
Im trying to return the char using the thispointer.
|
|
|
|
|
I created a dialog-based MFC application in VS6, and added a simple ATL object to it using the ATL Object Wizard (this creates several .c and .h files, and adds a lot of code to the app class). In the .h file that it created, I added public IWMPEvents to the class declaration. I also added COM_INTERFACE_ENTRY(IWMPEvents) to the BEGIN_COM_MAP macro. I then implemented the 45 or so methods of IWMPEvents . At this point the compiler and linker are happy. Now for the problem...
In the code where I actually want to use this new ATL object, I have:
CMyEventHandler *pEventListener = NULL;
CMyEventHandler::CreateInstance(&pEventListener); <<--- error
CComPtr<IWMPEvents> spEventListener = pEventListener;
connectionPoint->Advise(spEventListener, &dwAdviseCookie); The error is:
atlcom.h(3173) : error C2787: 'CMyEventHandler' : no GUID has been associated with this object
I've tried all I can think of but nothing is working. I've successfully compiled the wmphost project that comes with the Windows Media SDK, but cannot find any meaningful differences other than it does not use MFC.
What am I overlooking?
- DC"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
It's been ages since I played with this, but do you need to add an entry into the project .idl file defining a GUID for coclass or interface there?
Is there even an idl file for this project type?L u n a t i c F r i n g e
|
|
|
|
|
Yes a .idl file was created and it has a GUID in it for the IMyEventHandler interface."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: a .idl file was created and it has a GUID in it for the IMyEventHandler interface.
David, I don't get exactly what you're trying to do.
It seems like you're trying to create COM server and register something else that you have developed (CMyEventHandler ?) for receiving COM events. Right?
What I'm trying to figure out is why you're trying to create an instance of your CMyEventhandler ...
Is it really a COM server? If so, from where is it created and does the header files created have a CLSID for it?
Usually you would create a COM server with e.g. ::CoCreateInstance() , or one of its equivalents. You provide the CLSID for the server, the IID for the desired interface and a pointer to store the interface pointer in if the call was successful.
If the server produces COM events that the client is interested in, the client uses a mechanism in the server to register itself as an event listener (Advise() ?).
From your explanation I don't see the above happening, a part from calling CreateInstance but for what looks to me as the "wrong" object.
Can you elaborate on this a bit further David?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: David, I don't get exactly what you're trying to do.
It seems like you're trying to create COM server and register something else that you have developed (CMyEventHandler?) for receiving COM events. Right?
My overall intent is to open a .mp3 file using the Windows Media Player COM object, and then read some information from one of the headers. I can't get this information until the player has loaded the .mp3 file. A side effect of loading the .mp3 file is that it will start playing it. To get around this, I need to respond to the 'play' event and stop it. That's what got me to looking at the IWMPEvents interface.
Roger Stoltz wrote: What I'm trying to figure out is why you're trying to create an instance of your CMyEventhandler...
Is it really a COM server? If so, from where is it created and does the header files created have a CLSID for it?
Usually you would create a COM server with e.g. ::CoCreateInstance(), or one of its equivalents. You provide the CLSID for the server, the IID for the desired interface and a pointer to store the interface pointer in if the call was successful.
If the server produces COM events that the client is interested in, the client uses a mechanism in the server to register itself as an event listener (Advise()?).
From your explanation I don't see the above happening, a part from calling CreateInstance but for what looks to me as the "wrong" object.
Can you elaborate on this a bit further David?
Good questions. As I've done very little with COM, some of the terms and procedures are still a mystery. Other pieces of my code look like:
CComPtr<IWMPPlayer4> player;
HRESULT hr = player.CoCreateInstance(__uuidof(WindowsMediaPlayer), 0, CLSCTX_INPROC_SERVER);
CComPtr<IConnectionPoint> connectionPoint;
CComPtr<IConnectionPointContainer> connectionContainer;
player->QueryInterface(&connectionContainer);
connectionContainer->FindConnectionPoint(__uuidof(IWMPEvents), &connectionPoint); "One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: My overall intent is to open a .mp3 file using the Windows Media Player COM object, and then read some information from one of the headers.
Perhaps this is not what you'd like to hear/read, but wouldn't it suffice to read the mp3 file from your application if you're only interested in the header?
I guess you've thought about this alternative already and discarded it.
If not, you may find this[^] or this[^] useful.
I don't know what header information you're looking for.
More about the Media Player solution...
Have you had a look at this article[^] about handling Media Player events in C++?
Provided that you successfully can create the Media Player server, you should be able to find something in the article above that you can use.
You should also have a look at the ATL sample that demonstrates connection points: ATLDuck.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: Have you had a look at this article[^] about handling Media Player events in C++?
Yes, several times.
Roger Stoltz wrote: Provided that you successfully can create the Media Player server, you should be able to find something in the article above that you can use.
I can play the .mp3 file just fine. I can also change other settings (e.g., auto start). It's just getting past the "no GUID specified" compiler error that's troubling me."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: It's just getting notified of events that's troubling me.
Okay...
Basically this is what you have to do:
- Implement a class that derives from the event interface you're interested in and put the interface in the COM_MAP. As I understand it you've already done this part.
- When you've successfully created the Media Player server and got an interface pointer (
IWMPPlayer ), you create an instance of the class mentioned above; not by using CreateInstance() , use new or similar (you know what I mean). - Ask
IWMPPlayer for the IConnectionPointContainer interface as described in the article. - Find the connection point you want,
IWMPEvents , by calling IConnectionPointContainer::FindConnectionPoint() and you should get an IConnectionPoint interface in return as described in the article. - Register your class as an event listener by calling
IConnectionPoint::Advise() and provide a pointer to your instance of your CMyEventHandler . Store the cookie and the IConnectionPoint interface pointer as you'll need it when you unregister from the server. - You should be all set to catch events from Media Player!
- Remember to call
IConnectionPoint::Unadvise() when you're done.
The ATLDuck sample[^] explains how to set up connection point further. It gives you a complete working example and not just some code snippets.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
It appears that I have steps 1-5 in place. Do you agree?
Does the duck sample talk about how to avoid the GUID error that I'm battling?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: It appears that I have steps 1-5 in place. Do you agree?
Nope, I don't agree.
Not unless you've altered the code you presented earlier where you tried to create an instance of CMyEventHandler by calling CreateInstance() into what I suggested, e.g. using new .
DavidCrow wrote: Does the duck sample talk about how to avoid the GUID error that I'm battling?
Nope.
The question is irrelevant as a CLSID for CMyEventHandler won't be needed when you create a CMyEventHandler on the heap or the stack.
Note that what the compiler complains about is a missing "Class ID", CLSID, since it refers to the 'object' CMyEventHandler . The CLSID is the identity of the server one is trying to create with a call to CreateInstance() . This is not the same as the identity of the interface you're trying to use called "Interface ID" or IID, which also has a Globally Unique IDentifier assigned to it.
Your CMyEventHandler declaration should look something like this:
class ATL_NO_VTABLE CMyEventHandler :
public CComObjectRootEx<CComSingleThreadModel>,
public IWMPEvents
{
public:
BEGIN_COM_MAP( CMyEventHandler )
COM_INTERFACE_ENTRY(IWMPEvents)
END_COM_MAP()
public:
};
The code where you create the Media Player server should look something like this, as partially described in the article:
CComPtr<IWMPPlayer> spWMPPlayer;
CComPtr<IConnectionPoint> spConnectionPoint;
DWORD dwAdviseCookie;
HRESULT hr;
CMyEventHandler* pMyEventHandler = new CComObject<CMyEventHandler>;
CComQIPtr<IConnectionPointContainer, &__uuidof(IConnectionPointContainer)> spConnectionContainer( spWMPPlayer );
if( spConnectionContainer )
{
hr = spConnectionContainer->FindConnectionPoint( __uuidof(IWMPEvents), &spConnectionPoint )
if( pMyEventHandler && SUCCEEDED( hr ) )
{
hr = spConnectionPoint->Advise( (IUnknown*)pMyEventHandler, &dwAdviseCookie );
}
}
Finally, a little tip...
You could declare CMyEventHandler as a nested class inside the class from which you're creating the Media Player server. That would make it easier to call functions in the outer class from the event handlers. You could provide the 'this '-pointer to the constructor of the CMyEventHandler class and store it internally. Creation of the CMyEventHandler would of course look like this:
CMyEventHandler* pMyEventHandler = new CComObject<CMyEventHandler>( this );
I suppose you have to declare the nested CMyEventHandler class as a friend to the outer class if you don't feel like exposing the callbacks publicly.
From a design point of view I like this way of writing a COM event sink.
I hope you'll find the above helpful.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Roger Stoltz wrote: I hope you'll find the above helpful.
Yes, the compiler is happy now. It's still a tad confusing, however, since the two examples I was using as a reference were calling CreateInstance() .
Upon running the code, Advise() is returning 0x80040202 (CONNECT_E_CANNOTCONNECT ). MSDN article Q183216 talks about my sink object (CMyEventHandler ) may be missing something that QueryInterface() is looking for. As far as I can tell, my sink object has implemented all of the IWMPEvents methods."One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
DavidCrow wrote: MSDN article Q183216 talks about my sink object (CMyEventHandler) may be missing something that QueryInterface() is looking for. As far as I can tell, my sink object has implemented all of the IWMPEvents methods.
The article Q183216 is talking about when the server is querying for the source interface, IWMPEvents in your case, and the client who is supposed to implement the interface responds with an error that says the interface is not supported/implemented. The error returned to the server is most likely E_NOINTERFACE .
For this to be applicable in your situation you must have forgotten to put the entry in the COM_MAP , but as I understand from your previous posts you've already got that in place.
This made me wonder if the server might be requesting another interface such as IDispatch , e.g. if the IWMPEvents inherits from IDispatch , but as far as I can tell with the OLEView tool this is not the case.
Can you successfully "find" the connection point with IConnectionPointContainer::FindConnectionPoint() ?
Are you possibly making the call from a worker thread? If you are, does it work if you try to do this from your main thread?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|