为什么导入dll说找不到入口点

bys_home 2007-09-14 09:51:19
这是udt.h里的原型
#define UDT_API __declspec(dllimport)
typedef int UDTSOCKET;
UDT_API UDTSOCKET socket(int af, int type, int protocol);
UDT_API int bind(UDTSOCKET u, const struct sockaddr* name, int namelen);
UDT_API int listen(UDTSOCKET u, int backlog);
UDT_API UDTSOCKET accept(UDTSOCKET u, struct sockaddr* addr, int* addrlen);
UDT_API int connect(UDTSOCKET u, const struct sockaddr* name, int namelen);
UDT_API int close(UDTSOCKET u);
我在C#中引用
[DllImport("D:\\UDT.dll", CharSet = CharSet.Auto)]
public static extern int close(int u); //这里用int是对的吧?
调用的时候说找不到入口点?

dll的源代码下载在
http://www.trademis.com/download/udt.rar
...全文
653 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
wysheng75 2008-07-21
  • 打赏
  • 举报
回复
#ifdef MYLIBAPI

#else
#define MYLIBAPI extern "C"
#endif

MYLIBAPI int iResult;
MYLIBAPI int Add( const int a, const int b );

这样就函数名不会乱码了吗?

但是在.CPP 文件中,发生警告:
warning C4273: 'iResult' : inconsistent dll linkage. dllexport assumed.
vlysses 2007-09-14
  • 打赏
  • 举报
回复
将 extern "C" 添加在 DLL 函数声明之前就能避免"?close@UDT@@YAHH@Z"这样的乱码问题,可以用[DllImport("D:\\UDT.dll", EntryPoint = "close", ...调用!
whw123456 2007-09-14
  • 打赏
  • 举报
回复
mark~
bys_home 2007-09-14
  • 打赏
  • 举报
回复
找到的了,原来是DLL编译后入口点就不对的了,我用depends工具查看了一下,原来他的入口点就是工具中的名称,现在只要改为
入口点,改为这串乱码,就行的了,哈哈
[DllImport("UDT.dll", CharSet = CharSet.Auto, EntryPoint = "?close@UDT@@YAHH@Z")]
public static extern int close(int u);
shinaterry 2007-09-14
  • 打赏
  • 举报
回复
不用定义UDT_API了...

直接用extern "C"代替比较方便...
shinaterry 2007-09-14
  • 打赏
  • 举报
回复
extern "C" __declspec( dllexport ) int close(UDTSOCKET u);
extern "C" __declspec( dllimport ) int close(UDTSOCKET u);

[DllImport("D:\\UDT.dll", EntryPoint = "close", CharSet = CharSet.Unicode)]
public static extern int close(int u);
shinaterry 2007-09-14
  • 打赏
  • 举报
回复
CharSet = CharSet.Unicode
bys_home 2007-09-14
  • 打赏
  • 举报
回复
#ifdef UDT_EXPORTS
#define UDT_API __declspec(dllexport)
#else
#define UDT_API __declspec(dllimport)
#endif
第一行是这个,我少打的了
shinaterry 2007-09-14
  • 打赏
  • 举报
回复
用您原来的方法定义函数的入口点...

VC会自动把方法的参数名加密, 再以"方法名@参数1@@参数2..."的格式作为API的入口名...

而用extern "C"却可以解决这个问题...

^o^

110,475

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧