想实现自动提交表单的功能,把所有代码都写在testDlg.cpp文件中没有问题。// testDlg.cpp关键代码如下//HTML相关头文件
#include <atlbase.h>
CComModule _Module;
#include <mshtml.h>
#include <atlcom.h>
#include <oleacc.h>
#include <comdef.h>//实现填写表单
void  CtestDlg::PutFormValue(spDocument2,m_strUserName,m_strPassword)
{..........
}void CtestDlg::OnButton1()
{
CComPtr <IDispatch> spDispDoc;
spDispDoc = m_ctrlWeb.GetDocument();
CComQIPtr<IHTMLDocument2> spDocument2 = spDispDoc;
if (!spDocument2)
 return ;

//调用填写表单的函数
PutFormValue(spDocument2,m_strUserName,m_strPassword);
}
//===========================================================
想把实现填写表单的函数,放到另外一个文件中,用extern声明,
然后在testDlg.cpp中直接调用,
HTML相关头文件该如何进行条件编译呢????请熟悉的朋友帮忙提下建议,谢谢
//===========================================================
// CPutForm.h 头文件
//声明填写表单的函数
extern void  mymyPutFormValue(spDocument2,m_strUserName,m_strPassword);// CPutForm.cpp 实现文件
//实现填写表单
void  mymyPutFormValue(spDocument2,m_strUserName,m_strPassword)
{....
}// testDlg.cpp
#include  "CPutForm.h" //引用头文件
void CtestDlg::OnButton1()
{
CComPtr <IDispatch> spDispDoc;
spDispDoc = m_ctrlWeb.GetDocument();
CComQIPtr<IHTMLDocument2> spDocument2 = spDispDoc;
if (!spDocument2)
 return ;

//调用mymyPutFormValue
mymyPutFormValue(spDocument2,m_strUserName,m_strPassword);
}

解决方案 »

  1.   

    HTML相关头文件只在CPutForm.h头文件中定义:
    出现连接错误,class ATL::CComModule _Module重复定义//===========================================================
    // CPutForm.h 头文件
    //HTML相关头文件
    #include <atlbase.h>
    CComModule _Module;
    #include <mshtml.h>
    #include <atlcom.h>
    #include <oleacc.h>
    #include <comdef.h>//声明填写表单的函数
    extern void  mymyPutFormValue(spDocument2,m_strUserName,m_strPassword);// CPutForm.cpp 实现文件
    //实现填写表单
    void  mymyPutFormValue(spDocument2,m_strUserName,m_strPassword)
    {....
    }// testDlg.cpp
    #include  "CPutForm.h" //引用头文件
    void CtestDlg::OnButton1()
    {
    CComPtr <IDispatch> spDispDoc;
    spDispDoc = m_ctrlWeb.GetDocument();                
    CComQIPtr<IHTMLDocument2> spDocument2 = spDispDoc;
    if (!spDocument2)        
     return ;        
        
    //调用mymyPutFormValue
    mymyPutFormValue(spDocument2,m_strUserName,m_strPassword);
    }
    Linking...
    testDlg.obj : error LNK2005: "class ATL::CComModule _Module" (?_Module@@3VCComModule@ATL@@A) already defined in MyPutFormValue.obj
    Release/test.exe : fatal error LNK1169: one or more multiply defined symbols found
      

  2.   

    刚刚试了下把下面几个头文件都写到
    stdafx.h这个文件中就没有问题了//HTML相关头文件
    #include <atlbase.h>
    CComModule _Module;    
    #include <mshtml.h>    
    #include <atlcom.h>
    #include <oleacc.h>
    #include <comdef.h>