Home All Groups Group Topic Archive Search About

can't use a function from dll built in delphi

Author
29 Jan 2006 3:33 PM
Elhanan
hi..

i got a dll wrapped in com which was written in delphi,

although i can use in dotnet , trying to access a specific function in
vb6 gets me:

Function marked as restricted or uses a type not supported in Visual
Basic

Author
29 Jan 2006 6:06 PM
Mike D Sutton
> i got a dll wrapped in com which was written in delphi,
>
> although i can use in dotnet , trying to access a specific function in
> vb6 gets me:
>
> Function marked as restricted or uses a type not supported in Visual
> Basic

What's the function signature in your Delphi code?
Also, make sure that you export your function as standard call since
otherwise VB won't be able to call it.
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
30 Jan 2006 10:28 AM
Elhanan
here you go:

i should note that only the functions:

GetPlaintiffs
GetErrorMessage
GetDocumentTypes

don't work



//
************************************************************************
//
// Type Lib: E:\dcMgdSrk\DcSrkMgd.tlb (1)
// IID\LCID: {F31081A1-40F2-4DAA-93DC-01DE56B7FEEC}\0
// Helpfile:
// DepndLst:
//   (1) v2.0 stdole, (C:\WINNT\system32\STDOLE2.TLB)
//   (2) v4.0 StdVCL, (C:\WINNT\system32\STDVCL40.DLL)
//
************************************************************************
//
{$TYPEDADDRESS OFF} // Unit must be compiled without type-checked
pointers.
interface

uses Windows, ActiveX, Classes, Graphics, OleServer, OleCtrls, StdVCL;

//
*********************************************************************//
// GUIDS declared in the TypeLibrary. Following prefixes are used:

//   Type Libraries     : LIBID_xxxx

//   CoClasses          : CLASS_xxxx

//   DISPInterfaces     : DIID_xxxx

//   Non-DISP interfaces: IID_xxxx

//
*********************************************************************//
const
  // TypeLibrary Major and minor versions
  DcSrkMgdMajorVersion = 1;
  DcSrkMgdMinorVersion = 0;

  LIBID_DcSrkMgd: TGUID = '{F31081A1-40F2-4DAA-93DC-01DE56B7FEEC}';

  IID_ITSrkMigdal: TGUID = '{73995D07-F76F-4C5E-B958-55654C85DDE8}';
  CLASS_TSrkMigdal: TGUID = '{EE099BDA-6446-4460-8F22-70A94E9E09CF}';
type

//
*********************************************************************//
// Forward declaration of types defined in TypeLibrary

//
*********************************************************************//
  ITSrkMigdal = interface;

//
*********************************************************************//
// Declaration of CoClasses defined in Type Library

// (NOTE: Here we map each CoClass to its Default Interface)

//
*********************************************************************//
  TSrkMigdal = ITSrkMigdal;


//
*********************************************************************//
// Interface: ITSrkMigdal
// Flags:     (256) OleAutomation
// GUID:      {73995D07-F76F-4C5E-B958-55654C85DDE8}
//
*********************************************************************//
  ITSrkMigdal = interface(IUnknown)
    ['{73995D07-F76F-4C5E-B958-55654C85DDE8}']
    function  Init_Db(IniFileName: PChar): Integer; stdcall;
    function  Close_Db: Integer; stdcall;
    function  GetDocumentTypes: PChar; stdcall;
    function  ClaimExists(CompNum: Integer; TviaaNo: PChar): Integer;
stdcall;
    function  GetPlaintiffs(CompNum: Integer; TviaaNo: PChar): PChar;
stdcall;
    function  GetErrorMessage(ErrorCode: Integer): PChar; stdcall;
  end;

//
*********************************************************************//
// The Class CoTSrkMigdal provides a Create and CreateRemote method to

// create instances of the default interface ITSrkMigdal exposed by

// the CoClass TSrkMigdal. The functions are intended to be used by

// clients wishing to automate the CoClass objects exposed by the

// server of this typelibrary.

//
*********************************************************************//
  CoTSrkMigdal = class
    class function Create: ITSrkMigdal;
    class function CreateRemote(const MachineName: string):
ITSrkMigdal;
  end;

implementation

uses ComObj;

class function CoTSrkMigdal.Create: ITSrkMigdal;
begin
  Result := CreateComObject(CLASS_TSrkMigdal) as ITSrkMigdal;
end;

class function CoTSrkMigdal.CreateRemote(const MachineName: string):
ITSrkMigdal;
begin
  Result := CreateRemoteComObject(MachineName, CLASS_TSrkMigdal) as
ITSrkMigdal;
end;

end.
Author
30 Jan 2006 10:46 AM
Mike D Sutton
> here you go:
>
> i should note that only the functions:
>
> GetPlaintiffs
> GetErrorMessage
> GetDocumentTypes
>
> don't work
<code snipped>

I would suggest then that it's because those functions return a PChar, try putting ShareMem as the _first_ entry in both
your library and project uses clauses and see if that clears things up (although check for leaks with this technique..)
Alternatively you may want to pass the string back as an OleVariant containing a string which should handle the cleanup
for you.
Failing that, have a look at this old post which demonstrates a different way of passing strings about used by the Win32
API:
http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/msg/20450ad3c0e08e7f
Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/