Using CLS instead of dll in Visual Basic - vb.net

I've seen in several places that you should create a CLS file in Visual Studio 2010 instead of a dll file. I see how a windows application can get use a CLS file, but I am writing an extension for a program that is looking for dll files. Is it possible to create a dll in Visual Studio 2010. If not, is there a difference between using a dll vs. a cls as an extension

I only know the .cls extension as a VB6 class type source file and have heard of compiled java cls files. For interest sake, where have you seen that you should create CLS files in VS2010 instead of dlls?
Of course it's possible to create a dll in Visual Studio 2010. As in previous versions, dlls are Class Library assemblies. When you compile a Class Library project, you get a dll.You can also still check an option to 'Register for COM interop', which means you'd be able to use your dll with older applications built in VB6 for example, provided the interops are generated correctly.

Related

Using VB, VS 2013 How to use a DLL outside of the working directory

I am using writing in Visual Basic using Visual Studio 2013 and trying to use the debuger for code in a DLL that is outside of the working directory. The dll is a c++ project and the main app is a VB project.
How do I do that? In c++ it seems to be straight forward but not with VB.
Below is purely for background. I am interested in the question above in general and this is just the latest manifestation.
The full story: I am trying to debug the VB program and a DLL written in C++. I copied the the DLL into the working directory of the VB exe directory. But it gives me a tool tip at the break point in the DLL source code that reads "breakpoint will not currently be hit. No symbols loaded for this document." I am trying to figure out if that fixes the problem. If it does, it does. If it doesn't, it doesn't.
Pehaps you should p-invoke (enter link description here) to make a call and import that .dll. The other option would be to register dll in gac and make wrapper com for your library.
You should also add the library to your .NET application as follows:
xcopy "$(SolutionDir)DLL\$(ConfigurationName)"\*.dll "$(TargetDir)"*.* /Y
Project-->Properties-->Compile-->Build Events-->Post-build event command line pass the command.

How to use ReportViewer VB.net DLL in VB6 program?

I've written a DLL that provides methods for extracting data from a MySQL DB and generating a report using the built-in report viewer in VS 2012. The idea is to use this in a VB6 program. I've gone through the following process:
1) Build the DLL in VS with "register for COM interop" selected
2) Placed the DLL and TLB file in the directory of the VB6 program on another machine
3) Used regasm: "regasm Report.dll /tlb: Report.tlb /codebase" (redundant step if I already have the TLB file generated by VS?)
4) Added the TLB file to project references in VB6
The VB6 program builds and executes okay, but when I got to run my report I just get "Automation error: the system cannot find the file specified".
I've gone through the above process for a trivial DLL according to the instructions given here. This worked fine. I suspect that the references used in my DLL (MySQL.Data and Microsoft.ReportViewer.WinForms) may also need to be registered on the VB6 machine. I've been able to do this with MySQL.Data but not the ReportViewer DLL.
If it makes a difference, the DLL was built on a Windows 7 64 bit machine whereas the VB6 machine runs XP 32-bit.
Thanks in advance.
Turned out the problem was that I needed to set the Copy Local property for Microsoft.ReportViewer.Common and copy the relevant DLL files along with my own DLL. Hope this helps anyone with a similar problem.

VS 08 Express to Classic ASP

Here's the situation:
We have classic ASP running for our site.
We have VB6 DLLs, running inside the ASP as COM Objects.
I have moved over to Visual Studio 2008. I am trying to create DLLs that I can utilise in ASP the same way we would with VB6 (Server.CreateObject("")). Unfortunately, although registering is successful, I get a:
"The call to Server.CreateObject failed while checking permissions. Access is denied to this object." Error.
I have done plenty of research and found that you must register the VB.NET DLL with 'regasm' (which I did) you also need to tick the appropriate ("Make assembly COM-Visible") box.
However, through all my efforts, it seems I have run out of luck.
I did read something about having a class template called "COM Class" in order to create COM DLLs in VB.NET, but I do not have that option in the template choice.
So my question is, do I change to visual studio (non-express to obtain the COM class template and if so, would that definitely work?)
OR
Is there something that I am not doing correctly?
Please note moving to ASP.NET is not an option, nor programming in VB6.
Thanks!
EDIT
After about a full week of searching, I have found the answer, for anyone who finds this page: http://social.msdn.microsoft.com/Forums/en-US/9f84bdf7-aace-4a57-a3e4-3863a0efb647/how-to-create-comvisible-dll-that-i-can-use-from-vba-using-vs-express-2008-beta-2
man you have to read about .net a lot.
you cannot just write a .net dll and then use this in classic asp. These are two completely different Technologies.
it has absolutely nothing to do with visual Studio. Visual Studio is just the development Environment and has absolutely nothing to do with your .net Framework or your web application. you cannot use visual Studio > version 6 for vb6 programming. so you cannot create vb6 dlls with visual Studio 2008n or 2010 or 2003 or 2005.
you can write .net dlls and use them in classic asp or any other com Aware Technology. but they are still .net dlls which require the .net Framework. they are just com visible.
that is a bit complicated but possible:
you classes and methods have to be "com visible" you achieve this by using the Attribute [ComVisibleAttribute( true )]
just before the declaration of your class and before every method you want to be com visible.
example:
[ComVisibleAttribute( true )]
public class Helper {
public Helper() {
}
[ComVisibleAttribute( true )]
public object parseDate( string strDate ) {
return (object)DateTime.Parse( strDate ).ToString( "dd.MM.yyyy HH:mm:ss" );
}
}
you have to use an emtpy constructor for your classes!
furthermore you have to check "Assemlby Com visible" in Project properties-> assemblyinformation
or open Properties/AssemblyInfo.cs and add These lines:
[assembly: ComVisible( true )]
[assembly: Guid( "e2e1670d-1f90-4948-98be-27cc820b4675" )]
after you have build your dll you then have to use the ragasm.exe to Register the .net dll in the registry. (normal .net dlls are note registeres n the registry by default.
you can do that like so:
%windir%\Microsoft.NET\Framework\v4.0.30319\regasm.exe path/and/Name/of/your.dll /codebase
you have to make sure that the path to your wanted .net Framework is correct.
after that you have to restart your iis and can then use the .net dll methids from classic asp.
please be Aware that you can only pass and return values of simple datatypes to your .net methods from/to clasic asp like string, int etc.
Answer:
http://social.msdn.microsoft.com/Forums/en-US/9f84bdf7-aace-4a57-a3e4-3863a0efb647/how-to-create-comvisible-dll-that-i-can-use-from-vba-using-vs-express-2008-beta-2
Built the .dll, and targeted .NET Framework 3.5, making it COM visible.
Used the GAC utility that was installed with the Visual Studio 2008 Beta 2 (and hence >.NET Framework 3.5) - it was in C:\Program FIles\Microsoft SDKs\Windows\V.0A\bin - to place .the generated .dll into the GAC
Used the regsam.exe file I found in c:\ Windows\Microsoft.NET\framework\V2.0.50727 to >register the generated .dll.
Used the tlbexp.exe file I found in C:\Program FIles\Microsoft SDKs\Windows\V.0A\bin to >.export a .tlb file
In the VBA IDE, used Tools->References to browse to the .tlb file and select it as an >addtional reference.
The problem was that i was not doing step 2 or step 4.
I hope this helps someone in the future as it took me very long to solve.

How can I DllImport a file from resources using VB.NET?

Is there any way in VB.NET to DllImport a dll file from the resources?
I really don't want to add the dll with the executable path.
You can embed a DLL into an executable:
Jeffrey Richter: Excerpt #2 from CLR via C#, Third Edition
Many applications consist of an EXE file that depends on many DLL
files. When deploying this application, all the files must be
deployed. However, there is a technique that you can use to deploy
just a single EXE file. First, identify all the DLL files that your
EXE file depends on that do not ship as part of the Microsoft .NET
Framework itself. Then add these DLLs to your Visual Studio project.
For each DLL file you add, display its properties and change its
“Build Action” to “Embedded Resource.” This causes the C# compiler to
embed the DLL file(s) into your EXE file, and you can deploy this one
EXE file.
At runtime, the CLR won’t be able to find the dependent DLL
assemblies, which is a problem. To fix this, when your application
initializes, register a callback method with the AppDomain’s
ResolveAssembly event.

Add COM library reference in MonoDevelop

I have downloaded a .exe file that when executed (in wine) it puts two dll's in the system32 folder and a dll in the "Common files/App-name/" folder.
In theory, the installing of this file creates a tab in Visual Studio that appears when referencing and it is a COM library.
I have tried to reference these dll's in my console project but I get a message of "Is not a valid .Net assembly".
Is there something I can do?
MonoDevelop does not have support for adding COM references directly. You will have to use tlbimp.exe to generate a wrapper dll, then reference that. This is essentially what VS does transparently when you reference a native COM dll.