我看了mysql安装好后给的demo ,可惜它不是mfc的。
我在我的语句中加入
#include    <windows.h>
#include <stdio.h>
#include <string.h>
#include <mysql.h>
结果编译就出错了。--------------------Configuration: SetDBInfo - Win32 Debug--------------------
Compiling...
SetDBInfoDlg.cpp
d:\program files\mysql\mysql server 5.0\include\mysql_com.h(175) : error C2146: syntax error : missing ';' before identifier 'fd'
d:\program files\mysql\mysql server 5.0\include\mysql_com.h(175) : error C2501: 'SOCKET' : missing storage-class or type specifiers
d:\program files\mysql\mysql server 5.0\include\mysql_com.h(175) : error C2501: 'fd' : missing storage-class or type specifiers
d:\program files\mysql\mysql server 5.0\include\mysql_com.h(339) : error C2065: 'SOCKET' : undeclared identifier
d:\program files\mysql\mysql server 5.0\include\mysql_com.h(339) : error C2146: syntax error : missing ')' before identifier 's'
d:\program files\mysql\mysql server 5.0\include\mysql_com.h(340) : error C2059: syntax error : ')'
Error executing cl.exe.SetDBInfo.exe - 6 error(s), 0 warning(s)我不想使用mysqlodbc,难道我上述的办法就不行吗?

解决方案 »

  1.   

    错误与mysql无关,是socket的问题
      

  2.   

    我使用的是vc6,可以正确编译demo。
    请问楼上2位大虾,我缺哪些头文件?
      

  3.   

    #include "stdafx.h"
    #include <stdio.h>
    #include <string.h>
    #include <mysql.h>
      

  4.   

    回  syy64(太平洋) 大佬:
    我开始已经加入了
    #include    <windows.h>
    #include <stdio.h>
    #include <string.h>
    #include <mysql.h>,
    按照你说的,改为了
    #include "stdafx.h"
    #include <stdio.h>
    #include <string.h>
    #include <mysql.h>错误信息完全一致。我这个poject 是拿vc6 制作的一个mfc的对话框程序。
    在vc的option中的include 中的第一条中已经加入了 mysql 的include 的目录。
      

  5.   

    你既然用VC6,为什么不用MySQL的VC6类库呢?那里面都是封装好的C++的类……从底层来不是不可以,但是你需要自己打开mysql的那一把头文件,然后自己去追那些乱七八糟的预编译指令……你现在的问题很可能和某个指令规定的条件不满足有关(譬如你没有定义某个宏,或者某个宏版本上面无法满足……)
      

  6.   

    在包含mysql.h之前,需要包含winsock.h或winsock2.h,注意如果使用winsock2.h,则此头文件需要在Windows.h之前
      

  7.   

    还有就是注意你用mfc向导生成工程时一定要记得把socket支持选上
      

  8.   

    好人啊!!
    加上winsock2.h,编译通过,哭死我了。
      

  9.   

    总结下:
    在mfc中使用mysql ,可以加入以下头文件
    #include <winsock2.h>
    #include <mysql.h>
    另外请教  newbiestar()  大虾,MySQL的VC6类库 是嘛玩意? 
      

  10.   

    完了完了,那个东西已经不复存在了……现在只剩下一个MySQL++了,按照STL方式构建的MySQL C API的C++ Wrapper你可以参考这里……
    http://www.mysql.com/products/mysql++/,然后将会转入这里
    http://tangentsoft.net/mysql++/