Reputation: 21
I'm looking forward to find a way to get a URL from Firefox using MFC. Actually I used a way that get a URL from Firfox which is called DDE (Dynamic Data Exchange). It worked well in Firefox version 49, but doesn't work in Firefox version 50+.
I would like to get ideas about this problem. The following is:
1) Is there a big change between Firefox version 49 and 50?
2) Why DDE is not working in Firefox 50?
3) What is the best way to find a URL from Firefox using MFC? (Sadly, I can't use other programming languages such as C#.)
Here is the code that I recently used. Please have a look at this code and try to help me find answers to my three questions. Thank you!
wchar_t szApp[] = L"Firefox";
wchar_t szTopic[] = L"WWW_GetWindowInfo";
//DDE Initialization
DWORD idInst=0;
UINT iReturn;
iReturn = DdeInitialize(&idInst, (PFNCALLBACK)DdeCallback,
APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0 );
if (iReturn!=DMLERR_NO_ERROR)
{
_TM(L"DDE Initialization Failed: 0x%04x\n", iReturn);
Sleep(1500);
break;
}
//DDE Connect to Server using given AppName and topic.
HSZ hszApp, hszTopic;
HCONV hConv;
hszApp = DdeCreateStringHandle(idInst, szApp, 0);
hszTopic = DdeCreateStringHandle(idInst, szTopic, 0);
hConv = DdeConnect(idInst, hszApp, hszTopic, NULL);
DdeFreeStringHandle(idInst, hszApp);
DdeFreeStringHandle(idInst, hszTopic);
if (hConv == NULL)
{
_TM(L"DDE Connection Failed.\n");
Sleep(1500); DdeUninitialize(idInst);
break;
}
wchar_t szItem1[100];
wchar_t szDesc1[DDEREQUEST_ITEM_LENGTH];
memset(szItem1,0,sizeof(szItem1));
memset(szDesc1,0,sizeof(szDesc1));
wsprintf(szItem1,L"URL");
//Execute commands/requests specific to the DDE Server.
DDERequest(idInst, hConv, szItem1, szDesc1);
//DDE Disconnect and Uninitialize.
DdeDisconnect(hConv);
DdeUninitialize(idInst);
CString strData;
strData.Format(L"%s",szDesc1);
strData.MakeLower();
_TM(L"firefox Start : %s\n",strData);
int nStartPos = strData.Find(L"http");
if (nStartPos!=-1)
{
int nEndPos = strData.Find(L"\"",nStartPos+1);
if (nEndPos!=-1)
{
strReturnUrl = strData.Mid(nStartPos,nEndPos-1);
}
else
{
nEndPos = strData.Find(L"/",nStartPos+9);
strReturnUrl = strData.Mid(nStartPos,nEndPos-1);
}
}
_TM(L"firefox End : %s\n",strReturnUrl);
if (strReturnUrl.IsEmpty())
{
_TM(L"firefox chrome Start\n");
strReturnUrl = GetChromeWndAddress(hWnd);
_TM(L"firefox chrome End : %s\n",strReturnUrl);
}
Upvotes: 2
Views: 213