Solved

How can I make a DLL in Visula Basic?

Posted on 2001-07-27
19
272 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
ID: 6327288
you can create an activex dll(com component) ,
but you can't create a regular dll
0
 
LVL 4

Expert Comment

by:nutwiss
ID: 6327370
yup...
0
 
LVL 1

Expert Comment

by:Oen
ID: 6327400
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
ID: 6327406
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
ID: 6327491
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
ID: 6327582
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
ID: 6327596
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
ID: 6327603
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
ID: 6327700
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Expert Comment

by:Oen
ID: 6327725
... 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
ID: 6327806
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
ID: 6330946
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
ID: 6333710
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
ID: 6333799
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
ID: 6334397
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
ID: 6334513
Octi>
When OLE method was implemented on Windows the MFC classes was "born".Hmmmm!...
0
 
LVL 1

Expert Comment

by:Un1
ID: 6435022
VB normal DLL creator:

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

Expert Comment

by:DanRollins
ID: 7161611
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
ID: 7182466
Comment from expert accepted as answer

Computer101
E-E Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

919 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

18 Experts available now in Live!

Get 1:1 Help Now