1 Reply Latest reply: Mar 6, 2013 7:14 AM by BluShadow RSS

    execute pro*c in c++/cli environment

    Joseph Hwang
      I try to execute oracle pro*c in c++/cli project, but it throws exception. This is my code.

      === oracle_connect.pc

      #include <stdio.h>
      #include <sqlca.h>

      EXEC SQL BEGIN DECLARE SECTION;

           #define UNAME_LEN 30
           #define PWD_LEN 30
           
           VARCHAR uid[UNAME_LEN];
           VARCHAR pwd[PWD_LEN];

      EXEC SQL END DECLARE SECTION;

      void main(){

           strncpy((char *) uid.arr, "scott", UNAME_LEN);
           uid.len = (short)strlen((char*)uid.arr);
           uid.arr[uid.len] = '\0';
                
           strncpy((char *) pwd.arr, "tiger", PWD_LEN);
           pwd.len = (short)strlen((char*)pwd.arr);
           pwd.arr[pwd.len] = '\0';
           
           EXEC SQL CONNECT :uid IDENTIFIED BY :pwd ;

           if (sqlca.sqlcode != 0){
                printf("Error : [%s].\n", sqlca.sqlerrm.sqlerrmc);
                
                exit(0);
           }
           
           printf("Connected !");

           exit(0);
      }

      ====== exec_proc.cpp in c++/cli project

      ProcessStartInfo^ pStartInfo1 = gcnew ProcessStartInfo();
           pStartInfo1->FileName = "proc.exe";
           pStartInfo1->UseShellExecute = false;
           pStartInfo1->RedirectStandardOutput = true;
           pStartInfo1->WindowStyle = ProcessWindowStyle::Hidden;
           pStartInfo1->Arguments = "oracle_connect.pc";

           ProcessStartInfo^ pStartInfo2 = gcnew ProcessStartInfo();
           pStartInfo2->FileName = "cl.exe";
           pStartInfo2->UseShellExecute = false;
           pStartInfo2->RedirectStandardOutput = true;
           pStartInfo2->WindowStyle = ProcessWindowStyle::Hidden;
           String^ arg1 = " /I C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\public";
           String^ arg2 = " /I \"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\include\"";
           String^ arg3 = " /link C:\\app\\Administrator\\product\\11.2.0\\dbhome_1\\precomp\\LIB\\ORASQL11.LIB /LIBPATH:\"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\lib\"";
           
           pStartInfo2->Arguments = arg1 + arg2 +" oracle_connect.c" + arg3 ;

           try {
                Process^ exeP = Process::Start(pStartInfo1);

                StreamReader^ reader = exeP->StandardOutput;

                String^ result = reader->ReadToEnd();
                
                Console::Write(result);

                Console::ReadLine();


                Process^ exeK = Process::Start(pStartInfo2);

                StreamReader^ sReader = exeK->StandardOutput;

                String^ resultR = sReader->ReadToEnd();
                
                Console::Write(resultR); *// Throws error messages*

                Console::ReadLine();
           }
           catch ( Exception^ e){
                Console::WriteLine(e->Message);
      Console::ReadLine();
           }

      The errors are

      error LNK 2019 : unresolved external symbol "exit" ( and "printf", "strlen", "strncpy").....

      I think linking of proc lib is failed, but i don't know what is wrong...
      I need your help! Thanks in advance.