我写一个简单的COM,如下:
unit UnitTesting;
{$WARN SYMBOL_PLATFORM OFF}interfaceuses
ActiveX, Mtsobj, Mtx, ComObj, PrjTesting_TLB, StdVcl;type
Ttesing = class(TMtsAutoObject, Itesing)
protected
function hello: WideString; safecall; end;implementationuses ComServ;function Ttesing.hello: WideString;
begin
result:='HelloWorld';
end;initialization
TAutoObjectFactory.Create(ComServer, Ttesing, Class_tesing,
ciMultiInstance, tmApartment);
end.然后我写一个DLL程序,使用COM中的方法。最后前端调用。DLL程序如下:
function getString():string;stdcall;
var
proxyTest:Itesing;
begin
coInitialize(nil);
try
proxyTest:=Cotesing.Create ;
result:=proxyTest.hello;
//finally
//CoUninitialize;end;
exports
getString;客户端引用DLL,直接显示返回的字符串。但是如果我在DLL中把coInitialize和CoUninitialize同时写上,就出现错误"Statement expected but 'Exports' found"
如果我只留下coInitialize,能够返回结果,但是执行完后就显示无效的指针操作,如果都不写也错误。
请问我如何写呢?
unit UnitTesting;
{$WARN SYMBOL_PLATFORM OFF}interfaceuses
ActiveX, Mtsobj, Mtx, ComObj, PrjTesting_TLB, StdVcl;type
Ttesing = class(TMtsAutoObject, Itesing)
protected
function hello: WideString; safecall; end;implementationuses ComServ;function Ttesing.hello: WideString;
begin
result:='HelloWorld';
end;initialization
TAutoObjectFactory.Create(ComServer, Ttesing, Class_tesing,
ciMultiInstance, tmApartment);
end.然后我写一个DLL程序,使用COM中的方法。最后前端调用。DLL程序如下:
function getString():string;stdcall;
var
proxyTest:Itesing;
begin
coInitialize(nil);
try
proxyTest:=Cotesing.Create ;
result:=proxyTest.hello;
//finally
//CoUninitialize;end;
exports
getString;客户端引用DLL,直接显示返回的字符串。但是如果我在DLL中把coInitialize和CoUninitialize同时写上,就出现错误"Statement expected but 'Exports' found"
如果我只留下coInitialize,能够返回结果,但是执行完后就显示无效的指针操作,如果都不写也错误。
请问我如何写呢?
解决方案 »
- delphi 7+SQL2005 做简单的查询系统 仅仅就是查询功能
- 快帮帮忙吧
- 由于公司需要学delphi,现将学习中的疑问请教大家(都是初级问题)
- 紧急求助关于局域网数据通信!
- 怎样判断调用SaveDialog时,用单击的是“保存”还是“取消”按钮?
- 关于dll与应用程序的通信问题?
- 自动显示我要的几张jpg图片!!!高分!分不够在家!
- 关于远程*.cds文件的动态创建及及时更新?(在线等)
- delphi 快捷桌面的问题急救呀
- 本人在打开陈宽达<<delphi深度历险>>附带的足球赛程序时,因为它使用的是繁体字,菜单字体是乱码,请问如何解决,高分谢谢!
- 关于控件开发的问题(高分求教)
- MainMenu的菜单图标是.bmp文件形式.放到上面太大了,怎么变成.icp的形式,或者其他的方法阿!谢谢了
var
proxyTest:Itesing;
begin
coInitialize(nil);
try
proxyTest:=Cotesing.Create ;
result:=proxyTest.hello;
finally
CoUninitialize;
end;///////////////end;
exports
你用的是string类型uses 中加上shareMem
{ 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. }
var
proxyTest:Itesing;
begin
coInitialize(nil);
//try
proxyTest:=Cotesing.Create ;
result:=proxyTest.hello; {finally
CoUninitialize;
end;
}
end;
客户端可以接收到返回的字符HELLOWORLD,执行完后,仍然是无效的操作(由于没有释放资源)
proxyTest:Itesing;
begin
coInitialize(nil);
try
{proxyTest:=Cotesing.Create ;
result:=proxyTest.hello;}//去掉这两句看看还没有错误,如果没就是proxyTest.hello有问题
result := 'aa'; finally
CoUninitialize;
end;
结帖