Using a Visual Basic developed ActiveX dll in Borland C++ Builder 6.0

Posted on 2004-11-03
Last Modified: 2013-11-17
I have developed an ActiveX dll in Visual Basic and I can use this dll inside Visual Basic by just adding the dll using
Project>References then select the dll file.
That way I was able to call the dll using
 Dim a as new MyClassInVB

the code in VB has a function declaration of

public function GetInt() as integer
and this works well in VB

However, I need to use this dll inside Borland C++ Builder 6.0
So I used this method

//header file
class myclass
    typedef int (WINAPI* typeGetInt) (void);
    typeGetInt  GetInt;

//cpp file
void myclass::LoadMyDll(void)
int a = 0;

    HINSTANCE hSTM = LoadLibrary("myclassdll.dll");

    if (hSTM != NULL)
        GetInt = (typeGetInt) GetProcAddress(hSTM,"GetInt");

   a = GetInt();


However when it runs to a=GetInt();
an exception:
Project MyApp.exe raised exception class EAccessViolation with message 'Access violation at address 00000000. read of address 00000000'. Process stopped. Use Step or Run to continue.

There must be a way to use active X dlls in Borland C++ but I don't know how.

The above method works well for the dlls I've developed in Visual C++ 6.0.
Thanks in advance!
Question by:preddibear
    LVL 9

    Accepted Solution

    Oh! No!


    ActiveX are imported as components. LoadLibrary and GetProcAddress just won't work.

    The Access violation you are getting is correct. Specially since the value of return of GetProcAddress is NULL (You should check it ouy before calling it!):

    GetInt = (typeGetInt) GetProcAddress(hSTM, "GetInt");
    if(GetInt != NULL)
      a = GetInt(); // this code will never execute !!!!

    To use an ActiveX under BCB you need to import it into a package library by using the Projects->Import Type Library menu.
    The procedure is thoughtfully documented on BCB's online help.

    Once you import the ActiveX all its controls will be available for you to use inside the BCB enviroment as "native" components, and you'll use it as if you were using it on VB.


    Author Comment

    Hey Thanks!
    Your answer came in just on time!

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project ( automates most of the tasks discussed in this article. You can even fin…
    Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
    THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now