本帖最后由 gy007yg 于 2010-08-26 17:18:04 编辑

解决方案 »

  1.   

    后来查到是利用ShellExecute就可以实现啦 
      

  2.   

    我只是知道了调用。udl文件,但是在里面输入的数据库位置、名称什么的怎么获得?
      

  3.   

    点击确定后再次用打开文本的方式打开UDL读取.
      

  4.   

    // 功能: 打开数据链接对话框,获得输入值。CString CMyDialog::ADOConnection()
    {
        CString m_strConnectString;
    HRESULT hr = S_OK; MSDASC::IDataSourceLocatorPtr ptrDataSourceWnd = NULL;
    hr = ptrDataSourceWnd.CreateInstance(__uuidof(MSDASC::DataLinks));
        if(FAILED(hr))
    _com_issue_error(hr);
        hr = ptrDataSourceWnd->put_hWnd((long)this->m_hWnd);
    if(FAILED(hr))
            _com_issue_error(hr);
                  
    IDispatchPtr ptrDispatch = NULL;
    hr = ptrDataSourceWnd->PromptNew(&ptrDispatch);
       if(FAILED(hr))
    _com_issue_error(hr);
        if(ptrDispatch != NULL)
    {
           _ConnectionPtr m_Conn=  ptrDispatch;
       BSTR bstrConnectString =m_Conn->ConnectionString;
       USES_CONVERSION;
       m_strConnectString = W2CT(bstrConnectString);
       TRACE(_T("Connect String: %s\n"), (LPCTSTR)m_strConnectString);
    }
       return m_strConnectString;
    }//功能: 在对话框中,用户点按钮,打开数据链接对话框。
    void CMyDialog::OnBnClickedLink()
    {
    // TODO: 在此添加控件通知处理程序代码
    strConnection = ADOConnection() + ";" ;
      
    }//功能: 打开预先定义的udl文件。BOOL CMyDialog::OnInitDialog()
    {
    CDialog::OnInitDialog(); // TODO:  在此添加额外的初始化
        strAppPath = theApp.AppPathName();
        strConnection = _T("File Name="+strAppPath+"\\dbspy.udl;");
       
    return TRUE;  // return TRUE unless you set the focus to a control
    // 异常:OCX 属性页应返回 FALSE
    }