[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 903
  • Last Modified:

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

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
{
.....
Private:
    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!
0
preddibear
Asked:
preddibear
1 Solution
 
CayceCommented:
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.

Regards,
Cayce
0
 
preddibearAuthor Commented:
Hey Thanks!
Your answer came in just on time!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now