|
The AMCap program in the DirectX samples of platform SDK is a good starting reference.
«_Superman_»
I love work. It gives me something to do between weekends.
|
|
|
|
|
1.return String("abc");
2.String temp("abc");
return temp;
Thanks.
modified on Sunday, June 14, 2009 12:06 PM
|
|
|
|
|
In terms of overall semantics, no difference. With a decent, modern, optimising C++ compiler, they should result in the same object code - the 'named return value optimisation[^]' would make sure of that.
Without that optimisation, there will be extra string constructor and destructor calls.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
There is no difference. Both return the address of a temporary variable on the stack.
Best Wishes,
-David Delaune
|
|
|
|
|
As far as I understand, a call to CreateCompatibleDC(NULL) is equivalent to a call to CreateCompatibleDC(hdc) for some hdc (hdc is not NULL, of course).
The question is how to get hdc in the second call so that it is equivalent to the first one?
I actually need a handle of the window which is associated with the hdc. I was going to use WindowFromDC(hdc) for that porpose. Is it possible to find hdc and then to find window handle in that way?
The point is that some dictionaries like stardict use the technique of API hooking to translate text. They can translate a word when a mouse hovers over the text. In my case I don't use mouse position, I need to filter some text according to what window it belongs to. I thought it was possible to use DC for that purpose. The idea was to intercept DrawText, TextOut etc, get HDC from their parameter and then by call to WindowFromDC get window handle. The problem is that some application create DC in memory by CreateCompatibleDC(NULL) and do text output to the memory DC. The solution seemed to be in intercepting CreateCompatibleDC(NULL) and getting somehow the real DC by calling some (unknown to me) API-function from the intercepted CreateCompatibleDC, and finally getting window handle from WindowFromDC( <real dc=""> ).
modified on Sunday, June 14, 2009 1:53 PM
|
|
|
|
|
japcrword wrote: The question is how to get hdc in the second call so that it is equivalent to the first one?
Have you checked to see this is compatiable?
CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
CreateDC Function[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Well, I don't think this is what I need. First of all, I don't need to create any new device contexts. And second, as far as I know, the device context created by CreateDC(_T("DISPLAY"),NULL,NULL,NULL) is associated with the whole screen.
My problem is the following. I have an (intercepted) call
CreateCompatibleDC(NULL);
According to MSDN Library it creates a memory DC compatible with the application's current screen.
Application's current screen is the window owned by this application, or am I getting something wrong? I need the handle of that window. I want to find HDC simply in order to find window associated with it (calling WindowFromDC).
|
|
|
|
|
japcrword wrote: I need the handle of that window
Well, this is a completely different question. Unfortunately I am still unable to help you because you are not giving enough details.
japcrword wrote: I have an (intercepted) call
You need to define what you mean here. Have you used an API hook to intercept CreateCompatibleDC?
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you for quick answer. I indeed use API hooks to intercept CreateCompatibleDC. The created by CreateCompatibleDC memory DC is used for drawing some text. I need to know what window this memory DC is applied to in the end.
Some dictionaries like stardict use the technique of API hooking to translate text. They can translate a word when a mouse hovers over the text. In my case I don't use mouse position, I need to filter some text according to what window it belongs to. I thought it was possible to use DC for that purpose. The idea was to intercept DrawText, TextOut etc, get HDC from their parameter and then bby call to WindowFromDC get window handle. The problem is that some application create DC in memory by CreateCompatibleDC(NULL) and do text output to the memory DC. The solution seemed to be in intercepting CreateCompatibleDC(NULL) and getting somehow the real DC by calling some (unknown to me) API-function from the intercepted CreateCompatibleDC, and finally getting window handle from WindowFromDC( <real DC> ).
I'm beginning to think that it isn't so simple as I initially supposed.
modified on Sunday, June 14, 2009 1:53 PM
|
|
|
|
|
Sounds like an interesting project indeed.
japcrword wrote: Some dictionaries like stardict use the technique of API hooking to translate text. They can translate a word when a mouse hovers over the text.
Ahhh now we can get somewhere. I would be willing to bet that those software packages are using the Text Object Model[^] to retrieve the text under the mouse and translate it. You could probably then create a tooltip near the mouse location containing a translation.
Using The Text Object Model[^]
How to retrieve text under the cursor (mouse pointer)[^]
Regarding your original question... if you still want to pursue that... let me know. It may require the use of some undocumented Windows internels. Since your API hook is probably executing in the same thread as the window we could narrow down the possibilities with EnumThreadWindows Function[^] and at that point we may be able to use the undocumented GdiQueryTable. There may be an easier way to accomplish it, I will need to think about it.
At any rate I think you should spend a few minutes investigating the Text Object Model.
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you very much. The links you provided are highly valuable to me (I have had a brief look at them, but I will explore them in more detail). The last question. Do you think it makes sense to intercept BitBlt (or may be some other API) in order to get window that displays intercepted text output by calling WindowFromDC( <destination hdc taken from intercepted BitBlt> )? Thanks.
|
|
|
|
|
japcrword wrote: Do you think it makes sense to intercept BitBlt (or may be some other API) in order to get window that displays intercepted text output by calling WindowFromDC( <destination hdc="" taken="" from="" intercepted="" bitblt=""> )? Thanks.
You specifically mentioned StarDict as a reference dictionary/translation product. And you stated that you wanted to create something similar. The source code for this open source project is available here:
http://downloads.sourceforge.net/stardict/stardict-3.0.1.tar.bz2[^]
The file stardict-3.0.1\stardict-3.0.1\src\win32\TextOutHook.c will show you that the following GDI functions are hooked:
TextOutA
TextOutW
ExtTextOutA
ExtTextOutW
The file also contains GetMenuItemInfo and GetWindowText calls. So this is how the product you referenced is implemented.
Now it becomes a philosophical issue. In my opinion the Text Object Model[^] is a superior method of obtaining the text for a product designed to read multiple processes and window text.
Its never a good idea to rely on Window hooks in commercial products. The decision is yours.
Best Wishes,
-David Delaune
|
|
|
|
|
Hi,
I am trying to display the attachments for message which is inside Outlook. There i am retriving the mails from inbox also attachments are displaying, but when I am trying to save in the hard disc it is not working. When I am tried to debug the solution i am getting error at Istream interface please give me solution. I am sending attach.cpp code, it is just win32 console application
/////////////////////////////////////////////////////////////////////////////////////
////////////////////file name:getattach.cpp//////////////////////////////////////
#include
#include
#include <mapix.h>
#include
#include <mapiutil.h>
#define _tcscpy strcpy
#define _tcscmp strcmp
STDMETHODIMP OpenDefaultMessageStore(LPMAPISESSION lpMAPISession,LPMDB * lpMDB);
STDMETHODIMP OpenInbox(LPMDB lpMDB,LPMAPIFOLDER *lpInboxFolder);
STDMETHODIMP ListMessages(LPMDB lpMDB,LPMAPIFOLDER lpInboxFolder);
int main()
{
HRESULT hRes;
LPMAPIFOLDER lpInboxFolder = NULL;
LPMAPISESSION lpMAPISession = NULL;
LPMDB lpMDB = NULL;
LPSPropValue tmp = NULL;
LPMESSAGE lpMessage = NULL;
IMAPISession *pIMapi = NULL;
if(MAPIInitialize(NULL) != S_OK)
return FALSE;
hRes = MAPILogonEx(0,NULL,NULL,MAPI_LOGON_UI, &lpMAPISession);
if (FAILED(hRes))
return FALSE;
hRes = OpenDefaultMessageStore(lpMAPISession,&lpMDB);
if (FAILED(hRes))
return FALSE;
hRes = OpenInbox(lpMDB,&lpInboxFolder);
if (FAILED(hRes))
return FALSE;
hRes = HrGetOneProp(lpInboxFolder,PR_DISPLAY_NAME,&tmp);
if (FAILED(hRes))
return FALSE;
printf("I managed to open the folder '%s'\n",tmp->Value.lpszA);
hRes = ListMessages(lpMDB,lpInboxFolder);
if (FAILED(hRes))
return FALSE;
if(!lpMessage)
return FALSE;
IMAPITable *pAttachTable = NULL;
hRes = lpMessage->GetAttachmentTable(0, &pAttachTable);
}
/////////////////////////////////////////////////////////////////////////////////////////
/* open message store table, This step we are opening the
default message store table.*////////////
STDMETHODIMP OpenDefaultMessageStore(LPMAPISESSION lpMAPISession,LPMDB * lpMDB)
{
LPMAPITABLE pStoresTbl = NULL;
LPSRowSet pRow = NULL;
static SRestriction sres;
SPropValue spv;
HRESULT hRes;
LPMDB lpTempMDB = NULL;
enum {EID, NAME, NUM_COLS};
static SizedSPropTagArray(NUM_COLS,sptCols) = {NUM_COLS, PR_ENTRYID, PR_DISPLAY_NAME};
*lpMDB = NULL;
hRes = lpMAPISession -> GetMsgStoresTable(0, &pStoresTbl);
if (FAILED(hRes))
return FALSE;
sres.rt = RES_PROPERTY;
sres.res.resProperty.relop = RELOP_EQ;
sres.res.resProperty.ulPropTag = PR_DEFAULT_STORE;
sres.res.resProperty.lpProp = &spv;
spv.ulPropTag = PR_DEFAULT_STORE;
spv.Value.b = TRUE;
hRes = HrQueryAllRows(pStoresTbl,(LPSPropTagArray) &sptCols,&sres,NULL,0,&pRow);
if (FAILED(hRes))
goto quit;
hRes = lpMAPISession->OpenMsgStore(NULL,pRow->aRow[0].lpProps[EID].Value.bin.cb,
(LPENTRYID)pRow->aRow[0].lpProps[EID].Value.bin.lpb,NULL,MAPI_BEST_ACCESS,
&lpTempMDB);
if (FAILED(hRes))
goto quit;
*lpMDB = lpTempMDB;
quit: //quit label
FreeProws(pRow);
UlRelease(pStoresTbl);
if (FAILED(hRes))
{
HRESULT hr;
LPMAPIERROR lpError;
hr = lpMAPISession->GetLastError(hRes,0,&lpError);
if (!hr)
{
printf("%s\n%s\n",lpError->lpszError,lpError->lpszComponent);
MAPIFreeBuffer(lpError);
}
}
return hRes;
}
//////* CLOSE open message store table, Now we are opened default message store*////////////
/////////////////////////////////////////////////////////////////////////////////////////
/////////////////* Now in this we have to open inbox*///////////////////////////////////
STDMETHODIMP OpenInbox(LPMDB lpMDB, LPMAPIFOLDER *lpInboxFolder)
{
ULONG cbInbox;
LPENTRYID lpbInbox;
ULONG ulObjType;
HRESULT hRes = S_OK;
LPMAPIFOLDER lpTempFolder = NULL;
*lpInboxFolder = NULL;
hRes = lpMDB->GetReceiveFolder(NULL,NULL,&cbInbox,&lpbInbox,NULL);
if (FAILED(hRes))
goto quit;
hRes = lpMDB->OpenEntry(cbInbox,lpbInbox,NULL,MAPI_BEST_ACCESS,
&ulObjType,(LPUNKNOWN *) &lpTempFolder);
if (FAILED(hRes))
goto quit;
*lpInboxFolder = lpTempFolder;
quit:
MAPIFreeBuffer(lpbInbox);
return hRes;
}
//////////////* Now sucessfully opened the INBOX *//////////////////
///////////////////////////////////////////////////////////////////
///////////* List the messages which is inside INBOX*/////////////
STDMETHODIMP ListMessages(LPMDB lpMDB,LPMAPIFOLDER lpInboxFolder)
{
HRESULT hRes = S_OK;
LPMAPITABLE lpContentsTable = NULL;
LPSRowSet pRows = NULL;
LPSTREAM lpStream = NULL;
ULONG i;
enum
{
ePR_SENT_REPRESENTING_NAME,
ePR_SUBJECT,
ePR_BODY,
ePR_PRIORITY,
ePR_ENTRYID,
NUM_COLS
};
static SizedSPropTagArray(NUM_COLS,sptCols) =
{ NUM_COLS, PR_SENT_REPRESENTING_NAME, PR_SUBJECT,
PR_BODY, PR_PRIORITY, PR_ENTRYID };
hRes = lpInboxFolder->GetContentsTable(0,&lpContentsTable);
if (FAILED(hRes))
goto quit;
hRes = HrQueryAllRows(lpContentsTable,(LPSPropTagArray) &sptCols,NULL,NULL,0,&pRows);
if (FAILED(hRes))
goto quit;
for (i = 0; i < pRows -> cRows; i++)
{
LPMESSAGE lpMessage = NULL;
ULONG ulObjType = NULL;
LPSPropValue lpProp = NULL;
printf("Message %d:\n",i);
if (PR_SENT_REPRESENTING_NAME == pRows -> aRow[i].lpProps[ePR_SENT_REPRESENTING_NAME].ulPropTag)
{
printf("From: %s\n",pRows->aRow[i].lpProps[ePR_SENT_REPRESENTING_NAME].Value.lpszA);
}
if (PR_SUBJECT == pRows -> aRow[i].lpProps[ePR_SUBJECT].ulPropTag)
{
printf("Subject: %s\n",pRows->aRow[i].lpProps[ePR_SUBJECT].Value.lpszA);
}
if (PR_PRIORITY == pRows -> aRow[i].lpProps[ePR_PRIORITY].ulPropTag)
{
printf("Priority: %d\n",pRows->aRow[i].lpProps[ePR_PRIORITY].Value.l);
}
/////////////////////body///////////////////////////////////////////////////////
if (MAPI_E_NOT_FOUND != pRows -> aRow[i].lpProps[ePR_BODY].Value.l)
{
hRes = lpMDB->OpenEntry(pRows->aRow[i].lpProps[ePR_ENTRYID].Value.bin.cb,
(LPENTRYID) pRows->aRow[i].lpProps[ePR_ENTRYID].Value.bin.lpb,NULL,
MAPI_BEST_ACCESS,&ulObjType,(LPUNKNOWN *) &lpMessage);
if (!FAILED(hRes))
{
hRes = HrGetOneProp(lpMessage,PR_BODY,&lpProp);
if (hRes == MAPI_E_NOT_ENOUGH_MEMORY)
{
char szBuf[255];
ULONG ulNumChars;
hRes = lpMessage->OpenProperty(PR_BODY,&IID_IStream,STGM_READ,NULL,
(LPUNKNOWN *) &lpStream);
do
{
lpStream->Read(szBuf,255,&ulNumChars);
if (ulNumChars >0) printf("%.*s",ulNumChars,szBuf);
}
while (ulNumChars >= 255);
printf("\n");
hRes = S_OK;
}
else if (hRes == MAPI_E_NOT_FOUND)
{
printf("Message has no body!\n");
hRes = S_OK;
}
else
{
printf("Body: %s\n",lpProp->Value.lpszA);
}
}
//////////////////////////////////////////////////////////////////////////////
///////start for displaying a attachment/////////////////////////////////////
if(!lpMessage)
goto a;
IMAPITable *pAttachTable = NULL;
hRes = lpMessage->GetAttachmentTable(0, &pAttachTable);
SRowSet *pAttachRowSet = NULL;
SizedSPropTagArray(3, tblAttachColumns)={3,{PR_ATTACH_NUM,PR_ATTACH_SIZE,PR_ATTACH_FILENAME}};
pAttachTable->SetColumns((LPSPropTagArray)&tblAttachColumns, 0);
hRes = pAttachTable->QueryRows(1, 0, &pAttachRowSet);
if(pAttachRowSet->cRows != 1)
goto a;
long lAttachNum = 0;
DWORD dwAttachSize = 0;
TCHAR tchAttachName[MAX_PATH] = TEXT("\0");
lAttachNum = pAttachRowSet->aRow[0].lpProps[0].Value.l;
dwAttachSize = pAttachRowSet->aRow[0].lpProps[1].Value.ul;
char *ptr=tchAttachName;
const char *ptr1=(char*)pAttachRowSet->aRow[0].lpProps[2].Value.lpszW;
_tcscpy(ptr,ptr1);
printf("attachment name is:",ptr1,"\n");
IAttach *pAttach = NULL;
hRes = lpMessage->OpenAttach(lAttachNum, 0, 0, &pAttach);
if(FAILED(hRes))
goto a;
IStream *pAttachStream = NULL;
HANDLE hAttachFile = NULL;
TCHAR tchFilePath[MAX_PATH] = TEXT("\0");
wsprintf(tchFilePath, TEXT("\\%s"), tchAttachName);
hAttachFile = CreateFile(tchFilePath, GENERIC_WRITE, 0, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
hRes=pAttach->OpenProperty(PR_ATTACH_DATA_BIN, NULL, 0, 0,(IUnknown **)&pAttachStream);
if(hAttachFile == INVALID_HANDLE_VALUE || FAILED(hRes))
goto a;
LPVOID lpBuffer = NULL;
DWORD dwRead = 0, dwWritten = 0;
lpBuffer = (LPVOID)LocalAlloc(LPTR, 4096);
do
{
memset(lpBuffer, 0, 4096);
pAttachStream->Read(lpBuffer, 4096, &dwRead);
// actual problem here, Because pattachstream is storing null, giving a debug error.
if(dwRead > 0)
WriteFile(hAttachFile, lpBuffer, dwRead, &dwWritten,NULL);
} while(dwRead > 0);
CloseHandle(hAttachFile);
LocalFree(lpBuffer);
FreeProws(pAttachRowSet);
}
a:
MAPIFreeBuffer(lpProp);
UlRelease(lpMessage);
hRes = S_OK;
}
quit:
FreeProws(pRows);
UlRelease(lpContentsTable);
return hRes;
}
sampath-padamatinti
|
|
|
|
|
is reading carefully this [^].
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
[My articles]
|
|
|
|
|
sampath-padamatinti wrote: ...but when I am trying to save in the hard disc it is not working.
Is this supposed to represent something meaningful? Use the debugger to narrow the problem down to just a few statements.
Why all the goto calls? They make your code even harder to debug.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
|
char as return type works fine,
<br />
extern "C" char _declspec(dllimport) Test();<br />
<br />
_declspec(dllexport) char Test()<br />
{<br />
return 't';<br />
}<br />
But why char* doesn't work here as the return type?
<br />
extern "C" char* _declspec(dllimport) Test();<br />
<br />
_declspec(dllexport) char* Test()<br />
{<br />
return "Test From DLL";<br />
}<br />
----------------------------
286? WOWW!
|
|
|
|
|
_8086 wrote: But why char* doesn't work here as the return type?
Can you define what you mean by 'doesn't work'?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
<br />
error C2059: syntax error : '__declspec(dllimport)'<br />
----------------------------
286? WOWW!
|
|
|
|
|
By the way, I'm keeping
extern "C" char* _declspec(dllimport) Test();
in a .h file.
----------------------------
286? WOWW!
|
|
|
|
|
This is just a hunch, but the declaration looks a little off. Try putting char* after the _declspec, instead of before it; that worked for me
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
After some tests, I found that the first 4 bytes is vptr, which is followed by data members.
Where is the run time type info?
|
|
|
|
|
Well you could use typid , and then look in the disassembly what it really does, right?
|
|
|
|
|
It's held in a separate area - it's a per-class thing, whereas instance data isn't. I suspect the vtable (which the vptr points at) contains the run-time type-info. As the other answer said, trace through the VC++ code for doing it
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I need to configure some application variables. I have a CFormView and via menu conmstruct a simple CDialog. However, after DoModal returns TDOK I am unable to retrieve the CComboBox selection - not even the GetCount returns number of items in the CComboBox. I seldom use CDialog but this got me stumped, I am obviously missing an important piece of code.
Thanks for reading and your help is as always appreciated.
Here is the offending code:
void CFD2008View::OnConfigureSetup()
{
CString strText;
CComboBox* pCombo10;
int nIndex;
int nCount;
// verify document
if(!m_CFD2008Doc)
m_CFD2008Doc = GetDocument();
VERIFY (m_CFD2008Doc);
CDialog dlg(IDD_DIALOG1);
if (dlg.DoModal()==IDOK){
TRACE("\nvoid CFD2008View::OnConfigureSetup() ");
pCombo10 = (CComboBox *) GetDlgItem(IDC_COMBO10);
VERIFY(pCombo10);
nIndex = pCombo10->GetCurSel();
//always returns 0
nCount = pCombo10->GetCount();
// always returns 0
}
}
|
|
|
|
|