www.digitalmars.com         C & C++   DMDScript  

D - How to set the calling convention of nested functions ... ???

reply "Matthew Wilson" <matthew stlsoft.org> writes:
I vaguely recall something about this before, and being told that it was not
necessary to be able to set the calling convention of nested functions.
However,


I have a C function that looks like

    typedef int (*hrecls_process_fn_t)(recls_info_t info,
recls_process_fn_param_t param);

    private recls_rc_t Recls_SearchProcess( char
*searchRoot
                                        ,   char
*pattern
                                        ,   recls_uint32_t  flags
                                        ,   hrecls_process_fn_t         pfn
                                        ,   recls_process_fn_param_t
param);


Since pfn is a C ptr-to-func, I can't stick a D delegate in there, so I've
written a translation like

public recls_rc_t Search_Process(   in char[]
searchRoot
                                ,   in char[]
pattern
                                ,   in int
flags
                                ,   int delegate(in Entry entry,
recls_process_fn_param_t param)    dg
                                ,   recls_process_fn_param_t
param)
{
    /* extern(Windows) */ int process_fn(recls_info_t entry,
recls_process_fn_param_t p)
    {
        return dg(Entry._make_Entry(entry), p);
    }

    return Recls_SearchProcess(searchRoot, pattern, flags, process_fn,
param);
}

Sadly, I cannot declare the nested function process_fn() to be __stdcall. If
I do not do so, it doesn't match.

The only fix I can think of is to take it outside Search_Process(), which
chews.

Is there an alternative?
Oct 10 2003
parent "Matthew Wilson" <matthew stlsoft.org> writes:
Hmmm, that didn't format nicely, did it?

Trying again:

I have a C function that looks like

    typedef int (*hrecls_process_fn_t)(recls_info_t info,
                          recls_process_fn_param_t param);

    private recls_rc_t Recls_SearchProcess(
        char   *searchRoot
    ,   char    *pattern
    ,   recls_uint32_t  flags
    ,   hrecls_process_fn_t     pfn
    ,   recls_process_fn_param_t param);


Since pfn is a C ptr-to-func, I can't stick a D delegate in there, so I've
written a translation like

public recls_rc_t Search_Process(
      in char[]                 searchRoot
  ,   in char[]                 pattern
  ,   in int                    flags
  ,   int delegate(in Entry entry,
            recls_process_fn_param_t param)    dg
  ,   recls_process_fn_param_t  param)
{
    /* extern(Windows) */ int process_fn(recls_info_t entry
                            , recls_process_fn_param_t p)
    {
        return dg(Entry._make_Entry(entry), p);
    }

    return Recls_SearchProcess(searchRoot, pattern
                          , flags, process_fn, param);
}

Sadly, I cannot declare the nested function process_fn() to be __stdcall. If
I do not do so, it doesn't match.

The only fix I can think of is to take it outside Search_Process(), which
chews.

Is there an alternative?



"Matthew Wilson" <matthew stlsoft.org> wrote in message
news:bm87cq$2urb$1 digitaldaemon.com...
 I vaguely recall something about this before, and being told that it was

 necessary to be able to set the calling convention of nested functions.
 However,


 I have a C function that looks like

     typedef int (*hrecls_process_fn_t)(recls_info_t info,
 recls_process_fn_param_t param);

     private recls_rc_t Recls_SearchProcess( char
 *searchRoot
                                         ,   char
 *pattern
                                         ,   recls_uint32_t  flags
                                         ,   hrecls_process_fn_t

                                         ,   recls_process_fn_param_t
 param);


 Since pfn is a C ptr-to-func, I can't stick a D delegate in there, so I've
 written a translation like

 public recls_rc_t Search_Process(   in char[]
 searchRoot
                                 ,   in char[]
 pattern
                                 ,   in int
 flags
                                 ,   int delegate(in Entry entry,
 recls_process_fn_param_t param)    dg
                                 ,   recls_process_fn_param_t
 param)
 {
     /* extern(Windows) */ int process_fn(recls_info_t entry,
 recls_process_fn_param_t p)
     {
         return dg(Entry._make_Entry(entry), p);
     }

     return Recls_SearchProcess(searchRoot, pattern, flags, process_fn,
 param);
 }

 Sadly, I cannot declare the nested function process_fn() to be __stdcall.

 I do not do so, it doesn't match.

 The only fix I can think of is to take it outside Search_Process(), which
 chews.

 Is there an alternative?

Oct 10 2003