• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

How can I make a DLL in Visula Basic?

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
octi
Asked:
octi
  • 6
  • 3
  • 2
  • +7
1 Solution
 
rkot2000Commented:
you can create an activex dll(com component) ,
but you can't create a regular dll
0
 
nutwissCommented:
yup...
0
 
OenCommented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
rspahitzCommented:
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
 
octiAuthor Commented:
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
 
OenCommented:
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
 
jrspanoCommented:
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
 
jrspanoCommented:
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
 
OenCommented:
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
 
OenCommented:
... anyway one thing is sure :
ONLY USING MFC YOU CAN HANDLE THE OCX FILES.
0
 
agriggsCommented:
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
 
octiAuthor Commented:
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
 
OenCommented:
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
 
octiAuthor Commented:
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
 
agriggsCommented:
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
 
OenCommented:
Octi>
When OLE method was implemented on Windows the MFC classes was "born".Hmmmm!...
0
 
Un1Commented:
VB normal DLL creator:

http://www.banasoft.com/MakeEx.htm
0
 
DanRollinsCommented:
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
 
Computer101Commented:
Comment from expert accepted as answer

Computer101
E-E Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 6
  • 3
  • 2
  • +7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now