D
dey-999
Unregistered / Unconfirmed
GUEST, unregistred user!
我用delphi做了一个dll,delphi中调用没有问题,但是在vc中调用出错:Unhandled exception in PreviewDemo.exe(ReadCardInfo.dll):0xC0000005;Access Violation.
VC调用格式:
typedef CString (__stdcall * ReadCardInfo)();
{
HINSTANCE h0;
FARPROC f0;
ReadCardInfo lpDllMyFunc;
CString rs;
//h0=AfxLoadLibrary("ReadCardInfo.dll"
h0=LoadLibrary("ReadCardInfo.dll"
if (h0!=NULL)
{
lpDllMyFunc = (ReadCardInfo)GetProcAddress(HMODULE(h0),"GetBarCodeNo"
if (h0!=NULL)
rs = lpDllMyFunc();//出错处
//rs = (*lpDllMyFunc)();
}
FreeLibrary(HMODULE(h0));
}
Delphi代码:
library ReadCardInfo;
{ 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
SysUtils,
Forms,
Windows,
Messages,
Classes,
ReadCardMain in 'ReadCardMain.pas',
ReadCardFrm in 'ReadCardFrm.pas' {FrmReadCard};
{$R *.res}
exports
GetBarCodeNo;
begin
end.
unit ReadCardMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, ReadCardFrm;
function GetBarCodeNo():string;stdcall;
implementation
function GetBarCodeNo():string;stdcall;
var fReadCard:TFrmReadCard;
begin
Result:='';
fReadCard:=TFrmReadCard.Create(Application);
try
with fReadCard do begin
if ShowModal=mrOK then begin
Result:=ReturnCardNos();
end;
end;
finally
fReadCard.Free;
end;
end;
end.
ReadCardFrm.pas代码忽略
请各位大侠帮我看看,解决了另外付分啊,谢谢
VC调用格式:
typedef CString (__stdcall * ReadCardInfo)();
{
HINSTANCE h0;
FARPROC f0;
ReadCardInfo lpDllMyFunc;
CString rs;
//h0=AfxLoadLibrary("ReadCardInfo.dll"
h0=LoadLibrary("ReadCardInfo.dll"
if (h0!=NULL)
{
lpDllMyFunc = (ReadCardInfo)GetProcAddress(HMODULE(h0),"GetBarCodeNo"
if (h0!=NULL)
rs = lpDllMyFunc();//出错处
//rs = (*lpDllMyFunc)();
}
FreeLibrary(HMODULE(h0));
}
Delphi代码:
library ReadCardInfo;
{ 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
SysUtils,
Forms,
Windows,
Messages,
Classes,
ReadCardMain in 'ReadCardMain.pas',
ReadCardFrm in 'ReadCardFrm.pas' {FrmReadCard};
{$R *.res}
exports
GetBarCodeNo;
begin
end.
unit ReadCardMain;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics,
Controls, Forms, ReadCardFrm;
function GetBarCodeNo():string;stdcall;
implementation
function GetBarCodeNo():string;stdcall;
var fReadCard:TFrmReadCard;
begin
Result:='';
fReadCard:=TFrmReadCard.Create(Application);
try
with fReadCard do begin
if ShowModal=mrOK then begin
Result:=ReturnCardNos();
end;
end;
finally
fReadCard.Free;
end;
end;
end.
ReadCardFrm.pas代码忽略
请各位大侠帮我看看,解决了另外付分啊,谢谢