I am a newbie programmer in C#.
Since there is one DLL which is programmed and complied by PowerBuilder and there is no source code left, I am trying to import this DLL file into C# for my owned interest.
The first thing that I have "Add Reference" thru the solution explorer.
However, I have googled a lot but there is a lot of supporting community for teaching to use C# DLL into PowerBuilder. I just have the API Specification when using this PowerBuilder DLL in PowerBuilder only.
So far I have no ideas to work on this. Any fruitful reply that I can be advised?
Thanks!
Assuming it is a .net assembly, with a suitable license, and without dependencies on powerbuilder, it should be fairly simple to just import the dll by using "add Reference" and "Browse". To view the available classes you can double click on the reference to open it in the assembly explorer. Just listing available classes is a poor substitute for proper documentation, but better than nothing.
If these assumptions are wrong you can still use a decompiler like dotPeek to view a decompiled version of the source. Note that some licenses might not permit decompiling.
Related
I have an issue including a self-built library to a C#-project. I have created an own class library called ClassLibrary1 just to learn how to add libraries on Visual Studio 2019.
So I have written some simple code in a newly created .NET-class library project and have clicked on "create new solution" (directly translated from my german IDE-language. Maybe it's called slightly different) after writing the code. Back in the C#-project, I have selected the dll-file from bin/Debug/ of the class library's project folder.
After I have set the checkmark, the dll-file was shown in the solution-explorer under Assemblys like expected. But the issue I now have is that I still cannot use the ClassLibrary1.dll-file in the cs-file in this very project as I expected via the command "using ClassLibrary1;". It only shows me the error message "type- or namespacename "ClassLibrary1" not found" when trying to compile the C#-project and I don't get, why this is the case.
It seems like it has to be a very obvious problem but after some research on the internet and trying some things by myself still nothing has changed.
Thanks in advance for helpful replies.
The by far easiest way to manage a library is to use project references. Ensure that your library and the project that uses the library is in the same solution. Then right click the "references" and select "add Reference", go to the project tab and add a checkbox for the library. Read more about managing references.
You might also need to add namespaces for the classes you wish to use in the source files.
I would not recommend managing using file-references to lose dll-files, since it can easily become a hassle to manage. I.e. if you create a new version of the library you would need to build, and explicitly replace this file in all other projects and update all the references.
If you want to share libraries between multiple solutions the more popular solution would be to setup a nuget server. This solves some of the updating problems by maintaining multiple versions of the same library, and provides a nice interface to update references in all projects. But this is a somewhat more complicated solution, so I would not recommend this for new developers.
I writing and open-source winforms app, and my program depends on another open-source project called ObjectListView.
ObjectListView is its own project in my solution and referenced as such, but its output is set as a .DLL.. It's just an enhanced ListView control. Is there any way that the project ObjectListView can be embedded in my own assembly without having to ILMerge or use some form of packer? (Defeating the purpose of an open-source project)
My initial thought was just to manually drop all the source files and whatnot into my own project, but that seems rather clunky and far from an idea solution.
PS; I did try searching for this but I didn't come across much that wasn't related to embedding DLLs into an output assembly.. Not merging projects like this. I apologize in advance if this question has been answered before.
If you don't want a separate DLL, and you don't want an embedded DLL, then perhaps a "Shared Project" project type is what you're looking for. The docs state:
A Shared Project does not get compiled on its own, it exists purely as a grouping of source code files that can be included in other projects. When referenced by another project, the code is effectively compiled as part of that project. Shared Projects cannot reference any other project type (including other Shared Projects).
While I don't think your project is exactly what it's intended for, I think it will work in your scenario.
See What is the difference between a Shared Project and a Class Library in Visual Studio 2015? for more information.
I have a c++/CLI library that is in turn calling a c# library. That is fine, it is linking implicitly and all is good with the world. But for various reasons the libraries are not getting quite the prefect treatment by our automated build process, and the libraries are not finding each other unless we move the libraries to locations that we would rather not have them in, and would rather not fold into our build process.
It is suggested to me that we/I could write a post-build event that uses XCOPY. but lets say we don't want to do that.
Another suggestion is to explicitly load the dll. Windows says that to link explicitly "Applications must make a function call to explicitly load the DLL at run time." The problem is that Microsoft's example is not enough for my small mind to understand how to proceed with this idea. Worse, the only example I could find is out of date. Perhaps I am not using the right search terms but I am having difficulty finding more about it with google.
How do we explicitly Link a c++/Cli Library to a C# .dll?
----edit
OK, How do we explicitly Link a C++/CLI code, which exports a library using __declspec(), to a C# .dll.
There is no such thing as a "C++/CLI library", only assemblies are supported. There is no explicit or implicit linking, binding always happens at runtime. Assemblies are found at runtime by the CLR, the rules it uses to locate them are described in detail in the MSDN library.
Copying all dependencies into the same directory as the EXE is the sane way to go about it while you are developing the code. Well supported by build system, the C# and C++ rules are however different. C++ projects build to the solution's Debug directory, C# projects build to the EXE project's bin\Debug directory. So yes, altering a C++ project's Output Directory setting or copying files with a post build event is usually required to get everything together.
I am kind of new to C#. I built a class library in order to create a DLL which I need to reference from a VB.Net application.
I followed all the steps detailed in this this article in order to generate the COM assembly based on my C# class library.
All the process ran smoothly (create the key, run gacutil.exe to add the assembly to the cache), but I still can't see the DLL from my main project in order to add it as a reference.
What am I doing wrong? Any help will be appreciated
There's some pretty bad advice in that article, the GAC is a deployment detail and has no relevance to the task of writing and using an assembly on your dev machine. The entire process also has nothing to do with COM at all.
Get ahead by opening your VB.NET solution in Visual Studio. Right-click the solution in the Solution Explorer window, Add, New Project. Pick "Class Library" from the C# node. Now right-click your VB.NET project, Add Reference, Project tab and select your C# project. Any of the public C# classes you write are now available in your VB.NET code.
You might not see the solution if it contains only one VB.NET project. Fix with Tools + Options, Project and Solutions, General, tick "Always show solution".
I have a DLL that I've been using with no problem in Visual C# (simply adding the reference and using the namespace). Now I'm trying to learn C++, and I don't understand how you reference a namespace from a DLL. I can right-click on a project and select 'references' and from there click 'add new reference', but that just provides me with an empty 'projects' window. What am I missing?
C++ is a lot different from C#/VB.Net when it comes to processing DLL references. In C# all that is needed to do a reference is a DLL because it contains metadata describing the structures that lay inside. The compiler can read this information such that they can be used from another project.
C++ does not have the concept of metadata in the DLL in the sense that C# does. Instead you must explicitly provide the metadata in the form of a header file. These files are included in your C++ project and then the DLL is delay loaded at runtime. You don't actually "add a reference" so to speak in C++ but include a header file instead.
Once the header file is included, you can then access the namespace by including it in your CPP files
using namespace SomeNamespace;
First of all, if you are trying to use the same DLL you used in your C# application, if you are using pure native C++, it is not straightforward to make calls into that DLL. The problem is the DLL you are referencing in C# relies on the .NET framework in order to execute (it is a "Managed" DLL, as all C#, VB.NET and C++/CLI assemblies are). There is an easy way to reference "managed" code from C++ and that is by making a managed C++ project (AKA C++/CLI) (choosing from "CLR" section in the C++ project wizard in Visual Studio). Otherwise the only way to access the managed DLL is by exposing it to COM and using COM to access the object.
EDIT: The previous answer will be more helpful if you're using unmanaged c++; I assumed because of the C# reference that you were targeting managed C++.
The 'Add Reference' dialog should have a series of tabs - 'Projects' lists projects in the current solution; .NET lists the libraries installed in the GAC and 'Browse' lets you find a DLL yourself.
If you just want to add a reference to the DLL you should be able to do it with 'Browse'. If it's the output of a project you have the source to, add the project to the solution and it'll appear under the 'Projects' tab.
If this doesn't help, which version of Visual Studio are you using, and where/what is the DLL you want to use?