Creating a dll in VB6 for use in a .Net application - visual-studio

I have run into a problem where I need to use an old API created in VB6 which requires a vba.collection to be used when referencing the API for something.
I can't do this in my .net project as it fails when trying to convert visual.basic.collection to vba.collection.
I have found a workaround but cannot create the vb6 dll as I do not have vb6 and I cannot get hold of a copy.
Below are the steps I need to carry out in VB6, could anyone kindly help me to create this dll so I can complete my project?
Many Thanks!
Create a Visual Basic 6.0 DLL that returns the collection
Create a Visual Basic 6.0 Microsoft ActiveX DLL project. By default, the Class1 class is created.
Rename the project CollectionFactory, and then rename the class clsVBACollection.
Add the following code to the clsVBACollection class.
' This function creates a new object of the VBA collection.
Public Function CreateVBACollection() As Collection
' Define a variable of type Collection.
Dim col As Collection
' Create a Collection object.
Set col = New Collection
' Return the Collection object.
Set CreateVBACollection = col
End Function
On the File menu, click Make CollectionFactory.dll.

I was able to create the dll in the MS article using VB6 and this solved my problem, I hope this hels someone in the future!

Related

Development in Visual Studio for AX 2012

I have few questions regarding development in Visual Studio C# project for AX 2012.
There is a tool that provides Application Explorer from where you can drag any AOT item (Table, Class) in your project.
I dragged CustTable from the Application Explorer into my project and I can see the proxy class generated for it and all the methods that were in the Table are visible but I am interested to fetch all the records like below
select CustTable
So If I create object of the proxy class in Visual Studio how I will get all the records, there is one possibility to write a method in AX and call in the Visual Studio.
Second question is, I have created a class library and added in the C Sharp project of AOT, how I can use in the X++ classes? Is there anyway to call it. Please provide me some links related to it.
You can do one of the following : (assuming you have 2012 R2 by now)
You can use the new Linq provider: For sample code on how to do this, you can see here : http://msdn.microsoft.com/en-us/library/jj677293.aspx
You can use the table proxy as you mention above but this is done by using the find method on the Custtable.
CustTable custtable = new CustTable();
custtable = CustTable.findByCompany(dataAreaId, accountNum);
You could also use the business connector which has been around for a while now. An example of this is found here : http://msdn.microsoft.com/en-us/library/cc197126.aspx (This lets you use things like : axRecord.ExecuteStmt("select * from %1"); )
You can do something like this:
CustTable c = new CustTable();
c.ExecuteStmt("select * from %1");
while (c.Found)
{
MessageBox.Show(c.Name);
c.Next();
}

How to add reference Autocad typelibrary in runtime using vb6.0?

I am using vb6.0 application to interact with autocad. i am using autocad2007. While i run my application in autocad2007 no problem it's working fine. When i need to interact with autocad2010 my application doesn't work. So i changed reference Autocad 2010 type library. Now it's working fine only in autocad2010 but not working in autocad2007.
So any body help to me to add reference type library at runtime based on autocad version.
Assuming the dll names, method names and parameters, and properties are all the same you need to create the object in code rather than through the Project | References** menu. You can still add the reference to get the intellisense.
for instance, instead of ...
Dim objWApp As Word.Application
Set objWApp = new Word.Application
use ...
Dim objWApp As Object
Set objWApp = CreateObject("Word.Application")

ActiveX Can't Create Object

In my vb6 dll I keep getting this error
Code: 429
ActiveX Can't create object
This is the code from my form
Dim objAS400Price As New ReportTester.clsAS400PriceDiscr
Set objAS400Price = New ReportTester.clsAS400PriceDiscr
lngRetVal = objAS400Price.Report("AS400 Price Discrepancy Report", "AS400 Price Discrepancy Report", "C:\Temp", "Excel", "MASTERYY", "tschock", "NONE", "Local", True, "TSchock#ashleyfurniture.com")
This is the connection object from the dll
Set objDBConn = CreateObject("DBConnections2.DataAccess")
I used regsvr32 to register "DBConnections2.dll" on my local machine but the error is still occurring. Any suggestions to why this is happening?
I would recommend that you temporarily add a hard reference to the "DBConnections2.dll" through menu item Project->References. You should see the DLL in the list of references and be able to select it. If you do not, click the "Browse" button and add it.
Now create an early bound reference instead of using "CreateObject". By stepping into functions that call this DLL you may be able to discern which object is not referenced.
However, if you're still unable to get to the bottom of the bad reference it is likely that the "DBConnections2.dll" has a reference to one or more dependent DLLs that you are either missing or do not have registered. In that is the case you can use the Dependency Walker application to open the DLL and determine which DLL(s) references are listed as missing.
The Dependency Walker is available as an optional Tools install with Visual Basic 6. You can also download it separately if you wish.

How Can I Add an "ATL Simple Object" to Old ATL DLL Project Upgraded to VS 2010?

We have a DLL project which has existed for a long time (maybe as far back as Visual Studio 6) which has been updated for each new version of VS. The project contains a number COM classes implemented using ATL.
After upgrade to VS 2010, the project still builds fine. However, if I try to right-click the project and choose Add -> Class... -> ATL Simple Object, I get an error box that says this:
ATL classes can only be added to MFC EXE and MFC Regular DLL projects or projects with full ATL support.
This worked in VS 2008.
When I look at the project properties, Use of MFC was set to Use Standard Windows Libraries and Use of ATL was set to Not Using ATL. I changed these to Use MFC in a Shared DLL and Dynamic Link to ATL respectively, but still get the same error.
I know how to add new ATL objects without using the wizard, and I could try to recreate the project from scratch using VS 2010 to make it happy. But does anyone know of any easy way to get VS to allow me to use the ATL Simple Object wizard with a project that it doesn't recognize as a project "with full ATL support"?
Check this thread out.
It seems that adding this fragment info your ATL C++ code make it work. You don't need to actually build the project, just remove this stuff away after you are done with the wizard (provided that solution works for you).
// Added fake code begins here
class CAppModule :
public CComModule
{
};
// Added fake code ends here, below is regular ATL project stuff
CAppModule _Module;
This is where it all comes from, in $(VisualStudio)\VC\VCWizards\1033\common.js:
/******************************************************************************
Description: Returns a boolean indicating whether project is ATL-based.
oProj: Project object
******************************************************************************/
function IsATLProject(oProj)
{
try
{
var oCM = oProj.CodeModel;
oCM.Synchronize();
// look for global variable derived from CAtlModuleT
var oVariables = oCM.Variables;
for (var nCntr = 1; nCntr <= oVariables.Count; nCntr++)
{
var oVariable = oVariables(nCntr);
var strTypeString = oVariable.TypeString;
if (strTypeString == "ATL::CComModule" || strTypeString == "ATL::CAutoThreadModule")
{
return true;
}
Same problem here, but the project source already had CComModule _Module;
Fixed it, based on the IsATLProject script shown above, by changing it to
**ATL::**CComModule _Module;

where is my ActiveX DLL project template in VS 2005?

In VB6, ActiveX DLL is listed as a project template but in VS 2005+ there is no such thing. Where is my good old ActiveX DLL template? Many thanks in advance.
A couple of concepts; .NET Assemblies are the functional equivalent to ActiveX DLLs in the .NET langauges. .NET Classes and method can be decorated with attribute that have various meaning in different context. A .NET Assembly can be turned into a ActiveX/COM DLL (or OCX) by using various attributes to assign the correct GUIDs.
A basic overview of setting a .NET assembly use COM is here.
Note that do google searches you should include VB6 .NET and COM (not ActiveX). COM generates more hits as it is the underlying technology behind the ActiveX term.
The MSDN article I linked shows a basic COM setup for a .NET Class. The attribute here is the ComClass Attribute.
<ComClass(ComClass1.ClassId, ComClass1.InterfaceId, ComClass1.EventsId)> _
Public Class ComClass1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "6DB79AF2-F661-44AC-8458-62B06BFDD9E4"
Public Const InterfaceId As String = "EDED909C-9271-4670-BA32-109AE917B1D7"
Public Const EventsId As String = "17C731B8-CE61-4B5F-B114-10F3E46153AC"
#End Region
' A creatable COM class must have a Public Sub New()
' without parameters. Otherwise, the class will not be
' registered in the COM registry and cannot be created
' through CreateObject.
Public Sub New()
MyBase.New()
End Sub
End Class
There are other Attributes as well that are especially useful if you trying to subsitute a .NET assembly for an existing COM DLL or OCX. Finally .NET has a lot of different wizards that help you with the tedious details.
Try this: http://msmvps.com/blogs/pauldomag/archive/2006/08/16/107758.aspx
It outlines how to create an activex control and use it in a web page. As far as I know there's really no 'ActiveX' project template since .NET does it differently. However you can make your .Net controls visible to the COM world, which the article above illustrates.
It's not quite clear from you question, but if you want to be able to consume in VB6 (or some other com environment) something created in VS2005, you want to look at the Interop Forms Toolkit. This greatly simplifies interop between VB6 and VS2005. Now if you actually want to distribute those applications, installing what you created becomes a lot more fun (Hints: Don't use the GAC, install the .Net dll in the same directory as your application executable, and learn to use RegAsm.)
If you give a little description what you want to use the ActiveX.dll for (project library or User Control) and what environment you want to use it, more advice can be given.
I don’t know if this is what you are trying to do or not. But if you right click on the Toolbox in Visual Studio, in the popup menu select Choose Item…
When you get the “Choose Toolbox Item” dialog box come up, select the “COM Components” tab and check the COM Component(s) you want to add to the toolbox. I have done this to added the “Windows Media Player” to the toolbox and used it in a C# Winform.
From this dialog you can access any COM, OCX or ActiveX control loaded on you system.

Resources