Solved

Accessing VB dll from VC application

Posted on 2000-03-14
4
271 Views
Last Modified: 2010-05-02
Hi
I am wondering how is it possible to access a dll or an ocx created in VB by an application created in VC++?
Thanks!!!
0
Comment
Question by:JeromZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Expert Comment

by:Erick37
ID: 2618309
"HOWTO: Access a Visual Basic ActiveX DLL from Visual C++"

http://support.microsoft.com/support/kb/articles/Q194/8/73.ASP
0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2618922
In VC++ if you build an MFC Executable, on your dialog resources if you right click you can select Insert ActiveX control, which allows you to choose an ActiveX control to drop on the form.

Gordon
0
 

Accepted Solution

by:
RPoate earned 100 total points
ID: 2620464
I assume that you want to write a VB dll
and then call it from C++. (Gordonp seems to have it the other way around so I am not sure).

Anyway the first thing to say is that it can be done (I've done it).  You need to create a project with a class you define yourself.

Then you write some C code (Mine was not C++  ; but I am sure it's not too difficult to do it). A sample is
below.

(My VB dll is called Add_batch1X.exe
The VB code has a form which can be displayed although this is not necessary plus a few other features.)




// ===========================================================================
// File: S C L I E N T . C P P
//
//  The purpose of this file is to demonstrate how to interface with the
//  Halse Systems Automatic Batch Import facility
//
//
//  It is a provisional version and likely to change
//
//  Copyright (c) 1998  Halse Systems  +44 (0) 181 288 1481
//
//  Written by R B Poate  April  1998
// ===========================================================================


#define _WIN32_WINNT 0x0400
#define INC_OLE2
#include <stdio.h>
#include <windows.h>
#include <initguid.h>
#include <tchar.h>
#include <conio.h>


// ************************  CHANGE NEXT CODE LINE  ********************
// It needs to point to the Add_BatchX1.exe file
// Note that #import does not seem able to handle long file name - so put
// it somewhere with short directory names
//
// What is does is to extract class information which is then incorporated
// into this program in such a way that is can be used
//  
//
// ************************  CHANGE THE NEXT LINE ********************
//#import "c:\DCOM\Simple2\Simple2\Proj2\Add_BatchX1.exe"  no_namespace
#import "C:\SCSI\xcd32.dll"


// %%Constants: --------------------------------------------------------------
const ULONG cbDefault = 4096;    // default # of bytes to Read/Write

//--------------------------------------------------------------------------
// %%Function: main
// ---------------------------------------------------------------------------
 void __cdecl
main(int argc, CHAR **argv)
{

       long c ;
    COSERVERINFO csi, *pcsi=NULL;
    WCHAR wsz [MAX_PATH];
    ULONG cb = cbDefault;
   

    // **************************************************************************
   
    // The argv bits are not really supported but have been left in because they
      // may be supproted later

      // **************************************************************************

    // allow a machine-name as the command-line argument
   
      if (argc > 1)
        {
        MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, argv[1], -1,
            wsz, MAX_PATH);
        memset(&csi, 0, sizeof(COSERVERINFO));
        csi.pwszName = wsz;
        pcsi = &csi;
        }

    // allow a byte-size to be passed on the command-line
    if (argc > 2)
        cb = atol(argv[2]);
       


      // ************************************************************************

      //                 This is where things really starts

      // *************************************************************************

    // Define a batch and a directory
      // Note the double forward slashes for the directory
      char* Batch={"125X"};
      char* Root={"c:\\Customers\\GMBH\\"};



      CoInitialize(NULL);  // Initialise an DCOM interface

    _RBPClass1Ptr pRBP(__uuidof(RBPClass1));  // set up class RBPClass1

    // This gives us a pointer to the DCOM interface  pRBP

      // This can be used to run 'functions'

    pRBP->ShowForm() ;  // Show the form - not necessary - debugging purposes


// -------------------------------------------------------------------------------
//   You should be able to run the bit between the dashed lines any number of times


      pRBP->PutBatchNumber(Batch);  // put a batch number across
   
      pRBP->PutRootNode(Root);  // put a root node across
      
      pRBP->ShowData();  // show the data on the form - not necessary - debugging purposes
            
      c = pRBP->ImportBatch() ; // Import the batch and get a return code

    // return codes are as follows:

      // c is 0   It worked
      //            1      No batch number
      //            2      No root node
      //            3      Unable to get an internal (database) batch key
      //            4      No sub-directories found
      //            5      Not used
      //            6      Cannot get internal (database) order numbers
      //            7      No files found in the sub-directory - ie you gave me duff data!
      //
      //         99   General error - exact reason unknown



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

      pRBP=NULL;  // close the interface down

      CoUninitialize();  // kill off the dcom

}  // main

// EOF =======================================================================


If you want to know how it works you need to read the book
Inside Distributed COM. Microsoft Press
ISBN1-57231-849-x

Do I understand how it works? No.
I just followed the examples and hey presto it worked.

Regards Robert Poate
0
 

Author Comment

by:JeromZ
ID: 2630034
Thanks for the info guys....but do you guys know of any sites or books which show the various ways of accessing VB dll...such as accessing properties or things that have to take care of in C++ which dun have to take care of in VB...
cos i got a violation error .... due to Set MyNameSpace = Application.GetNamespace("MAPI")
Set MyAddressLists = MyNameSpace.AddressLists
I wonder why and is there any documentation for this?
I am not familiar with C++.

CH
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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