1 写proc 程序如my.pc 这个文件附在下面,是另一位老兄的
2 在控制台方式下,用c:>proc my.pc把它编译成为my.c文件
3 在VC下起一个新的对话框工程,在这个工程中加入一个新的you.cpp文件,在这个文件的第一行加入#include "stdafx.h",然后把my.c的内容全部复制到you.cpp上,
4 找到oracle安装目录下的orasql8.lib文件,把它的路径加到VC集成开发环境中,或者把这个文件直接复制到\Microsoft Visual Studio\VC98>lib中目录中,
5 把包含sqlca.h的目录(如D:\oracle\ora81\precomp\public)加入到vc的集成开发环境中
6 打开工程设置选项把上面的在link面版上加入orasql8.lib,然后就可以编译了,这时候如果出现下面的错误的话
...error LNK2001: unresolved external symbol "void __cdecl sqlcxt(void * *,unsigned long *,struct sqlexd *,struct sqlcxp const *)" (?sqlcxt@@YAXPAPAXPAKPAUsqlexd@@PBUsqlcxp@@@Z)
找到下面的内容
extern void sqlcxt (void **, unsigned long *,
                    struct sqlexd *, const struct sqlcxp *);
extern void sqlcx2t(void **, unsigned long *,
                    struct sqlexd *, const struct sqlcxp *);
extern void sqlbuft(void **, char *);
extern void sqlgs2t(void **, char *);
extern void sqlorat(void **, unsigned long *, void *);
把上面的内容换成
extern  "C"__declspec(dllimport) void sqlcxt (void **, unsigned long *,
                    struct sqlexd *, const struct sqlcxp *);
extern "C"__declspec(dllimport)void sqlcx2t(void **, unsigned long *,
                    struct sqlexd *, const struct sqlcxp *);
extern "C"__declspec(dllimport)void sqlbuft(void **, char *);
extern "C"__declspec(dllimport)void sqlgs2t(void **, char *);
extern "C"__declspec(dllimport)void sqlorat(void **, unsigned long *, void *);
这时再编译一下,一切OK!!第二种方法是如果你就是控制台程序的话,用proc my.pc 形成my.c
后,直接就可以c:>cl my.c orasql8.lib了附上另一位老兄的my.pc程序,他讲得很好!只是编译的地方讲得不是很清楚,编译的地方可以参照上面的内容,下面的程序是一个联结数据库的PRO*C 源程序例子。#include < sqlca.h > //声明SQL通讯区
#include < string.h >
#include < afxwin.h >
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR username[20]; //声明宿主变量
VARCHAR password[20];
VARCHAR dbname[20];
EXEC SQL END DECLARE SECTION;
int main()
{
strcpy((char *)username.arr,"SCOTT");
username.len = strlen((char *)username.arr);
strcpy((char *)password.arr,"TIGER");
password.len = strlen((char *)password.arr);
strcpy((char *)dbname.arr,"SUNDB");
dbname.len = strlen((char *)dbname.arr);
EXEC SQL WHENEVER SQLERROR STOP; //隐式异常处理
EXEC SQL CONNECT :username 
IDENTIFIED BY :password USING :dbname;
if (sqlca.sqlcode != 0) //显式异常处理
{
AfxMessageBox("\n与Oracle数据库连接失败!"); 
return;
}
}在VC 中使用PRO*C 时,先用PRO*C 编写所需的操作数据库的子程序,
再运行PRO*C 预编译程序把PRO*C 源程序转成相应的CPP 源程序,
将该程序插入到用户工程文件中并在需要对插入函数进行调用的模块中说明函数,
然后就可以在此模块中调用所需的函数。 liubear() deng0825(甲骨文) 

解决方案 »

  1.   

    祝贺你,
    我想这没有什么问题!我应经测试了oracle的所有的调用方式,
    只要记住oracle 的dll使用纯C写的就行了,这样VC不能直接调用,需要额外地设置函数调用原型!
      

  2.   

    在调用的时候,由于oracle 的对字符串的处理一般将其看成双字节的,需要多关照一点!也就是利用:
    reinterpret_cast<char *>
    reinterpret_cast<signed int  *>
    reinterpret_cast<unsigend int  *>
    转换一下!
      

  3.   

    谁研究一下在UNIX下怎么编译pro*c?
    必须写makefile,不能手动编译吗?
    谁能给我一个最简洁的makefile模板(就编译以上my.c)?
      

  4.   

    在unix下面编译pro*c,只要加入路径就可以编译了。不一定要写makefile。本人认为makefile相当于windows下的.bat文件。先将.pc文件编译成.c文件,然后用cc编译成可执行文件。