problem with simple dll in c++ - 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!

Related

{fmt} How to install and use fmtlib in Visual Studio?

I am trying to install fmtlib and I have downloaded the zip folder and extracted it, what do I do next to use it in my Visual Studio 2022 project? Because it's my first time installing an external library. Im using windows 10.
Once you have downloaded and extracted the fmtlib, Open Visual Studio and create new project New Project -> Console App
replace the application file where main method is present with below code.
First line (#define FMT_HEADER_ONLY) is mandatory, which tells compiler to compile fmt header file also.
#define FMT_HEADER_ONLY
#include <iostream>
#include <fmt/color.h>
int main()
{
std::cout << "Hello World!\n";
fmt::print(fmt::emphasis::bold | fg(fmt::color::red),
"Elapsed time: {0:.2f} seconds", 1.23);
}
Go to Properties of project Properties, and click on dropdown of Include Directories as shown in screenshot.
Click on New Line folder Folder Icon and click on line to edit and browse folder path of include directory (C:\Users\username\Downloads\fmt-8.1.0\fmt-8.1.0\include)Browse till include directory of fmt lib.
Cross check the path is added Confirm.
Now build the Project and Execute code. Colorful Text Output
Happy Coding!
First, you have to build the lib with CMake, then you will get the .lib files.
Then you simply add the Header files in the include folder to your project in Visual Studio and link the .lib files to your project like here described:
How to add additional libraries to Visual Studio project?
I believe fmtlib is header only. You can just add the unzipped folder to your includes.
If you enable C++ latest as your C++ Language Standard (latest) in properties, C++, language, you don't need fmtlib.

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)

Multiple file compilation in visual C++ 2010

I have a very specific question in regards to visual C++ 2010 express. I have looked everywhere but can't find instructions on how to compile several source files. I have programmed on Unix at the command line and am trying to learn visual C++ 2010. I am using a header file that contains the function declarations and global variables. I don't know if this is the correct venue to ask this question but if anyone knows of some place where I can get the answer I would be grateful
Thanks,
Ral
If you have a project that you build from the command line with a makefile, then the Visual Studio development environment will not recognize your project. To open and build your project using Visual Studio, first create an empty project containing the appropriate build settings using the Makefile Project Wizard. You can then use this project to build your project from the Visual Studio development environment.
The project displays no files in Solution Explorer. The project specifies the build settings, which are reflected in the project's property page.
The output file that you specify in the project has no effect on the name that the build script generates; it declares only an intention.
Source: Creating a Makefile Project (VS2013)
On the menu: File->New->Project
On the dialog:
select Win32 Console Application,
enter Name ( like you did in the -o in unix) in the bottom,
and press OK
On the next dialog: Press next.
On the next dialog:
unmark Precompiled headers
mark Empty project
press Finish
Now find the Solution Explorer tree. You have Solution name and a project with the same name in it.
Right click on the project (not solution)
choose Add->Existing Item
and select your files, (you can copy them to the opened folder and then choose them)
press Add
Now you can try to compile.

How can I compile binary?

I'm a .net developer by heart and usually write web applications. However I've been given the binary of a small project and I need to compile it (I think).
It is only two files: mfile.h and mfile.cpp. From looking at the code the .h file is a header file that contains constants and the cpp file is the actual codefile.
I created a new C++ makefile project in Visual Studio Pro 2008 and added these but when I try to build it just says Error 1 Error result -1 returned from ''. Project mfile
I honestly have never worked with this type of code before but I want to compile this and start learning. What exactly am I missing?
Wish you were running VS 6, in which case you'd just load the .cpp file, click "build", click "okay" when it says it's going to create a project for you, and off you go.
With VS 2008, you want to:
Move these files into a directory by themselves
Select File -> New -> Project from Existing code...
Accept "Visual C++ Project"
Select the directory where you put the file
Probably select "Console Application Project"
Accept the rest of the defaults (click "Finish").
Now you should be able to (finally) build your project.
Alternatively, you can compile from the command line. In the start menu go to "Microsoft Visual Studio 8.0" -> "Visual Studio Tools" and pick one of the command prompts. When it opens, use cd to switch to wherever you've stored the files. Type:
cl mfile.cpp
to compile.
Do not create a makefile project but a standard Console application project (empty). After the empty project is created, add the two files and hit F5. If there are no errors or missing dependencies, everything should compile and run.
Using the makefile project is not the right approach (for windows at least). You should start by using the wizard for a new C++ project. Add those files to the created solution and build.

How to create DLL in VB.NET

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.