BCB编的dll,VB调用时告诉我说找不到函数入口点(100分)

  • 主题发起人 主题发起人 ine
  • 开始时间 开始时间
I

ine

Unregistered / Unconfirmed
GUEST, unregistred user!
这里是我的一个BCB编的dll源程序.编译成功后用VB调用时告诉我说找不到
函数入口点云云.不知何故.
:) 如是白痴级错误,请您勿必指点一二.
谢谢!!

#include <vcl.h> //可能在这里无用.
#pragma hdrstop
extern "C" __declspec(dllexport) char InPort_ine (short);//声明

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
return 1; //BCB自动生成;
}


char InPort_ine(short X)//我自己的函数
{
char Y;
__asm
{
mov dx,X
in al,dx
mov Y,al
}
return (Y);
}



E-main Address: ine2@263.net


 
VB只能接收StdCall调用的Dll
 
用DLL的查看工具(如TDump,Quickviewer)查看你生成的DLL的引出函数,
可以看到引出的函数名形如InPort_ine@cqv,而不是InPort_ine.所以
VB不能找到函数.解决办法:

1.在VB中声明函数时用DLL中的引出名.

2.在函数前后加:
extern "C" { //加
WINAPI //加
char InPort_ine(short X)//我自己的函数
{char Y;
__asm{ mov dx,X
in al,dx
mov Y,al}
return (Y);}

} //加

3.先删除行:
extern "C" __declspec(dllexport) char InPort_ine (short);//声明
(这一行在方法2中也应该删除),然后生成一DEF文件:

exports
InPort_line=InPort_line@cqv
^^^^^^^^^^^^^^^这里是BCB编译生成的函数名,与用TDump等
看到的名字一样.可以用BCB将CPP编译成汇
编,就可以从汇编文件中找到这个名字.

三种方法择一.
 
我已经将信发出了.由于我们的e-mail服务器很不稳定,我再把代码贴到这里.
我用BCB4做的一个DLL的工程,最后连接出的DLL只有45K,有输出函数Test
<h1>Dll.cpp</h1>
//---------------------------------------------------------------------------
#include <windows.h>
#pragma hdrstop
//---------------------------------------------------------------------------
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void*)
{
return 1;
}
//---------------------------------------------------------------------------
extern "C"{
//---------------------------------------------------------------------------
int WINAPI __export Test(int,int)
{
return 0;
}
//---------------------------------------------------------------------------
}
//---------------------------------------------------------------------------
<h1>dll.bpr</h1>
# ---------------------------------------------------------------------------
!if !$d(BCB)
BCB = $(MAKEDIR)/..
!endif

# ---------------------------------------------------------------------------
# IDE SECTION
# ---------------------------------------------------------------------------
# The following section of the project makefile is managed by the BCB IDE.
# It is recommended to use the IDE to change any of the values in this
# section.
# ---------------------------------------------------------------------------

VERSION = BCB.04.04
# ---------------------------------------------------------------------------
PROJECT = Dll.dll
OBJFILES = Dll.obj
RESFILES =
RESDEPEN = $(RESFILES)
LIBFILES =
IDLGENFILES =
IDLFILES =
LIBRARIES =
SPARELIBS =
PACKAGES = Vcl40.bpi Vclx40.bpi Vcldb40.bpi ibsmp40.bpi vcldbx40.bpi Qrpt40.bpi /
TeeUI40.bpi teedb40.bpi tee40.bpi Dss40.bpi Vclmid40.bpi NMFast40.bpi /
Inetdb40.bpi Inet40.bpi dclocx40.bpi bcbsmp40.bpi
DEFFILE =
# ---------------------------------------------------------------------------
PATHCPP = .;
PATHPAS = .;
PATHASM = .;
PATHRC = .;
DEBUGLIBPATH = $(BCB)/lib/debug
RELEASELIBPATH = $(BCB)/lib/release
USERDEFINES = _NO_VCL
SYSDEFINES = NO_STRICT
# ---------------------------------------------------------------------------
CFLAG1 = -I$(BCB)/include -WD -O2 -Hc -H=$(BCB)/lib/vcl40.csm -w -Ve -a8 -5 -d -k- -vi /
-c -b- -w-par -w-inl -Vx -tWM -D$(SYSDEFINES);$(USERDEFINES)
IDLCFLAGS = -I$(BCB)/include -src_suffixcpp -D_NO_VCL
PFLAGS = -U$(BCB)/lib;$(RELEASELIBPATH) -I$(BCB)/include -D_NO_VCL -$Y- -$L- -$D- -v /
-JPHNE -M
RFLAGS = -i$(BCB)/include -D_NO_VCL
AFLAGS = /i$(BCB)/include /d_NO_VCL /mx /w2 /zn
LFLAGS = -L$(BCB)/lib;$(RELEASELIBPATH) -aa -Tpd -x
# ---------------------------------------------------------------------------
ALLOBJ = c0d32.obj $(OBJFILES)
ALLRES = $(RESFILES)
ALLLIB = $(LIBFILES) $(LIBRARIES) import32.lib cw32mt.lib
# ---------------------------------------------------------------------------
!ifdef IDEOPTIONS

[Version Info]
IncludeVerInfo=0
AutoIncBuild=1
MajorVer=1
MinorVer=0
Release=0
Build=1
Debug=0
PreRelease=0
Special=0
Private=0
DLL=0
Locale=2052
CodePage=936

[Version Info Keys]
CompanyName=
FileDescription=
FileVersion=1.0.0.1
InternalName=
LegalCopyright=
LegalTrademarks=AGZ
OriginalFilename=
ProductName=
ProductVersion=1.0.0.0
Comments=

[HistoryLists/hlIncludePath]
Count=1
Item0=$(BCB)/include

[HistoryLists/hlLibraryPath]
Count=1
Item0=$(BCB)/lib

[HistoryLists/hlDebugSourcePath]
Count=1
Item0=$(BCB)/source/vcl

[HistoryLists/hlConditionals]
Count=1
Item0=_NO_VCL

[HistoryLists/hlIntOutputDir]
Count=1
Item0=

[Debugging]
DebugSourceDirs=

[Parameters]
RunParams=
HostApplication=
RemoteHost=
RemotePath=
RemoteDebug=0

[Compiler]
InMemoryExe=0
ShowInfoMsgs=0

[CORBA]
AddServerUnit=1
AddClientUnit=1
PrecompiledHeaders=1

!endif

# ---------------------------------------------------------------------------
# MAKE SECTION
# ---------------------------------------------------------------------------
# This section of the project file is not used by the BCB IDE. It is for
# the benefit of building from the command-line using the MAKE utility.
# ---------------------------------------------------------------------------

.autodepend
# ---------------------------------------------------------------------------
!if !$d(BCC32)
BCC32 = bcc32
!endif

!if !$d(CPP32)
CPP32 = cpp32
!endif

!if !$d(DCC32)
DCC32 = dcc32
!endif

!if !$d(TASM32)
TASM32 = tasm32
!endif

!if !$d(LINKER)
LINKER = ilink32
!endif

!if !$d(BRCC32)
BRCC32 = brcc32
!endif

!if !$d(IDL2CPP)
IDL2CPP = idl2cpp
!endif

# ---------------------------------------------------------------------------
!if $d(PATHCPP)
.PATH.CPP = $(PATHCPP)
.PATH.C = $(PATHCPP)
!endif

!if $d(PATHPAS)
.PATH.PAS = $(PATHPAS)
!endif

!if $d(PATHASM)
.PATH.ASM = $(PATHASM)
!endif

!if $d(PATHRC)
.PATH.RC = $(PATHRC)
!endif
# ---------------------------------------------------------------------------
$(PROJECT): $(IDLGENFILES) $(OBJFILES) $(RESDEPEN) $(DEFFILE)
$(BCB)/BIN/$(LINKER) @&&!
$(LFLAGS) +
$(ALLOBJ), +
$(PROJECT),, +
$(ALLLIB), +
$(DEFFILE), +
$(ALLRES)
!
# ---------------------------------------------------------------------------
.pas.hpp:
$(BCB)/BIN/$(DCC32) $(PFLAGS) {$< }

.pas.obj:
$(BCB)/BIN/$(DCC32) $(PFLAGS) {$< }

.cpp.obj:
$(BCB)/BIN/$(BCC32) $(CFLAG1) -n$(@D) {$< }

.c.obj:
$(BCB)/BIN/$(BCC32) $(CFLAG1) -n$(@D) {$< }

.c.i:
$(BCB)/BIN/$(CPP32) $(CFLAG1) -n. {$< }

.cpp.i:
$(BCB)/BIN/$(CPP32) $(CFLAG1) -n. {$< }

.asm.obj:
$(BCB)/BIN/$(TASM32) $(AFLAGS) $<, $@

.rc.res:
$(BCB)/BIN/$(BRCC32) $(RFLAGS) -fo$@ $<
# ---------------------------------------------------------------------------
 
To ine:
你发过来的代码我试过了,可以编译出那个引出Myinport2函数的
DLL.不知你还有甚麽问题?由于我们的e-mail服务器很不稳定,所
以在这里也回一次.

BTW:请以后不要直接回信,那样我查找这里的位置很麻烦.另外,请用中文,
我的英文很差的.由于你的信件用ISO-8859-1作为编码语言,导致我
的回信也不能用中文.
 
lhz:

谢谢您的耐心指教,我又试了一下,结果如下:

bcb3:情况照旧
bcb4:成功了!!

具体原因我也不清楚.如果在理论上可以解释,我洗耳恭听.

这个问题给您一百分,实在难表我的谢意.但 :< 我还是个
穷人.

只有多说几句:

谢谢,谢谢,谢谢..........

See you later!

ine2@263.net
昨天晚上未登录上来,所以推到今天才发工资,不好意思.
 
后退
顶部