Solved

How can I make a DLL in Visula Basic?

Posted on 2001-07-27
19
267 Views
Last Modified: 2010-08-05
Is there any special syntax or functions which must be implemented to make a DLL in VB and use the functions from that DLL in C++? Some exemples would be usefull.
Thanks!
0
Comment
Question by:octi
  • 6
  • 3
  • 2
  • +7
19 Comments
 
LVL 5

Expert Comment

by:rkot2000
Comment Utility
you can create an activex dll(com component) ,
but you can't create a regular dll
0
 
LVL 4

Expert Comment

by:nutwiss
Comment Utility
yup...
0
 
LVL 1

Expert Comment

by:Oen
Comment Utility
Simple Way !
Create a C++ DLL with functions who can be "called" from Visual Basic and C++.If you have some knowledge about C programming you must now what is ODL.
P.S.Microsoft do the same when is need to handle data from VB to C and reverse.
0
 
LVL 22

Expert Comment

by:rspahitz
Comment Utility
Example?
Open new project, select ActiveX DLL from the [New] tab, and create away, possibly using the Add-Ins|Class Builder Utility... (which may need to be enabled using Add-Ins|Add-In Manager)

Do ActiveX DLLs work in C++?
0
 

Author Comment

by:octi
Comment Utility
rspaihitz>
I made an ActiveX DLL but this does not working in C++.
Oen>
I know how to make a DLL in C++, which could be called form any language. But the thing is to handle data form VB!
Thanks!
0
 
LVL 1

Expert Comment

by:Oen
Comment Utility
Hi Octi!
Please be more specific.I dont't understand(really) what means:
"handle data form(?from) VB!"
You wish to handle FORMS from VB to C?
Data can be handled through functions parameters.
0
 
LVL 3

Expert Comment

by:jrspano
Comment Utility
rspaihitz>
I made an ActiveX DLL but this does not working in C++.
Oen>

yes they do! It's harder but it still works
0
 
LVL 3

Expert Comment

by:jrspano
Comment Utility
you would use vb to make your active x dll and then use it in c++.  I'm not exactly sure how though.  you might want to ask in the c++ area.  How ever com is handled in c would be the way to do it.  I do know that you have to handle the stuff vb normally does for you in c. like the co functions, addreference, etc.
0
 
LVL 1

Expert Comment

by:Oen
Comment Utility
Octi>
...so you can use IDL and make a Type Library using MIDL(Microsoft Interface Definition Language) compiler.Is some samples on the www.msdn.microsft.com(i don't remember exactly , but you can search)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:Oen
Comment Utility
... anyway one thing is sure :
ONLY USING MFC YOU CAN HANDLE THE OCX FILES.
0
 
LVL 2

Accepted Solution

by:
agriggs earned 200 total points
Comment Utility
Follow the above suggestions from rspahitz and jrspano to create an ActiveX DLL in VB.  Then go into C++, create a new project that supports MFC, it can be a console application.

Then go to classwizard, by pressing Ctrl-W, it has an "Add Class" button, select the "From a type library" option.  Then browse through the file system for the DLL that is created by your VB ActiveX DLL project.  Then select which ever classes from that DLL that you want to use.  The classwizard will create header files and code for all classes that you selected based upon COleDispatchDriver.  It will take care of most of the details for you.

Then write some C++ code, like the following:

#include "myvbdll.h"  //the h file created by classwizard


MyVBClass aClass;     //dimension a variable of the proper type

    aClass.CreateDispatch("MyVBDLL.MyVBClass");
//you must enter the correct Prog ID into the string above
//if successful, now your aClass object is an instance
//of your class, and you can call the methods and properties
//almost exactly like in VB, except properties you must prepend Set or Get to the method name

Good luck!


0
 

Author Comment

by:octi
Comment Utility
Oen>
About data from VB: I would like to access Excel objects (by referencing ECXEL.OBL) to call some functions, then access the results of this functions in C++ (Builder), because I can't access the EXCEL.OBL in C++. The simplest way for me it seemst to incapsulete the VB functions in an ActiveX DLL or ActiveX component (OCX) and call them form C++.
The problem is that I made an ActiveX DLL but the functions which I wrote in VB are not visible form C++(are not DLL export functions). If I make an ActiveX component, and import them in C++, compile them then install them, I can see the functions of it in C++, but if I call them I get an exception from the MS..VB6.DLL. (The exception message is: Can't acces an inactive scope). What do you mean that OCX files could be handled only from MFC projects? I managed to compile and install OCX-es whidout MFC-s. Is true that they don't work...but it is strange why not...

agriggs>
I don't use Visual C++, but I try to make the same thing in C++ Builder. As far as I know AcitveX components should provide a common interface, what would make them usable from other languages to...not just from Microsoft's environments.

jrspano>
How?
0
 
LVL 1

Expert Comment

by:Oen
Comment Utility
Octi>
I agree Agriggs !
He explain how can you handle your ActiveX in a MFC project.
Microsoft Visual C++ ver 6.0 know to decompile your OCX files(if your .TLB files exist "near" .OCX files) and generate source file(.CPP and .H) with Methods ,Properties and Events of your OCX.

Example of what MSVC6.0 doing with OCX:

//---------------------------------------------------------
//ProgessBar2 is my OCX.
//_progressbar2.cpp file

#include "stdafx.h"
#include "_progressbar2.h"

/////////////////////////////////////////////////////////////////////////////
// C_ProgressBar2

IMPLEMENT_DYNCREATE(C_ProgressBar2, CWnd)

/////////////////////////////////////////////////////////////////////////////
// C_ProgressBar2 properties

/////////////////////////////////////////////////////////////////////////////
// C_ProgressBar2 operations

BOOL C_ProgressBar2::GetEnabled()
{
      BOOL result;
      InvokeHelper(0x68030002, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
      return result;
}

void C_ProgressBar2::SetEnabled(BOOL bNewValue)
{
      static BYTE parms[] =
            VTS_BOOL;
      InvokeHelper(0x68030002, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
             bNewValue);
}

void C_ProgressBar2::Refresh()
{
      InvokeHelper(0x60030005, DISPATCH_METHOD, VT_EMPTY, NULL, NULL);
}

short C_ProgressBar2::GetPercent()
{
      short result;
      InvokeHelper(0x68030001, DISPATCH_PROPERTYGET, VT_I2, (void*)&result, NULL);
      return result;
}

void C_ProgressBar2::SetPercent(short nNewValue)
{
      static BYTE parms[] =
            VTS_I2;
      InvokeHelper(0x68030001, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
             nNewValue);
}

unsigned long C_ProgressBar2::GetBarColour()
{
      unsigned long result;
      InvokeHelper(0x68030000, DISPATCH_PROPERTYGET, VT_I4, (void*)&result, NULL);
      return result;
}

void C_ProgressBar2::SetBarColour(unsigned long newValue)
{
      static BYTE parms[] =
            VTS_I4;
      InvokeHelper(0x68030000, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
             newValue);
}

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

and progressbar2.h file :

//---------------------------------------------------------
#if !defined(AFX__PROGRESSBAR2_H__C659AD84_8BBE_11D4_8D77_8FC1C2ABC483__INCLUDED_)
#define AFX__PROGRESSBAR2_H__C659AD84_8BBE_11D4_8D77_8FC1C2ABC483__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.

/////////////////////////////////////////////////////////////////////////////
// C_ProgressBar2 wrapper class

class C_ProgressBar2 : public CWnd
{
protected:
      DECLARE_DYNCREATE(C_ProgressBar2)
public:
      CLSID const& GetClsid()
      {
            static CLSID const clsid
                  = { 0xb7389307, 0x3b91, 0x11d2, { 0xa7, 0x6d, 0xd0, 0x6b, 0x47, 0xc1, 0x1, 0x1 } };
            return clsid;
      }
      virtual BOOL Create(LPCTSTR lpszClassName,
            LPCTSTR lpszWindowName, DWORD dwStyle,
            const RECT& rect,
            CWnd* pParentWnd, UINT nID,
            CCreateContext* pContext = NULL)
      { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID); }

    BOOL Create(LPCTSTR lpszWindowName, DWORD dwStyle,
            const RECT& rect, CWnd* pParentWnd, UINT nID,
            CFile* pPersist = NULL, BOOL bStorage = FALSE,
            BSTR bstrLicKey = NULL)
      { return CreateControl(GetClsid(), lpszWindowName, dwStyle, rect, pParentWnd, nID,
            pPersist, bStorage, bstrLicKey); }

// Attributes
public:

// Operations
public:
      BOOL GetEnabled();
      void SetEnabled(BOOL bNewValue);
      void Refresh();
      short GetPercent();
      void SetPercent(short nNewValue);
      unsigned long GetBarColour();
      void SetBarColour(unsigned long newValue);
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX__PROGRESSBAR2_H__C659AD84_8BBE_11D4_8D77_8FC1C2ABC483__INCLUDED_)
//---------------------------------------------------------
0
 

Author Comment

by:octi
Comment Utility
Oen>
Nothing new in mentioned procedure. C++Builder makes the same thing. Compiles the *.OCX, generates the header files, but methods are still not accessible from the code.
I did't use MFC classes...Is there any reasonable explanation why should this work only in a MFC kind project in Visual C++?
0
 
LVL 2

Expert Comment

by:agriggs
Comment Utility
Ok, I just assumed Visual C++.  You can't do it the way I suggested, because the class that is generated is derived from COleDispatchDriver, which has a lot of essential code in it.

Since you don't have MFC, you don't have COleDispatchDriver.

Sneak a peak at www.wxwindows.org.  It has a class called wxAutomation, I think, that can be used to access Automation objects.  And I know they strive for compatibility with multiple compilers, including Builder.

0
 
LVL 1

Expert Comment

by:Oen
Comment Utility
Octi>
When OLE method was implemented on Windows the MFC classes was "born".Hmmmm!...
0
 
LVL 1

Expert Comment

by:Un1
Comment Utility
VB normal DLL creator:

http://www.banasoft.com/MakeEx.htm
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Hi octi,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept agriggs's comment(s) as an answer.

octi, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Expert Comment

by:Computer101
Comment Utility
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

762 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

7 Experts available now in Live!

Get 1:1 Help Now