注册时说找不到指定的模板 ,是不是DELPHI的DLL有问题,应该怎么写?

解决方案 »

  1.   

    在DELPHI中要怎么写才可以注册成功?(在没有安装DELPHI环境的机器上)
      

  2.   

    library helloworld;
    uses
      SysUtils,
      Classes;
    {$R *.res}
    function GetString:string;stdcall;
    begin
      Result:='hello world';
    end;
    exports
        GetString ;
    begin
    end.
    ///
    [DllImport("kernel32",EntryPoint="LoadLibrary",SetLastError=true)]
    static extern IntPtr LoadLibrary(string lpLibName); [DllImport("kernel32",EntryPoint="GetProcAddress",SetLastError=true)]
    static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); [DllImport("kernel32",EntryPoint="FreeLibrary",SetLastError=true)]
    static extern bool FreeLibrary(IntPtr hModule); 

    public delegate string GetString(); 
    private void button1_Click(object sender, System.EventArgs e)
    {
    IntPtr hmod=LoadLibrary(@"D:\helloworld.dll");
    IntPtr funcaddr=GetProcAddress(hmod, "GetString");
    GetString myfunc = (GetString) Marshal.GetDelegateForFunctionPointer( funcaddr, typeof( GetString ) ); 
    MessageBox.Show( myfunc() );
    FreeLibrary(hmod);
    }
      

  3.   

    够详细了,不过尽量用PChar,不要用delphi特有的变量。
      

  4.   

    TO:hongqi162(失踪的月亮) 
      Delphi写好的dll文件到没有安装DELPHI环境的机器上注册失败。
      

  5.   

    我并不关心C#中的代码,那不是我来写的(呵呵)。我只关系Delphi生成的dll。搞C#的人说不是标准的COM。要怎么写才是标准的啊。我的代码:
    library PInterface;uses
      Sharemem,
      SysUtils,
      Classes,
      ComServ,
      UInterface_Obj in 'UInterface_Obj.pas',
      UInterfaceBase in 'UInterfaceBase.pas',
      UInterface in 'UInterface.pas';{$R *.res}
    exports
      DllGetClassObject,
      DllCanUnloadNow,
      DllRegisterServer,
      DllUnregisterServer,
      SetShuiBiaoCJ,
      SetShuiBiaoLX,
      SetShuiBiaoFL,
      SetShuiBiaoKJXX;begin
    end.
      

  6.   

    unit UInterface;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Controls,  Dialogs, UInterface_Obj;var
      SetInterface:TSetInterface;procedure InitInterface;
    function SetShuiBiaoCJ(I_ChangJiaBH:int64;S_ChangJiaMC:PChar):Boolean;export; stdcall;
    function SetShuiBiaoLX(I_BiaoLeiXBH:int64;S_LeiXingMC:PChar):Boolean;export; stdcall;
    implementation
    procedure InitInterface;
    begin
      if not Assigned(SetInterface) then
        SetInterface := TSetInterface.Create(nil);
    end;function SetCeBenXX(S_CH,S_ChaoBiaoYBH,S_ST:Pchar):Boolean;export; stdcall;
    begin
      Result := False;
      InitInterface;
      //数据检查
      if S_CH = '' then Exit;
      if S_ChaoBiaoYBH = '' then Exit;
      if S_ST = '' then Exit;  Result := SetInterface.SetCeBenXX(PChar(S_CH),PChar(S_ChaoBiaoYBH),PChar(S_ST));
    end;function SetShuiBiaoCJ(I_ChangJiaBH:Int64;S_ChangJiaMC:PChar):Boolean;export; stdcall;
    begin
      Result := False;
      InitInterface;
      //数据检查
      if I_ChangJiaBH = 0 then Exit;  Result := SetInterface.SetShuiBiaoCJ(I_ChangJiaBH,S_ChangJiaMC);
    end;
    ............
    ............
      

  7.   

    delphi写的是标准的~~~
    又不是vb和c#
    还com呢
      

  8.   

    但写好的dll换个环境就是注册(regsvr32)不了,怎么办?