using Visual Basic DLL files in MFC/C++

mjwilliamson used Ask the Experts™

I've created a an Active X DLL(VB) which uses
OLE automation on Excel and displays some charts in
a form. When importing into VB applications all works fine.

When I try to call the DLL I get a "Runtime Error!"

I thought it was ole auto that was causing the problem
however I made a simple DLL which just shows a form.
The same error occurs.

Can anyone explain/proved a solution to this problem.
It appears showing the form is causing the problem.
Is this because the dll is executing in the same
process space as the MFC app.

Any help appreciated

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®


Sorry - line 7 should read

when i try to call the dll from MFC app i get
a runtime error.

My code I am using is below

HRESULT hResult;
CLSID clsid;

hResult = CLSIDFromProgID(OLESTR("MarksDLL.Class1"),&clsid);

_Class1 *t;
hResult = CoCreateInstance(clsid,NULL,CLSCTX_INPROC_SERVER,__uuidof(_Class1),(LPVOID *) &t);

     AfxMessageBox("Creation Failed");


ShowForm simple shows a vb form (Form1.Show)

 Just to Clarify...
 You have a VB Active-X that diplays a Form
 An MFC app (Dialog or S/MDI)that is using this ActiveX
 When you run the MFC App and launch the Form You get RunTime Error, from VB or MFC?
 What does the Debug Output Say?





I have VB Active X DLL


Option Explicit

Dim frm As Form1

Public Sub ShowForm()
    MsgBox "Calling show Form"
    Call frm.Show
End Sub

Private Sub Class_Initialize()
    MsgBox "Initialising class"
    Set frm = New Form1
End Sub


Private Sub Form_Load()

MsgBox " Form: Form Loaded"

End Sub

The MFC App is a Dialog App in which I create a
new window derived from CWnd.

The VB DLL is called from menu option in main window.

The Error comes from MFC/C++

Microsoft Visual C++ Runtime Library

"this application has requested the Runtime to terminate it in an unusal way".

When I call the dll I get the all the msgs in code above
and then the error - so it gets through to loading the form
and then....crash!

Anything else just ask

Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.



above url is where I got info on importing VB Active X DLL
into MFC.
Did you try it without the Form being Shown?


Yes, it works fine then. It was when I added the
code to show the form that the problems started.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial