Solved

Open file by dragging on application icon

Posted on 2000-02-22
12
290 Views
Last Modified: 2013-11-20
I have created an application which can open a file with extension abc. If i execute my application and drag a file with abc extension and drop it on my application window then the file is open in my application. For this I have called EnableShellOpen()RegisterShellFileTypes()and DragAcceptFiles() function in InitInstance() function. But when I drag the file with abc extension and drop it on the exe file of my application then my application crashed.
If any body have any idea how to solve this problem then please reply.
0
Comment
Question by:nabnof
  • 7
  • 5
12 Comments
 
LVL 30

Expert Comment

by:Zoppo
ID: 2549753
Where does it crash?

Tip: You must take care that dropping files onto a running application strongly differs from dropping it onto the exe-file of your application in explorer. Dropping files on running application causes the application to recieve a WM_DROPFILES message which can be handled with CWnd::OnDropFiles(), dropping them on the exe-file causes the application to be started with the pathnames of the dropped files passed as command line arguments.

ZOPPO
0
 

Author Comment

by:nabnof
ID: 2550005
My application crashed when processing
ProcessShellCommand() function. I have checked the value of CCommandLineInfo& rCmdInfo structure which is passed as an argument in this function, the value of strFileName is correct. If you know any function which should be call to solve this problem then please let me know because I am totally stuck because of this problem.
   You are right that in my scenario that first my application should be launched and then file is opened , but how it is possible to do both steps because i do not know how application will be launhed.
0
 

Author Comment

by:nabnof
ID: 2550008
My application crashed when processing
ProcessShellCommand() function. I have checked the value of CCommandLineInfo& rCmdInfo structure which is passed as an argument in this function, the value of strFileName is correct. If you know any function which should be call to solve this problem then please let me know because I am totally stuck because of this problem.
   You are right that in my scenario that first my application should be launched and then file is opened , but how it is possible to do both steps because i do not know how application will be launhed.
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 2550060
Perhaps your InitInstance does some initialization which is needed with OnFileOpen() after that ProcessShellCommand(). ProcessShellCommand() itself calls OnFileOpen() when the CommandLineInfo's FileOpen option is set.

Post some code please, best the whole InitInstance and the OnFileNew and OnFileOpen ...

ZOPPO
0
 

Author Comment

by:nabnof
ID: 2553244
Following is the sequence in which functions are executed and the point where crashed happened.
First of all ProcessShellCommand() is executed in which the case CCommandLineInfo::FileOpen is executed, in this case OpenDocumentFile(rCmdInfo.m_strFileName) function of CWinApp is executing , in this function m_pDocManager->OpenDocumentFile(lpszFileName) is called , when this function is returning my application is crashed. I am sendig the code of Initistane :
BOOL PExampleClassApp::InitInstance()
{
      AfxEnableControlContainer();
if (!AfxSocketInit())
      {
            AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
            return FALSE;
      }
      AfxInitRichEdit();
if( !AfxOleInit())
      {
            AfxMessageBox(IDS_OLE_INIT_FAILED);
            return FALSE;
      }
#ifdef _AFXDLL
      Enable3dControls();                  // Call this when using MFC in a shared DLL
#else
      Enable3dControlsStatic();      // Call this when linking to MFC statically
#endif
      SetRegistryKey(_T("ABC"));

      LoadStdProfileSettings();

CSingleDocTemplate* pDocTemplate;
      pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,
            RUNTIME_CLASS(PExampleClassDoc),
            RUNTIME_CLASS(PMainFrame),       // main SDI frame window
            RUNTIME_CLASS(PFormSelection));
      AddDocTemplate(pDocTemplate);
// enable file manager drag/drop and DDE Execute open
      EnableShellOpen();
      RegisterShellFileTypes(TRUE);

CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);
      AfxMessageBox("Parseshellcommand Start");
      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
      {

            return FALSE;
      }

// Enable drag/drop open

      m_pMainWnd->DragAcceptFiles(TRUE);
      m_pMainWnd->ShowWindow(SW_SHOW);
      m_pMainWnd->UpdateWindow();
}

I am very grateful to you for your deep concern in solving my problem and requesting you to help me as soon as possible.
0
 

Author Comment

by:nabnof
ID: 2553305
Following is the sequence in which functions are executed and the point where crashed happened.
First of all ProcessShellCommand() is executed in which the case CCommandLineInfo::FileOpen is executed, in this case OpenDocumentFile(rCmdInfo.m_strFileName) function of CWinApp is executing , in this function m_pDocManager->OpenDocumentFile(lpszFileName) is called , when this function is returning my application is crashed. I am sendig the code of Initistane :
BOOL PExampleClassApp::InitInstance()
{
      AfxEnableControlContainer();
if (!AfxSocketInit())
      {
            AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
            return FALSE;
      }
      AfxInitRichEdit();
if( !AfxOleInit())
      {
            AfxMessageBox(IDS_OLE_INIT_FAILED);
            return FALSE;
      }
#ifdef _AFXDLL
      Enable3dControls();                  // Call this when using MFC in a shared DLL
#else
      Enable3dControlsStatic();      // Call this when linking to MFC statically
#endif
      SetRegistryKey(_T("ABC"));

      LoadStdProfileSettings();

CSingleDocTemplate* pDocTemplate;
      pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,
            RUNTIME_CLASS(PExampleClassDoc),
            RUNTIME_CLASS(PMainFrame),       // main SDI frame window
            RUNTIME_CLASS(PFormSelection));
      AddDocTemplate(pDocTemplate);
// enable file manager drag/drop and DDE Execute open
      EnableShellOpen();
      RegisterShellFileTypes(TRUE);

CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);
      AfxMessageBox("Parseshellcommand Start");
      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
      {

            return FALSE;
      }

// Enable drag/drop open

      m_pMainWnd->DragAcceptFiles(TRUE);
      m_pMainWnd->ShowWindow(SW_SHOW);
      m_pMainWnd->UpdateWindow();
}

I am very grateful to you for your deep concern in solving my problem and requesting you to help me as soon as possible.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:nabnof
ID: 2553313
Following is the sequence in which functions are executed and the point where crashed happened.
First of all ProcessShellCommand() is executed in which the case CCommandLineInfo::FileOpen is executed, in this case OpenDocumentFile(rCmdInfo.m_strFileName) function of CWinApp is executing , in this function m_pDocManager->OpenDocumentFile(lpszFileName) is called , when this function is returning my application is crashed. I am sendig the code of Initistane :
BOOL PExampleClassApp::InitInstance()
{
      AfxEnableControlContainer();
if (!AfxSocketInit())
      {
            AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
            return FALSE;
      }
      AfxInitRichEdit();
if( !AfxOleInit())
      {
            AfxMessageBox(IDS_OLE_INIT_FAILED);
            return FALSE;
      }
#ifdef _AFXDLL
      Enable3dControls();                  // Call this when using MFC in a shared DLL
#else
      Enable3dControlsStatic();      // Call this when linking to MFC statically
#endif
      SetRegistryKey(_T("ABC"));

      LoadStdProfileSettings();

CSingleDocTemplate* pDocTemplate;
      pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,
            RUNTIME_CLASS(PExampleClassDoc),
            RUNTIME_CLASS(PMainFrame),       // main SDI frame window
            RUNTIME_CLASS(PFormSelection));
      AddDocTemplate(pDocTemplate);
// enable file manager drag/drop and DDE Execute open
      EnableShellOpen();
      RegisterShellFileTypes(TRUE);

CCommandLineInfo cmdInfo;
      ParseCommandLine(cmdInfo);
      AfxMessageBox("Parseshellcommand Start");
      // Dispatch commands specified on the command line
      if (!ProcessShellCommand(cmdInfo))
      {

            return FALSE;
      }

// Enable drag/drop open

      m_pMainWnd->DragAcceptFiles(TRUE);
      m_pMainWnd->ShowWindow(SW_SHOW);
      m_pMainWnd->UpdateWindow();
}

I am very grateful to you for your deep concern in solving my problem and requesting you to help me as soon as possible.
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 2553634
Now, I cannot see any problem with this code, maybe the problem is somewhere in the document class' loading/creating functions.

That's hard for me to find in this way, so I would suggest you to send me your project's code to zoppo@cdsgmbh.de that I can debug it here and try to find out. If you don't want to send me whole project you could even make a copy of your project and try to remove any part which is not needed to reproduce the behavior.

ZOPPO
0
 

Author Comment

by:nabnof
ID: 2553980
I am very grateful for your help in this problem but I am not able to send the code. My senior has another point in mind, since my applications is SDI but I created multilple views . In InitInstance the document is opeened first in ParsCommandLine fuction and views are created afterward, do u mind this maybe cause of crash of my application. Please do reply.
0
 
LVL 30

Accepted Solution

by:
Zoppo earned 25 total points
ID: 2554007
Yes, I think this may possibly be the problem.
Maybe you can solve this problem by just calling a OnFileNew() before ParseCommandLine().
But even it can be that the problem is where/when and how you create these multiple views. Try to create these views within mainframe's creation, i.e. best in CMainFrame::OnCreateClient(), which is called by the gframework to create the view.

ZOPPO
0
 

Author Comment

by:nabnof
ID: 2554168
By calling OnFileNew() before ProcessShellCommand() , my problem is solved and now my application is not crashing. I am very very thankful to you for constant help. Now just last question that why just calling this function my problem is solved. Please do reply so that I understand the logic behind this. Again I am very very grateful and looking forward in future for your kind assisstance. My name is Jamil Ahmed and I am working as a Software Engineer in private software house in Karachi Pakistan.
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 2554290
Hi nabnof,

now, I cannot tell you exactly why this is, just a thought: Your application does not crash if it starts without a filename passed with command line, so I know you OnFileNew() is ok, because this is by default called from ProcessCommandLine() with no arguments. With arguments you application crashed, so I think the problem is that something is not yet initialized before OnNewDocument() is called.
Perhaps you overwrote the default behavior of OnNewDocument() or any function called from within OnNewDocument() to create your views and do some other initialization and the problem is that OnNewDocument() is never called when filenames are passed via command line.

It's hard for me to say more about this without knowing the code, but it seem logical to me...

Of course I can try to help you when I have time to do, so feel free to email me when you have problems.

ZOPPO
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now