Answer the question
In order to leave comments, you need to log in
How to create a DLL correctly?
Good evening. There is a task to transfer data from c # to c ++. I look towards DLL. But off.docs are not very clear. Using VS 2019. I create a dll called Dll2, there are two defined files DLL2.h and DLL2.cpp. There are two questions. First, do I understand correctly that in the header file I should write the names of the methods used below in this way:
#ifdef DLL2_EXPORTS
#define DLL2_API __declspec(dllexport)
#else
#define DLL2_API __declspec(dllimport)
#endif
...
extern "C" DLL2_API int Summ(int first, int second);
...
#include "pch.h"
#include "framework.h"
#include "Dll2.h"
...
DLL2_API int Summ(int first, int second)
{
return first + second;
}
[DLLImport("path_to_DLL")]
public static extern void Summ(int first, int second);
static void Main()
{
Console.WriteLn(Summ(2,3));
}
Answer the question
In order to leave comments, you need to log in
The problem was the compiler decorating the names. I changed DllImport to this:
In order to find a new name, I used DUMPBIN. Here is the sequence of actions:
1. Open Visual Studio
2. Tools -> Command Prompt -> Developer Command Prompt
3. Enter the following text at the command line: DUMPBIN /EXPORTS "path_to_your_dll"
4. Look for your function in the output and enter the value in the EntryPoint
I hope this will help someone.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question