Borland C++ Builder & OCI 7.* & creating own DLL (sorry it's long)

From: Bartosz Zembrzuski <Bartosz.Zembrzuski_at_softax.com.pl>
Date: Thu, 17 Aug 2000 16:16:26 GMT
Message-ID: <399C0AEB.98F07058_at_softax.com.pl>


Hi

I've got a big problem , and I hope someone would help me.

I'm using Borland C++ Builder 4.0 Professional. I'd like to create windows DLL. It have to contain a group of simple C++ classes which will cover an OCI 7.* interface. Everything have gone well, until I tried to use it. I wrote program which was linked with this library - but it doesn't work.

I simply cannot successfully execute olog function because it returns value -2147467259 :(((((

I don't know what's going on - the same source code copied inside a program works fine. But in library doesn't.

Below is capture from compiler window - you can read compiler and linker options used to create library.



bcc32 -P -DNO_STRICT;USEPACKAGES;_RTLDLL -w -Ve -r- -a8 -k -y -v -vi- -c
-b- -Vx

 -tWD -tWM -w-hid -c -I"c:\program files\borland\cbuilder4\include"
-IC:\ORANT\O

CI80\Include -DOCI_BORLAND -oWINDEBUG\ora_connection.obj -DDEBUG_CODE
-DBUILD_

liborautil -Od -k -vi- -v -r- -y ora_connection.cxx Borland C++ 5.4 for Win32 Copyright (c) 1993, 1999 Inprise Corporation ora_connection.cxx:
Warning W8004 ora_connection.cxx 46: 'rc' is assigned a value that is never used
 in function COraConnection::Connect(const string &,const string &,const string
&)
ilink32 -L"c:\program files\borland\cbuilder4\lib";"c:\program files\borland\cbu
ilder4\lib\obj";"c:\program files\borland\cbuilder4\lib\debug" -aa -Tpd
-x -Gn -

Gi -v c0d32.obj memmgr.lib Vcl40.bpi Vclx40.bpi vcljpg40.bpi bcbsmp40.bpi Qrpt40
.bpi Vcldb40.bpi ibsmp40.bpi vcldbx40.bpi TeeUI40.bpi teedb40.bpi tee40.bpi nmfa
st40.bpi dclocx40.bpi sysinit.obj WINDEBUG\ora_connection.obj , WINDEBUG
\liborautil.dll, , import32.lib cp32mti.lib C:\ORANT\OCI80\LIB\BORLAND\oc
i.lib
Turbo Incremental Link 4.00 Copyright (c) 1997, 1999 Inprise Corporation

Test program is a simple form that contains one button. It's compiled using standard debug options (but having disabled incremental linking and precompiled (cached) headers). Oci.lib and my dll library file (liborautil.lib) has been added to the project.

below is sources code for library (it contains 4 files)

  • incl_ora.hxx
    #ifndef _INCL_ORA_HXX_ #define _INCL_ORA_HXX_
#ifndef __STDC__
#define __STDC__ 1
#endif


extern "C"
{
#include <ociapr.h>
}

#define TEXT_CAST(what) \

     const_cast<text *>((const text *)(what))

#define ORA_EXPORT __export

#endif // _INCL_ORA_HXX_

  • incl_stl.hxx
    #ifndef _INCL_STL_HXX_ #define _INCL_STL_HXX_
#include <vector>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <queue>
#include <string>

using namespace std;

#endif

  • ora_connection.hxx

#ifndef _ORA_CONNECTION_HXX_
#define _ORA_CONNECTION_HXX_

#include "incl_stl.hxx"
#include "incl_ora.hxx"

class ORA_EXPORT COraConnection
{
public :

    COraConnection();

    COraConnection(const string& user, const string& password,

                   const string& sqlnet = "");
    

    void Connect(const string& user, const string& pass, const string &sqlnet="");     

private:

    ub1 m_hda[256];
    Lda_Def m_lda;
    bool m_connected;
};

#endif

  • ora_connection.cxx
#if defined(__BORLANDC__) && defined(USEPACKAGES)
#  include <vcl.h>
#endif

#include "ora_connection.hxx"

#include "incl_stl.hxx"

COraConnection::COraConnection()
{

    memset(m_hda, 0, 256 * sizeof(ub1));     m_connected = false;
}

COraConnection::COraConnection(const string& user, const string& password,

                               const string& sqlnet)
{

    memset(m_hda,0,256 *sizeof(ub1));
    Connect(user, password, sqlnet);
}

void COraConnection::Connect(const string& user, const string& password, const string &sqlnet)
{

    sword ret = olog(&m_lda, m_hda,

            TEXT_CAST(user.data()), user.size(),
            TEXT_CAST(password.data()), password.size(),
            TEXT_CAST(sqlnet.data()), sqlnet.size(),
            OCI_LM_DEF);

    ub2 rc = m_lda.rc;

    if(ret != 0)
    {

        text msg[512];                      /* message buffer to hold
error text */

        Cda_Def * cursor = (Cda_Def *)&m_lda;

        printf("\n-- ORACLE error\n");

        oerhms(&m_lda, cursor->rc, msg, (sword) sizeof msg);

        printf("\n%s\n",msg);
    }
 m_connected = true;
}



During execution oerhms function never returns and uses 100% CPU time. :((

Below is part of source code using these small library - it's being executed by Button OnClick event handler

  • source file for Borland form unit
    //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop

#include "form.h"

#include "ora_connection.hxx"

const string USER = "mci";
const string PASSWORD = "mci";
const string DB = "testowyyyy";

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)

    : TForm(Owner)
 {
}

//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender) {

    COraConnection * connection;
    connection = new COraConnection();
    connection->Connect(USER, PASSWORD, DB);     delete connection;

}

//---------------------------------------------------------------------------

// header file is rather obvious

I hope someone reached the end ..... ;))

What am I doing wrong ??? What do I have to do to make it work ??? Pleeeasse help !!!

Thanks a lot Received on Thu Aug 17 2000 - 18:16:26 CEST

Original text of this message