函数返回值为string数组,请问数据类型如何设定才能被Authorware调用?
另:目前版本需要创建资源文件吗?

解决方案 »

  1.   

    返回一个对象不行?例如:TStringList;Authorware应该有吧?
      

  2.   

    在DLL中将输入法的列表赋值于Authorware传入的TStringList,Authorware中再利用这个对象显示相关的输入法列表,而Authorware中调用DLL也应该动态调用,用完就要释放!
      

  3.   

    好象需要用Pchar数据类型,用Delphi做的能被AW用需要与C语言的数据类型一致
      

  4.   

    好象是02年的时候做过...需要使用PChar返回,并且还需要进行内存分配,GlobalAlloc...
      

  5.   

    Creating the ReturnString function
    The ReturnString function merits some discussion. Any string that you want to pass back to APW must go through this function. What it does is allocate some memory for the string, copy the string into it, and then return it to APW. Note that APW does the freeing of the memory allocated. I will make some more comments when creating the UCase function. This function should not be exported; it will not be called directly from APW.Open the Unit1 code window. 
    First we need to declare our function. In the 'interface' section, after the line that declares the Add function, add this line:function ReturnString(StringIn: Pchar): Pchar ; far;There is no need to use the 'stdcall' directive on this function. The 'stdcall' is only necessary on functions that are to be exported. Your interface section should look like thisuses sysutils, wintypes, winprocs; function Add( n1, n2 : Integer ) : Integer ; export; {$ifdef WIN32} stdcall ; {$endif}
    function ReturnString(StringIn: Pchar): Pchar ; far; Here is the ReturnString function. It is placed in the 'implementation' section, after the Add function.function ReturnString(StringIn: Pchar): Pchar ; 
    { Puts a string on the windows heap and returns a windows handle to the string } 
    var 
       hGlobalMemory: THandle; 
       lpGlobalMemory: pointer ; begin    {This line sets up a character pointer from windows heap } 
       hGlobalMemory := GlobalAlloc(GMEM_MOVEABLE , strlen(StringIn)+1); 
       if hGlobalMemory <> 0 then { memory allocated OK } 
          begin       { This sets up the string in the memory grabbed from the heap } 
          lpGlobalMemory := GlobalLock(hGlobalMemory); 
          lstrcpy(lpGlobalMemory,StringIn);        
          GlobalUnlock(hGlobalMemory); 
          end;    { This returns a pointer to the string to APW } 
       ReturnString := Pchar(hGlobalMemory); end; 
      

  6.   

    unit myunit;
    interface
    uses
     sharemem, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, Buttons,  imm;
    type
        timmdata = array  of pchar; {------------声明}function getallime():  timmdata ;  export; {$ifdef WIN32}   stdcall; {$endif}
    function ReturnString(StringIn: Pchar): Pchar ; far;
    function opencid(cidname:pchar):BOOLEAN; export; {$ifdef WIN32}  stdcall; {$endif}implementation //获取所有输入发的数组
    function getallime():  timmdata ;  stdcall;
     var
       j: integer;
       a: timmdata;
       retstr : array[0..64] of char;
        Begin
       SetLength(a,screen.Imes.Count);
       for j:=0 to screen.Imes.Count-1 do
        begin
          //  a[j]:=StrAlloc(Length(screen.imes.strings[j])+1);
         //   a[j]:=pchar(screen.imes.strings[j]);
           StrPCopy(retstr,screen.imes.strings[j]); { 把一个 pascal 类型的串转换到 C 类型}
           a[j]:= ReturnString( retstr ); {把转换的结果送到Authorware}
        end;
        result:=a;
        SetLength(a,0);
      End;
    function ReturnString(StringIn: Pchar): Pchar ;
    { 把一个串放到Windows的堆栈中,把Windows的句柄放到这个串}
    var
      hGlobalMemory: THandle;
       lpGlobalMemory: pointer ;
    begin
         {从Windows的堆栈中设置一个字符串指针 }
      hGlobalMemory := GlobalAlloc(GMEM_MOVEABLE , strlen(StringIn)+1);
      if hGlobalMemory <> 0 then { 内存分配正常 }
         begin
            { 在堆栈当中已经占用的内存放置该串 }
         lpGlobalMemory := GlobalLock(hGlobalMemory);
         lstrcpy(lpGlobalMemory,StringIn);
        GlobalUnlock(hGlobalMemory);
        end;
        { 把这个串的指针返回到Authorware }
       ReturnString := Pchar(hGlobalMemory);
    end;//打开输入法的函数
     function  opencid(cidname: pchar) : BOOLEAN; stdcall;
      var
       I: Integer;
       mycid:hkl;
       instr: string[64]; { 一些中间结果串 }
       retstr : array[0..64] of char; { 返回到Authorware的串}
     begin
       instr := Strpas(cidname);
       StrPCopy(retstr,instr);
       I:=screen.Imes.Indexof(retstr);
       mycid:=hkl(screen.Imes.Objects[i]);
       activatekeyboardlayout(mycid, KLF_activate);
       RESULT:=TRUE;
     end;
    end.以上在Delphi 都不能通过了(出现的是乱码)!请问大侠哪里有误?
      

  7.   

    昏倒...不过我现在这里只有C++Builder的代码,Delphi的没有了,也没有Authorware。返回值不能使用你的那个Array of Char,直接使用PCHar.
      

  8.   

    直接用PChar 好象更不行了,直接内存读取报错
      

  9.   

    不过我知道了:做成DLL而不是U32就可以不需要创建资源文件
      

  10.   

    我只在6.0以前上面做过,当时不支持标准的DLL。只支持UCD/U32格式
      

  11.   

    一样的,支持DLL没有关系,那请看看我上面的码哪儿有错误,谢谢!~
      

  12.   

    一样的,跟是否支持DLL没有关系,请看看我上面的码哪儿有错误,谢谢!~
      

  13.   

    建议按U32格式写,我以前做的就是通过PChar返回的。当时做的是ADO数据库查询。
      

  14.   

    再想想啦,主要是我另外一个DLL可能也得需要PCHAR返回的以便于在AW下调用,所以想把这个给搞通了,谢谢啦!
      

  15.   

    标准的DLL是不建议使用PChar作为返回值的。如果现行版本的AW支持标准的DLL调用,那么应该就可以通过输出参数来返回结果。
      

  16.   

    问一下使用的是AuthorWare哪个版本?
      

  17.   

    AW7当中的说明:
    Custom functions in DLLs
    Windows dynamic link libraries (DLLs) provide a way of linking to external functions that you
    call from within calculation icons. Authorware must have the following information about a
    function in a DLL before it can load it:
    • Where the function resides
    • The function’s name
    • How many and which type of arguments the function takes
    • The type of arguments the function returns
      

  18.   

    "AW7当中的说明"没有说明使用什么参数类型啊.
    用的是AW7
    "标准的DLL是不建议使用PChar作为返回值的。如果现行版本的AW支持标准的DLL调用,那么应该就可以通过输出参数来返回结果。",是这样吗?我看到有篇文章说得和C语言兼容需要PCHAR,我才用PCHAR的。请问输出参数和返回结果一般都应该是什么数据类型呢?
    谢谢啦
      

  19.   

    需要PCHAR,没有错,但是要知道PCHAR即C/C++里面的char *,它是一个动态内存管理的,所以如果你在你的DLL当中使用了,那么由DLL分配了内存,那又由谁来释放呢?很难保证DLL当中不使用到自定的内存管理方法。另外,AW7及以前版本明确需要DLL当中附上相关的说明,即需要一个特定的描述资源,而你偏说你不想要去做这个资源文件。