400分求助:可供BCB调用的VC DLL应该怎么写?

reallove 2003-09-12 10:02:21

按一般的VC DLL方式写好像是不行了,在VC中能顺利加载,但在BCB中就会发生异常。

希望可得到各位高人的指点,测试通过了的源代码是最好,到时400分一分不少,
我的信箱是 MsVcNet@msn.com. 谢谢。
...全文
95 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
yinzhaohui 2003-09-13
  • 打赏
  • 举报
回复
使用COM
vcforever 2003-09-13
  • 打赏
  • 举报
回复
用Windows API写一个标准的win32dll,应该就可以了!
reallove 2003-09-13
  • 打赏
  • 举报
回复
UP,400分哪。
flinming 2003-09-13
  • 打赏
  • 举报
回复
UP
reallove 2003-09-13
  • 打赏
  • 举报
回复
UP
philis 2003-09-12
  • 打赏
  • 举报
回复
extern "C" __declspec(dllexport)bool STDCALL CreateObject(char *astrName,LPVOID * apVoid)
{
if (astrName == NULL)
return false;
else
{
if (strcmp(astrName,"TEST")==0)
{
Ctest *lpObj = new Ctest;
*apVoid = lpObj;
}



}
return true;
}
类Ctest用继承纯虚函数,每个函数前记得加STDCALL就行了。
DisplayWorld 2003-09-12
  • 打赏
  • 举报
回复
CBC调用VC的DLL有两种方式:

1)显示

HMODULE hMod = LoadLibrary("SecurityCOM.dll");

if(hMod)
{
BOOL bInit = -1;
typedef BOOL(__stdcall * PFNSTARTUP)(VOID);

PFNSTARTUP pfnStartup = (PFNSTARTUP)GetProcAddress(hMod,
"W32SecurityStartupCOM");

if(pfnStartup)
{
bInit = pfnStartup();
}

FreeLibrary(hMod);
}

2)隐示

欲使用VC的DLL在CBC中,首先使用CBC所提供的impdef.exe工具由VC的DLL生成LIB,再把生成的LIB包含到你CB的工程中即可,当然也要提供头文件;这个工具的位置在..\Program Files\Borland\CBuilder5\Bin\impdef.exe;

它的命令行方式为:
impdef.exe input_you_lib_name.lib you_dll_name.dll

即可生成一个新的LIB;
叶子哟 2003-09-12
  • 打赏
  • 举报
回复
具体说说!
怎么不行了!
reallove 2003-09-12
  • 打赏
  • 举报
回复
UP
reallove 2003-09-12
  • 打赏
  • 举报
回复
说明:DLL使用MFC静态MFC,使用MFC;在BCB调用中,使用显示加载。
xghost 2003-09-12
  • 打赏
  • 举报
回复
up
skt01 2003-09-12
  • 打赏
  • 举报
回复
使用:
dll type:
1.regular dll using shared mfc dll
2.regular dll with mfc statically linked(最好用这个)
library fundll; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (select Project-View Source) USES clause if your DLL exports any procedures or functions that pass strings as parameters or function results. This applies to all strings passed to and from your DLL--even those that are nested in records and classes. ShareMem is the interface unit to the BORLNDMM.DLL shared memory manager, which must be deployed along with your DLL. To avoid using BORLNDMM.DLL, pass string information using PChar or ShortString parameters. } uses ShareMem, // ShareMem 一定放第一个 Windows, Messages, SysUtils, math, strutils, registry , StdCtrls, ExtCtrls, ADODB, DB,dateutils,Dialogs; // fucs in 'fucs.pas'; const INPASSSTR='89ABCDEFGcdefghijkHIJ%^KLMN0123opqrstuOP -_\|/?@#$&*' ; //切记:Library 的名字大小没关系,可是DLL-Func的大小就有关系了。 // 在 DLL-Func-Name成MyMax与myMAX是不同的。如果错了,立即的结果是你调用到此DLL的AP根本开不起来。 //参数的大小就没关系了。甚至不必同名。如原型中是 (X,Y:integer)但引用时成(A,B:integer),那是没关系的。 //切记:要再加个stdcall。书上讲,如果你是用DelphiDLL,且希望不仅给 Delphi-AP也希望BCB/VC-AP等使用的话,那你最好加个Stdcall ; //参数型态:Delphi有很多种它自己的变量型态,这些当然不是DLL所喜欢的,Windows/DLL的母语应该是C。所以如果要传进传出DLL的参数,我们尽可能照规矩来用。这两者起来,后者会麻烦不少。如果你对C不熟的话,那也没关系。我们以后再讲。 //3.将这些可共享的Func送出DLL,让外界﹝就是你的Delphi-AP啦﹞使用: //光如此,你的AP还不能用到这些,你还要加个Exports才行。 代码: //=============比较大小的函数=============== Function MyMax ( X , Y : integer ) : integer ; stdcall ; //stdcall 可以让 BCB/VC-AP等使用的 begin if X > Y then Result := X else Result := Y ; end ; //==============加密======================= function Inpass(s:string):string; stdcall ; var i:integer; passstr,dd:string; begin for i:=1 to length(s) do begin dd:=inttohex(ansipos(s[i],inpassstr),4); if dd='0000' then begin result:='0';exit end; passstr:=passstr+dd ; end; Result :=passstr; end; //==============解密======================= function Outpass(s:string):string;stdcall ; var pass,dd:string; i,leng:integer; begin leng:= floor(length(s)/4); pass:=''; for i:=1 to leng do begin dd:=ansimidstr(s,(i-1)*4+1,4); if strtoint('$'+dd)=0 then begin result:='0';exit;end; if strtoint('$'+dd)>78 then begin result:='0'; exit end; pass:=pass+ansimidstr(inpassstr,strtoint('$'+dd),1) ; end; Result :=pass ; end; //==========test========================= function jsjyh(strym:string):string;stdcall; var newstr1,he,oldstr:string; tj:boolean; i:integer; begin i:=1; he:=''; tj:=true; // 取出要参与校验和计算的字符串给oldstr if (length(strym) mod 2)0 then begin showmessage('你输入的源码个数有错,不能是奇数个,请重输入!'); exit; end; oldstr:=trim(strym); while tj=true do begin newstr1:=copy(oldstr,i,2); oldstr:=copy(oldstr,i+2,length(oldstr)-2); //开始计算校验和并给he变量 if he='' then begin he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+'00',16),2); he:=rightstr(he,2); end else begin he:=inttohex(strtointdef('$'+newstr1,16)+ strtointdef('$'+he,16),2); he:=rightstr(he,2); end; if length(oldstr) =0 then tj:=false; end; result:=strym+he; end; //============================================== {$R *.RES} //将这些可共享的Func送出DLL,让外界﹝就是你的Delphi-AP啦﹞使用: //光如此,你的AP还不能用到这些,你还要加个Exports才行。 代码: exports MyMax,Inpass,Outpass,jsjyh; begin end.

16,472

社区成员

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

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

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