2

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);
}
HANS
  • 21
  • 1
  • Can you provide some explanation of what this code is supposed to do? – jhpratt May 30 '18 at 04:37
  • When I focus my mouse cursor to web page in firefox brower, I use DDE request to get string informations from web page. Should I add more explanation to this code? @jhpratt – HANS May 30 '18 at 05:01
  • 1
    See this example using UI Automation with Chrome https://stackoverflow.com/questions/48504300/get-active-tab-url-in-chrome-with-c/48507146#48507146 - It's the same idea with Firefox – Barmak Shemirani May 30 '18 at 05:58
  • @BarmakShemirani As I see, That is a great idea! It is really helpful to me. Thank you for your advice! I'll try that. – HANS May 30 '18 at 06:02
  • @BarmakShemirani Thank you so much, Barmak Shemirani! I resolve this problem with your answer. I really appreciate it!!! – HANS May 31 '18 at 01:40
  • You are welcome. You can add an answer to your own question if you like. – Barmak Shemirani Jun 01 '18 at 15:39

0 Answers0