How to create DLL in VB.NET - vb.net-to-c#

I am using VB.NET 2008, and I want to make a DLL that will be used in a C# project.

When you build your class library in Visual Studio, it will generate the DLL for you and place it in the bin directory.
YourProject/bin/Debug/YourProject.dll
YourProject/bin/Release/YourProject.dll
It will be placed in the folder that represents your build-mode (Debug / Release), which you can normally switch in your toolbar.

Go to File > New Project and select Visual Basic, Class Library as the project type.
Enter your solution name and directory, and click on OK.
Voila!
Once you code your library and build it, you can go add it to your references in your C# project.

Just select a Class library as the project type.

Related

Create MS Visual C++ DLL project out of existing sources

My goal is to compile existing C++ classes (legacy code, stored in a set of *.h files) into a DLL so that it can be further integrated into a C# application.
For that purpose, it seems best to use MS Visual Studio. I have no experience with this environment, so I tried the naive approach found on MSDN and other SO answers:
File | New | Project from existing code
selected Visual C++
selected file location that is base for include references used in those .h files
specified a project name
let the wizard find and add all C++ files below the directory
selected "Use Visual Studio" for build, with project type "Dynamically Linked Library (DLL) project"
checked none of the checkboxes below (ATL, MFC, CLR)
specified . dir in the "Include search paths (/I)" in Debug settings
checked "Same as Debug configuration" in "Release settings"
clicked Finish button
This creates couple of VS files in the directory:
mylibrary.sln
mylibrary.vcxproj
mylibrary.vcxproj.filters
mylibrary.vcxproj.user
With a project created this way, I press F6 or select Build | Rebuild solution from the menu.
Then I expect the build to produce the .dll file somewhere, but it does not appear. Only these files appear:
.vs/mylibrary/v15/.suo
.vs/mylibrary/v15/Browse.VC.db
.vs/mylibrary/v15/Browse.VC.opendb
.vs/mylibrary/v15/ipch/AutoPCH/efad7c74cd39331b/EXAMPLE.ipch
Debug/mylibrary.log
Debug/mylibrary.tlog/mylibrary.lastbuildstate
Next, I decided to try creating a fresh new library project, just to observe the differences to get some hints, but that did not help - there were too many differences, even in the file structure...
My questions are:
is my choice of MS Visual C++ a good one for given purpose?
if so, what am I doing wrong here?
I think your steps are probably correct and I think that the right approach to use the code from a C# application. You definitely can call a C++ library from C# by importing the methods.
You missed only to export the methods that you want to use from your library. try using __declspec(dllexport) with these methods. please check this link:
https://msdn.microsoft.com/en-us/library/a90k134d.aspx.
Also, the output should be at the build folder, not the source code folder
Compiling .h files into libraries is ok, the compiler does not care - however, the UI does.
Still, you can tweak this by directly editing the .vcxproj file.
While doing so, make sure that the <ClCompile> sections contain:
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
Note that you can use commandline for building the DLL project:
"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" -target:Clean,Build
(this assumes that your current directory is the one with your .vcxproj)

Visual Studio C++ Solution compilation

My Visual Studio Solution contains the following projects :
Solution
-> FolderName
C++ Project Name 1
C++ Project Name 2
-> C++ Project Name 3
-> C# Project Name
C++ Project Name 3 is a library type project (generates a dll and a lib)
C++ Project Name 1 and 2 use a header from C++ Project Name 3 and in the linker section they expect for the lib generated by C++ Project Name 3
If compiled one by one in the project order (3,1,2) everything is compiled correctly and works, but in case i try to compile the entire solution i get a linker error stating that it cannot compile C++ project Name 1 because it cannot find the lib from C++ Project Name 3 .
My question is how can i compile correctly (in the expected order) if i select compile solution ? Next step i have to do is to compile using the build system from TFS and i expect there i will have the same problem
In Visual Studio, go to the Project menu, then Project Dependencies. Select the project that "needs" the library, and check the library's check box. This will tell Visual Studio how to determine order or compilation.
Note: you can also manually change build order, but by setting dependencies, Visual Studio can work out the order itself, which may be more optimal.
MSDN: How to: Create and Remove Project Dependencies
It sounds like you need to set up your project dependencies for the solution. How to: Create and Remove Project Dependencies
Use the Project Dependencies, Common Properties, Solution Property Pages Dialog Box to set the current build order. To access this dialog box, select a solution in Solution Explorer, choose Property Pages on the View menu, and then select Project Dependencies under Common Properties.
https://msdn.microsoft.com/en-us/library/zk4ahe0t(v=vs.90).aspx

How can I change a project in a solution from application to static library?

Background: In visual studio 2015, I have an project A built as an application. I want to create two packages B and C which wrap the contents of A into a DLL (in B) and into a runable application in C. After removing the main from A, I want to change project A from an application to a static library.
I tried changing the
Project Properties|Configuration Properties|General|Project Defaults
from Application (.exe) to Static Library (.lib). This leads to a linker error:
LINK : fatal error LNK1561: entry point must be defined
Obviously, Visual Studio still thinks that this subproject has to be compiled like an application (see here ). It therefore expects that there is a int main() which I don't want to have anymore.
So, how can I change the project type so that it is compiled as a static library?
There seems to be no way to change the build type from the GUI.
However, this can be done by altering the file A.vcxproj.
Search for all tags <ConfigurationType> and change them from Application (or whatever you have there) to StaticLibrary.
This only needs to be done for project A - the solution will adapt, the next time you start it in Visual Studio.
To properly link A into B and C, don't forget to:
1) Add a reference from B and C to A.
Open Solution>Project B/C>References, choose Add Reference, add reference to A.
2) Add a project dependency from B and C to A.
Open the context menu for any project and select Build Dependencies...>Project Dependencies>Dependencies. Add A as a dependency for both B and C.
In Visual Studio 2017, you can change the Configuration Type using the Project Properties.
With your project open, go Project / Properties.
Under Configuration Properties / General / Project Defaults, there is an entry called Configuration Type. The choices I see are Static Lib (.lib), Dynamic Lib (.dll), Application (.exe), Makefile and Utility.
My project was imported as a Dynamic Lib. I updated this setting and it now generates Static Lib. Related to the other answer, changes this setting in Visual Studio did result in the value within the project.vcxproj file to be updated. I figure doing it through Visual Studio instead of directly on the file would be more safe.

Create a DLL from a CPP file called by ctypes

I have some functions defined in a cpp file, that is used in a game made in Python using ctypes.
I wanted to create a DLL with this cpp file, so that I could call it later in Python in Windows. For that I have been trying to use Visual Studio 2015, but I have not been able to do it.
Could you help me create the DLL?
In visual studio, access your project properties by right-clicking your project and selecting Properties. From there go to Configuration Properties->General check for the field Configuration Type and set it to Dynamic Library (.dll). That's it!
Is that what you wanted to know?

problem with simple dll in c++

Hello
i do not use c++ but i try to make a simple dll in c++ by usin Microsoft visual studio 2008 this my steps
1-new project
2-select win32 and chose win32 project
3- from the win Application Wizard i chose Dll and in Additional Option i celect Empty Project
4-right click "Source Files" and add new item
5- chose c++ file(.cpp)
6- in this file i write this code
#include <windows.h>
__declspec(dllexport) int ss()
{
return 5;
}
7-Build the project >> Build Succeeded
but there is no dll file
what is the wrong ??
Thanks in advance.
Where are you checking for the .dll output? By default it outputs to the Solution (NOT Project) debug/release folder.
If you are new to .dll building in Visual Studio I would suggest starting a project in a similar manner but NOT selecting empty project, and selecting 'exports symbols'. By doing this Visual Studio will generate an example file that shows you a good notation for defining exports.
Before you compile make sure you set up the buildconfiguration to "Release" and you have to save the whole project somewhere before you compile, otherwise it's located in a temp-folder. After you saved it, compile it and look inside the projectfolder. There should be a folder named "bin" with subfolders. Look inside those subfolders and you should find your dll!