vs2017生成的动态库的问题?

刚接触vs,写了个简单的测试的例子,发现生成的动态库没有入参
.cpp
#include "TestDLL.h"

int init(const int a, const int b)
{
return a + b;
}


.h
#pragma once

extern "C" declspec(dllexport) int __init(const int a, const int b);


使用dumpbin查看动态库,内容如下:

图片说明

为什么没有入参呢?不是应该是这样的吗?

ordinal hint RVA name
1 0 00001000 sum = @ILT+140(sum)

函数名是不是不一样啊,一个带__一个没带

.cpp
#include "TestDLL.h"

extern "C" declspec(dllexport) int __init(const int a, const int b)
{
return a + b;
}

.h
#ifndef TEST_DLL_H
#define TEST_DLL_H

extern "C" __declspec(dllexport) int MyAdd(const int a, const int b);

#endif

.cpp
#include "TestDLL.h"

extern "C" __declspec(dllexport) int MyAdd(const int a, const int b)
{
return a+b;
}

试试这个

不知道算不算原因,debug模式的是有@ITL的,release没有,不太明白为什么。

你发布动态库时候,加了def文件声明函数没有?
如果没加def文件声明,那么函数在调用时候有别名的,比如你说的加了一个@类似的,这样就无法进行加载。