|
In your FormatMessage call
balakrishnan vinchu wrote: retval = FormatMessage(
messageflags,
OLE2T(formatstring),
NULL,
LANG_SYSTEM_DEFAULT,
(LPTSTR) &lpMsgBuf,
0,
(va_list*)&argsarray[0]
);
The line
(LPTSTR) &lpMsgBuf,
is wrong. It should be simply
lpMsgBuf,
Forget it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
modified on Wednesday, May 7, 2008 5:40 AM
|
|
|
|
|
I changed my code as you explained in previous mail.
LPTSTR lpMsgBuf = NULL;
DWORD messageflags = FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY ;
DWORD retval;
//Format the message from the format string.
retval = FormatMessage(
messageflags,
OLE2T(formatstring),
NULL,
LANG_SYSTEM_DEFAULT,
lpMsgBuf, // Suggested to pass simply lpMsgBug
0,
(va_list*)&argsarray[0]
);
if (!retval)
return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, GetLastError());
CComBSTR message(lpMsgBuf);
*outputstring = message.Detach();
LocalFree(lpMsgBuf);
Now i am not getting the Formatted message, since retval returned from FormatMessgae API is zero (i.e 0), Because of this CComBSTR message didn't created. Also if i wont initialize lpMsgBuf = NULL, then functions just gives exception.
Give me some suggestion.
Thanks
Regards,
Bala
|
|
|
|
|
Once try this
initialize lpMsgBuf as:
LPVOID lpMsgBuf;
and inside FormatMessage write lpMsgBuf as:
(LPTSTR) &lpMsgBuf,<br />
Mukesh Kumar
Software Engineer
|
|
|
|
|
Is this the right way?
LPVOID lpMsgBuf;
DWORD messageflags = FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY ;
DWORD retval;
//Format the message from the format string.
retval = FormatMessage(
messageflags,
OLE2T(formatstring),
NULL,
LANG_SYSTEM_DEFAULT,
(LPTSTR) &lpMsgBuf,
0,
(va_list*)&argsarray[0]
);
if (!retval)
return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, GetLastError());
CComBSTR message;
message = T2OLE(LPTSTR(lpMsgBuf));
message.CopyTo(outputstring);
I modified LPTSTR lpMsgBuf; to LPVOID lpMsgBuf;
And converted LPTSTR to LPOLESTR.
Am i doing correct here?
Regards,
Bala
|
|
|
|
|
Is this working correctly now?
Mukesh Kumar
Software Engineer
|
|
|
|
|
You're right (and I was wrong...). Whenever you use FORMAT_MESSAGE_ALLOCATE_BUFFER you have to pass the address of the variable, hence your code was correct.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
balakrishnan vinchu wrote: *outputstring = message.Detach();
you already taken the ownership of the BSTR, created and associated with the CComBSTR, by Detach method; hence CComBSTR is not expected to release the BSTR. If you are expecting so then you are not supposed to return that buffer as out parameter (outputstring). this outputstring is not released and i think, so the tool you used to detect memory leak points to the creator of it, CComBSTR message(lpMsgBuf);.
|
|
|
|
|
Is this the right way?
LPVOID lpMsgBuf;
DWORD messageflags = FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ARGUMENT_ARRAY ;
DWORD retval;
//Format the message from the format string.
retval = FormatMessage(
messageflags,
OLE2T(formatstring),
NULL,
LANG_SYSTEM_DEFAULT,
(LPTSTR) &lpMsgBuf,
0,
(va_list*)&argsarray[0]
);
if (!retval)
return MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, GetLastError());
CComBSTR message;
message = T2OLE(LPTSTR(lpMsgBuf));
message.CopyTo(outputstring);
I modified LPTSTR lpMsgBuf; to LPVOID lpMsgBuf;
And converted LPTSTR to LPOLESTR.
Am i doing correct here? [Smile]
Regards,
Bala
|
|
|
|
|
the question is not about "message" variable how you clean up "outputstring" variable.
|
|
|
|
|
I wanna make a session logger program for different users working with my program(create a list buttons they click), this should be saved somewhere and later, it must be possible to read this info and create an excel report file from it.
How can I do it?
modified on Wednesday, May 7, 2008 2:49 AM
|
|
|
|
|
Yes it is possible, you need to add Excel com object in your program!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You/codeProject$$>
|
|
|
|
|
|
there are 2 problems! The big problem is the first one, I don't have any idea how they log events and save them!
|
|
|
|
|
|
Hi,
I'm looking for a way to take a screen shot of a game from another process. I can get a screen shot of any normal application but the game uses DirectX and i have no idea how to do that . I searched the internet for a solution but i couldn't find any clue. All my attempts resulted in a black screen taken as screen shot which is normal due to that fact that the game doesn't render its images on screen but directly to the graphic card memory.
Any help regarding my problem is be appreciated.
Thanks
|
|
|
|
|
You can use
1. to hook DirectX
2. get address of graphics card and read bitmap in it
|
|
|
|
|
Interesting, do you know a resource about how to hook to directx and gain access to its surface buffer?
|
|
|
|
|
Have you tried printscreen when the game is running if so it would be possible in external application i think. probably you might have choosen wrong window handle to capture when in fullscreen. Have you tried to run the game in windowed mode.
Some Games have inbuilt feature for screen capture check that too.
|
|
|
|
|
Thanks for the fast reply,
The game responds to printscreen in full mode and saves a screenshot in JPG format in a directory, however printscreen works fine when it is windowed mode. I think this can solve the problem just when the game window has focus. My intention is to write a bot to control the game while running in the background. I think I'll need to access the game's screen while it is in the background. I wonder how that would be possible since the game might not render its screen at all. I have a feeling that i have to trick it into rendering or something like that
|
|
|
|
|
|
|
Hey everyone,
I create an empty dialog and add an activex control names ms flex grid 6.0. I create a class which inherited from CDialog and when I say create it fails and gives no information:
<br />
class CTry : CDialog<br />
{<br />
public: <br />
CTry ();<br />
};<br />
<br />
CTry ::CTry ()<br />
{<br />
if (!Create(DialogID))<br />
{ <br />
exit(-1);<br />
} <br />
};<br />
When I remove flex grid from dialog it suceeds...
I also know there was a liecense problem in design time with flex grid, but it says nothing when I am using it in design time
So any idea why this happens?
(Actually it happens when I try to add rich text box also.. seems like I cannot add an outside activex control)
Thanks everyone.
modified on Wednesday, May 7, 2008 1:31 AM
|
|
|
|
|
try initializing rich edit control with AfxInitRichEdit once in your application
BOOL <yourapp>::InitInstance()
{
AfxInitRichEdit( );
...
if you are not able to load flex grid,
try also, AfxEnableControlContainer() in InitInstance
|
|
|
|
|
I need to use Flex Grid, I just tried to use richedit also but didn't work.
So do you have any idea why flex grid didn't work??
here's code:
<br />
BOOL Appl::InitInstance()<br />
{<br />
AfxOleInit();<br />
thanks...
|
|
|
|
|
Have you tried the code which i given, because i tested AfxOleInit did't work but
AfxInitRichEdit for richedit control and AfxEnableControlContainer for Flex grid it worked.
|
|
|
|