我快疯啦,该死的DLL!我自己写的DLL放到其他程序里就是用不了!错误是...

rogear 2001-11-12 02:06:18
我在dll的cpp程序里这样定义的函数:
__declspec(dllexport) unsigned char MyFuncation( void );

在对应的h文件里面也作了同样的说明,然后用生成的lib放到project->setting里的link里面,把lib文件、dll文件和h文件都放到程序目录下,并且在文件中包含h文件,可是编译的时候仍报告没有入口,错误如下:
LINK : fatal error LNK1561: entry point must be defined
Error executing link.exe.


有谁可以告诉我为什么阿?怎么解决?
...全文
685 42 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
42 条回复
切换为时间正序
请发表友善的回复…
发表回复
rogear 2001-11-13
  • 打赏
  • 举报
回复
有哪位仁兄可以给我一段自己开发的dll源代码?把project->setting里的东东都告诉我,我将不胜感激!我可以另开贴子把我300多分全部奉送,一个贴子不够我不停的开贴子给您加分!
andy_show 2001-11-12
  • 打赏
  • 举报
回复
我觉的问题不是在你的DLL里边,看了前面的贴子,我觉的你在自己的DLL里的工作应该都是正确的,而且那个DLL也编译连接出来了。问题应该出在你那个应用程序的工程设置里边。还有那个wWinMainCTRStartup不需要你自己实现,这个函数由VC的CRT实现,你只要在工程设置对话框的Link页的Output Category里边指定一下就可以了,缺省的时候,这里是空的。或者,你可以使用这个工程的其它的配置编译一下看看。
azuo_lee 2001-11-12
  • 打赏
  • 举报
回复
DLL不一定要有DLLMain函数,但是必须要有入口函数。很不幸的是,如果你没有在Link的参数中指定,却省情况下入口函数名字就是DLLMain。你可以提供一个空的DLLMain,什么都不做,但是必须有一个,不能没有。

wWinMainCRTStartup是UNICODE版的EXE入口,与DLL无关。

KB是Knowledge Base。

另外,你的错误是Linker报的,不是Compiler。这应该与上面的PRB无关。
rogear 2001-11-12
  • 打赏
  • 举报
回复
操,我在link里面把我的lib全都清空了还是出现一模一样的错误!
dahua 2001-11-12
  • 打赏
  • 举报
回复
push
rogear 2001-11-12
  • 打赏
  • 举报
回复
我实在是没有办法啦,我是真的解决不了了,程序的位置不可能再出现什么错误啦
andy_show 2001-11-12
  • 打赏
  • 举报
回复
KB是M$的Knowledge Base的缩写。可以微软的网站上查到,有些在MSDN上也有。

下面是那篇kb的原文,希望对你有帮助。

PRB: Missing /c Compiler Option Causes LNK1561 Linker Error

Q228455


--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual C++, 32-bit Editions, version 6.0

--------------------------------------------------------------------------------


SYMPTOMS
When compiling a multiple source file project that creates a pre-compiled header file inside the Visual C++ Integrated Development Environment (IDE), the following error can occur:

Compiling...
StdAfx.cpp
LINK : fatal error LNK1561: entry point must be defined
Error executing cl.exe.

NOTE: The linker error is generated during the compiler phase of the build.



CAUSE
The /c compiler option is missing from the build settings.



RESOLUTION
Add /c to the compiler options. To do this, you must edit the compiler options in the Project Options box in the C/C++ tab under Project Settings.

NOTE: This box is only editable if the whole project is selected in the tree control on the Project Settings.



STATUS
This behavior is by design.



MORE INFORMATION
By default, the Visual C/C++ compiler attempts to compile and link in a single step. The /c (Compile without Linking) option is used to tell the compiler to compile only. Since Visual C++ compiles and links in separate steps, then /c is required for all Visual C++ builds.

To reproduce the error, create a default MFC project and remove the /c option from the Project Settings by editing the compiler options in the Project Options box in the C/C++ tab under Project Settings.



REFERENCES

© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Kelly Marie Ward, Microsoft Corporation


Additional query words:

Keywords : kbCompiler kbLinker kbVC600
Issue type : kbprb
Technology : kbvc


Last Reviewed: February 4, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.




--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources
andy_show 2001-11-12
  • 打赏
  • 举报
回复
应该不会是那个DLL的问题,用我前面提到的方法check一下你正在连接的程序的设置。
rogear 2001-11-12
  • 打赏
  • 举报
回复
dll文件不需要一定要有DLLMain函数吧?难道一定要有吗?

andy_show,我在程序中就只有那三个函数是从dll里面携取得,我觉得那样定义已经没有问题了,除此之外我没有其他的函数入口,至于wWinMainCRTStartup函数我不知道,也不知道怎么写它,另外,不好意思,KB是什么意思?
azuo_lee 2001-11-12
  • 打赏
  • 举报
回复
1。No entry point?难道你没有定义DLLMain函数????不会吧?或者是你定义的入口函数与LINK选项ENTRY所规定的入口名称不一致。
2。Unknown Character一般是因为不小心拷贝了中文的字符。仔细检查你程序中的空格和标点符号,确信它们都不是全角字符。
andy_show 2001-11-12
  • 打赏
  • 举报
回复
我看不像是连接到DLL库函数的时候出的问题,否则应该是"unresolved external symbol"这样的错误,看文档好像是程序的入口没有定义,可能是你在Link的时候指定了自己的程序入口; 还有我记得好像MFC的程序在Build UNICODE版本的时候,也需要求手工指定一个程序入口叫wWinMainCRTStartup;另外还有一篇M$的KB说提到VC 6.0的一个bug也会导致这个错误,KB号是Q228455.
rogear 2001-11-12
  • 打赏
  • 举报
回复
好,我再来按照你的方法试!
freeman9 2001-11-12
  • 打赏
  • 举报
回复
用def文件定义:
LIBRARY "your dll"
DESCRIPTION 'Windows Dynamic Link Library'

EXPORTS
; Explicit exports can go here
fun1
fun2
fun3

函数声明和定义时用WINAPI,如:
int WINAPI function( par1,par2 )
rogear 2001-11-12
  • 打赏
  • 举报
回复
加了#pragma comment(lib,"*.lib") 依然是说我没有定义入口,我要抓狂了!
rogear 2001-11-12
  • 打赏
  • 举报
回复
补充一下,UI和UC分别是我定义的宏,分别为unsigned int 和unsigned char
sexmwj 2001-11-12
  • 打赏
  • 举报
回复
不会吧,我从没遇到这个情况,你可以用这个试试:
在调用时,加上:
#pragma comment(lib,"*.lib")
rogear 2001-11-12
  • 打赏
  • 举报
回复
我在把我的部分源程序贴近来吧:
dll工程(名称hyd.dll):

#ifndef __HYD_DLL_EXPORT__
#define __HYD_DLL_EXPORT__ __declspec(dllexport)
#endif

UC __HYD_DLL_EXPORT__ InitHYDService(UC *ConfigFile);
void __HYD_DLL_EXPORT__ ExitHYD(void);
BOOL __HYD_DLL_EXPORT__ HYD_proc(UC *pBuf, UI BufLen,UC *pResultBuf);
具体函数代码省略;

调用部分:
H文件声明:
#ifndef __HYD_IMPORT_DLL__
#define __HYD_IMPORT_DLL__ __declspec(dllimport)
#endif

UC __HYD_IMPORT_DLL__ InitHYDService(UC *ConfigFile);
void __HYD_IMPORT_DLL__ ExitHYD(void);
BOOL __HYD_IMPORT_DLL__ HYD_proc(UC *pBuf, UI BufLen,UC *pResultBuf);

在程序中直接调用这三个函数,在project->setting里面加入了hyd.lib,把hyd.dll考入了工程目录下,把hyd.lib考入了工程目录下,并且在direction的lib中添加了指向此工程目录(我知道不添加也可以,我是死马当活马医),然后怎么编译都是说我没有定义入口



靠!!!!!!!!!!!!
rogear 2001-11-12
  • 打赏
  • 举报
回复
不会这么多人都没有碰到活都不知道什么原因吧?难不成老夫发现了BUG?
rogear 2001-11-12
  • 打赏
  • 举报
回复
还有哪位哥哥想得到是哪个原因吗?
ygd 2001-11-12
  • 打赏
  • 举报
回复
extern "C" __declspec(dllexport) unsigned char MyFuncation( void );
加载更多回复(22)

16,547

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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