This discussion is archived
7 Replies Latest reply: Oct 29, 2012 9:41 PM by 970843 RSS

OO4O and Standard C++

669890 Newbie
Currently Being Moderated
How can I get the C++ classes of OO4O into a standard C++ program? I don't want to use ASP or anything, just the C++ interfaces with the database.
  • 1. Re: OO4O and Standard C++
    gdarling - oracle Expert
    Currently Being Moderated
    Hi,

    You just need to include "oracl.h" and link with oraclm32.lib.
    I wouldnt encourage new development using OO4O however, as it's somewhat in maintenance mode these days. You may want to consider using the Oracle C++ Call Interface (OCCI) instead of OO4O.
    Anyway, here's some code a simple oo4o c++ example.

    Cheers,
    Greg


    /*
    create or replace procedure get5 (v1 out number) is
    begin
    v1 := 5;
    end;
    /
    */
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream.h>
    #include "oracl.h"

    int main( void )
    {
         char szOutput[500];
         ODatabase odb;
         OValue val;

         OStartup();
         odb.Open("orcl", "scott", "tiger");
         odb.GetParameters().Add("numparam",0, OPARAMETER_OUTVAR, OTYPE_NUMBER);
         odb.ExecuteSQL("Begin get5 (:numparam); end;");
         odb.GetParameters().GetParameter("NumParam").GetValue(&val);
         cout<< "value is " << (const char*) val<<endl;
         return 0;
    }
  • 2. Re: OO4O and Standard C++
    669890 Newbie
    Currently Being Moderated
    I installed the OO4O package, but I don't see oracl.h anywhere. Where is it?
  • 3. Re: OO4O and Standard C++
    669890 Newbie
    Currently Being Moderated
    Wait, never mind, I found oracl.h, but your example doesn't work for me. First, I get that it can't find iostream.h, and when I replace it with <iostream>, I get a ton of errors, not the least of which are "undefined class _export" and all the variables are undeclared identifiers.
  • 4. Re: OO4O and Standard C++
    gdarling - oracle Expert
    Currently Being Moderated
    Hi,

    It compiles fine using VS6.
    I just tried a console app using VS2005 via New > Project, and got the same errors.
    I then tried using VS2005 to migrate the VS6 solution, and that worked OK. I didnt spend much time trying to fiddle with the switches to find out exactly why, but here is the resulting compile and link options in the working solution if you want to try to compare them.

    Hope it helps,
    Greg


    COMPILE
    ==========
    /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_VC80_UPGRADE=0x0600" /D "_MBCS" /Gm /EHsc /RTC1 /MTd /Fp".\Debug/foo.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug\\" /W3 /nologo /c /ZI /TP /errorReport:prompt



    LINK
    ==========
    /OUT:".\Debug/foo.exe" /INCREMENTAL /NOLOGO /MANIFEST /MANIFESTFILE:".\Debug\foo.exe.intermediate.manifest" /DEBUG /PDB:".\Debug/foo.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT oraclm32.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
  • 5. Re: OO4O and Standard C++
    669890 Newbie
    Currently Being Moderated
    I discovered that the problem was with the compiler. It was going to WIN16 not WIN32, so the _export command was being defined incorrectly. I added the following to the top of my code and it was all good.

    #ifndef WIN32
    #define WIN32
    #endif
  • 6. Re: OO4O and Standard C++
    970843 Newbie
    Currently Being Moderated
    Can you please post a few examples on procedure and package with procedures handling sinle and multiple queries,,like using SELECT and UPDATE in the same procedure.
  • 7. Re: OO4O and Standard C++
    970843 Newbie
    Currently Being Moderated
    If it get failed in this line >>odb.ExecuteSQL("Begin get5 (:numparam); end;");
    what might be the problem?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points