想在Windows平台下用C/C++开发一个无界面的数据库应用程序,除了用VC,大家说说看还有什么编译器比较合适?要求所写的程序必须可在VC外的其他C编译器下编译通过,如果我用VC下的Console程序写,有哪些需要注意的地方?对数据库的连接用什么方式比较合适(主要是Oracle和Sybase数据库)?(如果用ADO方式要求包含stdafx.h头文件,这样就不能独立于VC环境),谢谢了,分不够可以加。

解决方案 »

  1.   

    不一定要包含stdafx.h,将import命令放到你想放的地方。
      

  2.   

    用ADO要求包含stdafx.h么?
    没这回事
    在自己的头文件中#import也一样
      

  3.   

    偶公司的服务器程序基本都是纯C++的
    就是用VC写
      

  4.   

    用VC的Console写的程序不能引用MFC的类吧,就是说写的Console程序肯定可以在其他C编译器下运行是吗?
      

  5.   

    1.用VC写的console可以引用MFC类
    2.用纯VC写的不一定能用其它编译通过,如以下程序:
    #include <windows.h>
    #include <stdio.h>
    #include  <comdef.h>
    #import "d:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
    void main()
    {
       CoInitialize(NULL);  _ConnectionPtr m_pConnection;
      HRESULT hr;
      hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
      if(SUCCEEDED(hr))
        hr = m_pConnection->Open(L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\temp\\DBTEST\\db1.mdb;Persist Security Info=True",L"",L"",adModeUnknown);///连接数据库
        else
         {
          printf("error\n");
          return;
         }  if(!SUCCEEDED(hr))
      {
          printf("error\n");
          return;
     } 
       _variant_t RecordsAffected;
       _RecordsetPtr m_pRecordset =  m_pConnection->Execute(L"SELECT COUNT(*) FROM users",&RecordsAffected,adCmdText);
      _variant_t vIndex = (long)0;
      _variant_t vCount = m_pRecordset->GetCollect(vIndex);///取得第一个字段的值放入vCount变量
      m_pRecordset->Close();///关闭记录集
      
      printf("共有%d条记录\n",vCount.lVal);  _CommandPtr m_pCommand;
      m_pCommand.CreateInstance("ADODB.Command");
      _variant_t vNULL;
      vNULL.vt = VT_ERROR;
      vNULL.scode = DISP_E_PARAMNOTFOUND;///定义为无参数
      m_pCommand->ActiveConnection = m_pConnection;///非常关键的一句,将建立的连接赋值给它
      m_pCommand->CommandText = "SELECT id,username FROM users";///命令字串
      m_pRecordset = m_pCommand->Execute(&vNULL,&vNULL,adCmdText);///执行命令,取得记录集
      while(!m_pRecordset->adoEOF)
      {
        vIndex = (long)0;
        _variant_t id = m_pRecordset->GetCollect(vIndex);///取得第一个字段的值放入vCount变量
      
        vIndex = (long)1;
        _variant_t vName = m_pRecordset->GetCollect(vIndex);///取得第一个字段的值放入vCount变量
        int nLen = wcslen(vName.bstrVal)+1; 
        char *buf = new char[2*nLen]; 
        WideCharToMultiByte(CP_ACP, 0, vName.bstrVal, nLen, buf, 2*nLen, NULL, NULL);     
        printf("id=%d\tname=%s\n",id.iVal,buf);
        delete buf;    m_pRecordset->MoveNext();  } 
      m_pRecordset->Close();///关闭记录集  if(m_pConnection->State)
         m_pConnection->Close(); ///如果已经打开了连接则关闭它}用VC没问题,用BCB或GCC就不行
      

  6.   

    要用其他编译器那么不要用MFC,ado什么的。直接调用ODBC API可能是通用性最好的
      

  7.   

    lcstudio(铁板牛牛),能给个例子吗?不晓得这种方式怎么写。thx:)