default parameters in the exported function..??


hi,

the native dll have tried call c# has functions contain default parameters this

/**********************code snippet1*******************************************************************************/

typedef struct
{
   unsigned char tagtype;
   unsigned char antnum;
   unsigned char ids[12];
}tagids;

__declspec(dllexport) __stdcall short multitagidentify(handle hcom, unsigned int *count, tagids *value, unsigned char readeraddr=0xff);

/**********************code snippet1******************************************************************************/

and function example;


if(multitagidentifycomhandle&cnt,tagdata,0xff==0)

     {

          for(i = 0; < cnt; i++)

              outputdate(tagdata[i]);

     }

it said if want call exported function c#,i have use overloaded methods..i have tried code the overloaded function one..like this

/**********************code snippet2****************************************************************************/


[structlayout(layoutkind.sequential, charset = charset.ansi)]
      public struct tagids
      {
          public byte tagtype;
          public byte antnum;
          [marshalas(unmanagedtype.byvaltstr, sizeconst = 12)]
          public string ids;
      }

public class libwrap
{
 
     public libwrap()
        {

        }

     [dllimport("drfapiv10.dll", callingconvention = callingconvention.stdcall,charset=charset.ansi, entrypoint = "multitagidentify")]

     public static extern short isomultitagidentify(intptr hcom, ref uint count,[in,out] tagids[] value,byte readeraddr );
     public static extern short isomultitagidentify(intptr hcom, ref uint count, [in, out] tagids[] value)
       {
           return isomultitagidentify(hcom, count, value, 0xff);
       }
}
/**********************code snippet2****************************************************************************/

could verify me whether correct or wrong..?


thanks in advance

suzan,

sorry, i'm multi-trasking , didn't have time read post too closely [i checking see if had responded mine :)]  but there tool pubished through msdn magazine while ago that.  http://msdn.microsoft.com/en-us/magazine/cc164193.aspx shows p/invoke interop assistant.  thinking use verfy settings.

the code generated is:

[system.runtime.interopservices.structlayoutattribute(system.runtime.interopservices.layoutkind.sequential, charset=system.runtime.interopservices.charset.ansi)]
public struct tagids {
   
    /// unsigned char
    public byte tagtype;
   
    /// unsigned char
    public byte antnum;
   
    /// unsigned char[12]
    [system.runtime.interopservices.marshalasattribute(system.runtime.interopservices.unmanagedtype.byvaltstr, sizeconst=12)]
    public string ids;
}

public partial class nativemethods {
   
    /// return type: short
    ///hcom: handle->void*
    ///count: unsigned int*
    ///value: tagids*
    ///readeraddr: unsigned char
    [system.runtime.interopservices.dllimportattribute("<unknown>", entrypoint="multitagidentify", callingconvention=system.runtime.interopservices.callingconvention.stdcall)]
public static extern  short multitagidentify(system.intptr hcom, ref uint count, ref tagids value, byte readeraddr) ;

}

in code provide 2 methods delegate nativemethods.multitagidentify call.  hope helps.

michael



.NET Framework  >  Common Language Runtime Internals and Architecture



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'